Sparse 3D arrays

It seems that SparseArrays only offers sparse vectors and matrices. Are there packages for higher dimensional sparse arrays? I am mainly interested in 3d.

What do you need it for, i.e. what operations do you need? Maybe you can just use a Dict?

Maybe NDSparse from IndexedTables?

May main concern is to save memory. For arithmetic I have modest wishes. I mainly need to be able to do arithmetic with slices and views (being able to convert them to full is enough). So indeed this could be implemented by wrapping a Dict.

NDSparse do not have slicing interface. Should not be difficult to make one though.

I put together a package following @fredrikekre suggestion.
https://github.com/jw3126/SimpleSparseArrays.jl

2 Likes

@jw3126, @fredrikekre. I landed here looking for 3-d sparse arrays. Why not integrate “SimpleSparseArrays” functionality into SparseArrays. I do not see why the latter would have only upto 2-d functionality.

2 Likes

I think it would indeed be nice to have a goto package for nd sparse arrays. I don’t have a strong opinion on whether such a package should be in the stdlib or not. But it would need to be more polished than “SimpleSparseArrays” in its current form, before it could go to stdlib.

2 Likes

I found https://github.com/Jutho/SparseArrayKit.jl which is registered in registry, and works well with newer versions of Julia.

2 Likes

There’s an n-dimensional sparse array package that might be useful: GitHub - JuliaSparse/NDimensionalSparseArrays.jl: A Julia package for n-dimensional sparse arrays

The main difference from similar packages is that it comes with no dependencies.

1 Like

@jw3126, @fredrikekre. I landed here looking for 3-d sparse arrays. Why not integrate “SimpleSparseArrays” functionality into SparseArrays. I do not see why the latter would have only upto 2-d functionality.

Note to necro this thread but:

The SparseArrays stdlib is a fantastic library but shows it’s age in many ways. It is largely an interface to older SuiteSparse solvers, and is entirely based on one structure: the CSC matrix.

While it would be nice to have one single sparse library for the entire ecosystem, SparseArrays.jl is stuck on the 1.x series and cannot be broken. That leaves essentially no room for experimentation with new interfaces, structures, and functions. It is also a fairly fragile library, making pretty important assumptions like the existence of a zero and is hard to maintain with respect to the broadcast system especially. And it can never take advantage of parallelism in the 1.x series dramatically limiting performance.

For those reasons I have encouraged people to build their sparse experiments and libraries outside of the stdlib, and a lot of good packages have come out of that like Finch.jl, SuiteSparseGraphBLAS.jl (undermaintained right now but a new release should be out soon), SparseArrayKit.jl, and now NDimensionalSparseArrays.jl!

5 Likes