JuliaArrays / StructArrays.jl

Efficient implementation of struct arrays in Julia
https://juliaarrays.github.io/StructArrays.jl/
Other
327 stars 42 forks source link

Convert to sparse array by mapping over components #275

Closed jishnub closed 11 months ago

jishnub commented 1 year ago

Structured matrix types may be converted to sparse matrices efficiently, so it makes sense to map sparse to the components of a StructArray

On master

julia> using LinearAlgebra, SparseArrays, StructArrays, BenchmarkTools

julia> D = Diagonal(Float64[1:4000;]);

julia> S = StructArray{ComplexF64}((D, D));

julia> @btime sparse($S);
  47.009 ms (16 allocations: 192.64 KiB)

This PR

julia> @btime sparse($S);
  74.021 μs (18 allocations: 407.02 KiB)

~I have structured this as an extension module to make it easier to move SparseArrays to an extension in the future.~ I've made this an extension.

jishnub commented 1 year ago

Test failures are as seen in https://github.com/JuliaArrays/StructArrays.jl/issues/274, and seem to be unrelated to this PR

Edit: tests appear to pass after the latest commit. The failure on nightly is due to changes in how NamedTuples are displayed in the docstrings, and is unrelated to this PR.

piever commented 11 months ago

Thanks for the PR and sorry for the long wait! I've rebase this in #289 (we just a small change to use createinstance to generate the sparse array. If that makes sense to you, I can go ahead and close this one and merge #289.

jishnub commented 11 months ago

Yes, makes sense, thanks!

piever commented 11 months ago

Perfect, this was merged in #289