-
Notifications
You must be signed in to change notification settings - Fork 5
Description
I'm writing this issue to gauge support for index maps, which define a virtual indexing space alongside a physical storage space. These can be useful to define batched and diagonal sparse arrays. An index map can be A mapping from the N virtual indices to M storage indices using the operators +
, -
, *
, /
, %
and parantheses only (division is integer division), the usual BODMAS rules apply. This also leads to supporting the diagonal format. I'll raise an issue on the binsparse repo and link it here.
Here is an example field for a blocked CSR array, with a batch size of 3
.
"index_map": ["i0 / 3", "i0 % 3", "i1 / 3", "i1 % 3"],
The way this can be interpreted is there are two virtual dimensions in the array, and four physical storage dimensions. i0
and i1
are the virtual indices, and the four elements of index_map
tell us how to index into the existing four dimensions with two indices. Here is another example for a 5x5 diagonal matrix:
"index_map": ["i0", "i0 + i0 // 5 + i1"],
This can also support "broadcasting" in NumPy via virtual dimensions. Here is an example with np.broadcast_to(x[:, None, :], ...)
with x.ndim == 2
:
"index_map": ["i0", "0 * i1 + i2"],