-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spzeros and speye are really slow #22110
Comments
Good catch. This is because myspzeros(Tv::Type, Ti::Type, m::Integer, n::Integer) to: myspzeros(::Type{Tv}, ::Type{Ti}, m::Integer, n::Integer) where {Ti, Tv} fixes the problem. Would you make a pull request to make this change? |
It seems to be an issue with having the type arguments being function calls. I have actually noticed this problem in my own code. In this function, if I just call |
Hm, that does make sense. What problem am I seeing with my code then? |
Just to be extra clear what I am doing is replacing function ptrace(ρ::Density, out)
res = ptrace(full(ρ),out,dims(ρ))
return Density(res[1],res[2])
end with function ptrace(ρ::Density, out)
return Density(ptrace(full(ρ),out,dims(ρ))...)
end |
Splatting penalty. Not related to the |
I see. Is that penalty also expected if I was doing: function ptrace(ρ::Density, out)
res = ptrace(full(ρ),out,dims(ρ))
return Density(res...)
end
|
I am surprised there is a difference between the two. |
With the example in the docstrings, I get:
julia> @benchmark ptrace($ρ,2)
BenchmarkTools.Trial:
memory estimate: 592 bytes
allocs estimate: 7
--------------
minimum time: 283.362 ns (0.00% GC)
median time: 300.149 ns (0.00% GC)
mean time: 358.231 ns (14.33% GC)
maximum time: 7.924 μs (94.38% GC)
--------------
samples: 10000
evals/sample: 315
julia> @benchmark ptrace($ρ,2)
BenchmarkTools.Trial:
memory estimate: 608 bytes
allocs estimate: 8
--------------
minimum time: 6.531 μs (0.00% GC)
median time: 6.842 μs (0.00% GC)
mean time: 7.013 μs (0.69% GC)
maximum time: 501.158 μs (96.20% GC)
--------------
samples: 10000
evals/sample: 5
julia> @benchmark ptrace($ρ,2)
BenchmarkTools.Trial:
memory estimate: 592 bytes
allocs estimate: 7
--------------
minimum time: 283.185 ns (0.00% GC)
median time: 306.042 ns (0.00% GC)
mean time: 365.921 ns (14.18% GC)
maximum time: 9.788 μs (95.12% GC)
--------------
samples: 10000
evals/sample: 313 |
So if I understand correctly, the issue only occurs when splatting directly on a function call? |
I searched and couldn't find any open issue on this, which surprised me.
Not too sure what the problem is with the code in Base, but if I write my own
spzeros
, it is much faster (the same thing happens withspeye
):The text was updated successfully, but these errors were encountered: