Sparse arrays of higher order

Are there any good packages which have a similar feature as SparseArrays.SparseMatrixCSC but with higher order arrays? For example, a sparse array with 3 indices or 4 indices, stored in a similar way to a sparse matrix, except for having more indices.

3 Likes

There isn’t anything in stdlib I know of that does this. Part of the reason is that in higher dimensions indices take more room to store so arrays need to be sparser for it to be worth it. Also higher dimensional sparse data often has specific structure worth exploiting. That said, you can make a Dictionary of Keys or array of sparse matrices pretty easily though.

2 Likes

What’s a DOK?

Is a dictionary mapping tuples (or SVectors) to keys too slow for this? (Or maybe DOK is Dictionary of Keys?)

You could do a StructArray of tuples and keep it sorted (sortperm on StructArray{NTuple{N, Int}} is much faster than on Vector{NTuple{N, Int}}), and use a regular vector for the values. Then, you’d use searchsortedfirst to find the keys. That’s pretty much what IndexedTables.NDTable does, so you could also use that directly.

2 Likes