Skip to content

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Nov 23, 2022

This helps considerably with sparse parent arrays by dispatching to specialized methods instead of hitting a fallback.
On master

julia> using StructArrays, BandedMatrices, BenchmarkTools

julia> A = BandedMatrix(0 => rand(100));

julia> B = BandedMatrix(0 => rand(100));

julia> S = StructArray{Complex{eltype(A)}}((A,B));

julia> @btime $S .= 0;
  66.965 μs (0 allocations: 0 bytes)

This PR

julia> @btime $S .= 0;
  19.845 ns (0 allocations: 0 bytes)

@jishnub
Copy link
Member Author

jishnub commented Nov 28, 2022

@aplavin Could you have a look at this PR?

@aplavin
Copy link
Member

aplavin commented Nov 28, 2022

I think it's better to follow the insert! function above

function Base.insert!(s::StructVector{T}, i::Integer, vals) where T
valsT = maybe_convert_elt(T, vals)
foreachfield((v, val) -> insert!(v, i, val), s, valsT)
return s
end

and use maybe_convert_elt.

Btw I can only comment here, not actually confirm merging.

@piever
Copy link
Collaborator

piever commented Nov 30, 2022

Thanks for this! Other than for some small stylistic comments it looks good to me.

@jishnub
Copy link
Member Author

jishnub commented Nov 30, 2022

I've included the changes, could you have a look again?

@piever
Copy link
Collaborator

piever commented Nov 30, 2022

LGTM!

@piever piever merged commit 41ca636 into JuliaArrays:master Nov 30, 2022
@jishnub jishnub deleted the fill branch November 30, 2022 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants