local mlx speedups

2026-03-02

I never really used the MLX features from Apple but the UMAP-MLX project is making me wonder if I should dabble in it more. This project takes UMAP and gives it a significant speedup, 30x! Small caveat here is this currently only works for datasets that are small enough not to need approximation algorithms.

Uploaded image
The clusters look similar too

Some stats from the readme:

N       umap-learn    MLX      speedup
1000    4.87s         0.40s    12x
2000    6.18s         0.36s    17x
5000    17.22s        0.44s    40x
10000   25.85s        0.56s    46x
20000   22.01s        0.54s    41x
60000   68.99s        2.04s    34x
70000   81.40s        2.65s    31x

Impressive!

The "database sharding" term comes from ultima online.

2026-02-22

"Sharding" is a popular database technique where you split a database across multiple "shards" to spread the load. The term sounds like it might have originated from the actual term "shard" which implies it is a piece of a larger whole, but it turns out the actual origin is more related to fantasy lore.

The full details are explained in this interview from ars technica where Richard Garriott explains how Ultima Online (or at least the version from the 90ies) was created with an ecology bug. In the same interview he also mentions a bit of lore related to the game. As the story goes, when you defeated a final boss who carried "the gem of immortality" it broke into many different shards. And this bit of lore was used to justify the creation of many different servers, each with their own copy of the game.

That's where the original term seems to have come from. Some other sources online seem to verify it.

Having fun while exploring topology

2026-02-22

I never really studied topology but it sure feels like a field of math with a lot of nerd-snipes. In particular: let's talk about the Borsuk-Ulam theorem. Or at least: a simple version of it. The theorem says that any line you draw around a circle that connects back to itself you will always have two points on opposite sides of each-other with the same height.

What's fun with these topology theorems is that they are incredibly easy to demo now that we have widgets in Python notebooks! So I started a notebook with a widget that lets you draw points on a canvas.

Uploaded image
The `ScatterWidget` from `drawdata`

Next, I would smoothe a line through these points and plot it on a polar coordinate system. The x coordinate would represent the angle and the y coordinate would represent the height. With that, I can now render these charts:

Uploaded image
Left to right: the smoothed line that I drew with it's reverse cousin, the chart that shows the difference between these two charts and the polar view of the drawn image.

If you want to play around with the notebook yourself, you can do that here:

Open in molab

You can so much intuition when you're able to interact with the math directly. Not just with visual elements but also with Python code! There have been plenty of moments where the math doesn't immediately make sense to me and a Python implementation makes it much easier to wrap my head around it.

Why does this always work?

In this particular case, the math proof is pretty simple and satisfying too. Let $f(\theta)$ be our original function that goes around in a circle in the polar coordinate system.

Define $g(\theta) = f(\theta) - f(\theta + \pi)$.

Then:

$$g(0) = f(0) - f(\pi)$$

$$g(\pi) = f(\pi) - f(2\pi) = f(\pi) - f(0) = -g(0)$$

So $g(0)$ and $g(\pi)$ have opposite signs (unless one is already zero). By the Intermediate Value Theorem, $g$ must cross zero somewhere in between.

That zero is your antipodal pair: $f(\theta^) = f(\theta^ + \pi)$.

This is the 1D case of the Borsuk-Ulam theorem. The full theorem says: for any continuous map $f: S^n \to \mathbb{R}^n$, there exists a point $x$ where $f(x) = f(-x)$.