-
Notifications
You must be signed in to change notification settings - Fork 54
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
Make sure reductions benefit from sparsity #244
Conversation
maybe also for vectors? |
Co-authored-by: Sobhan Mohammadpour <[email protected]>
I took the |
the only thing bugging is any of matrix julia> using Revise, SparseArrays, LinearAlgebra
for f in [sum, any, all],
t in [Int, Float64, Bool],
a in [
sprand(t, 100000, 100000, 0.00000001),
sprand(t, 100000, 0.0001),
]
f != sum && t != Bool && continue
@show f
f(a)
f(transpose(a))
f(a.nzval)
@time f(a)
@time f(transpose(a))
@time f(a.nzval)
end
[ Info: Precompiling SparseArrays [3f01184e-e22b-5df5-ae63-d93ebab69eaf]
f = sum
0.000005 seconds (1 allocation: 16 bytes)
0.000006 seconds (2 allocations: 64 bytes)
0.000007 seconds (2 allocations: 64 bytes)
f = sum
0.000003 seconds (1 allocation: 16 bytes)
0.000003 seconds (2 allocations: 48 bytes)
0.000003 seconds (2 allocations: 48 bytes)
f = sum
0.000004 seconds (1 allocation: 16 bytes)
0.000002 seconds (2 allocations: 64 bytes)
0.000004 seconds (2 allocations: 64 bytes)
f = sum
0.000001 seconds (1 allocation: 16 bytes)
0.000002 seconds (2 allocations: 48 bytes)
0.000002 seconds (2 allocations: 48 bytes)
f = sum
0.000004 seconds
0.000005 seconds (1 allocation: 48 bytes)
0.000005 seconds (1 allocation: 48 bytes)
f = sum
0.000239 seconds
0.000232 seconds (1 allocation: 32 bytes)
0.000003 seconds (1 allocation: 32 bytes)
f = any
0.067989 seconds
0.223590 seconds (1 allocation: 48 bytes)
0.000019 seconds (1 allocation: 48 bytes)
f = any
0.000007 seconds
0.000006 seconds (1 allocation: 32 bytes)
0.000001 seconds (1 allocation: 32 bytes)
f = all
0.000002 seconds
0.000003 seconds (1 allocation: 48 bytes)
0.000002 seconds (1 allocation: 48 bytes)
f = all
0.000003 seconds
0.000003 seconds (1 allocation: 32 bytes)
0.000002 seconds (1 allocation: 32 bytes) i agree it's better to handle things at a lower level |
I thought it should show the portrait. 😄 Are the timings without compilation? |
i think so (updated) |
Codecov Report
@@ Coverage Diff @@
## main #244 +/- ##
==========================================
+ Coverage 91.82% 92.05% +0.22%
==========================================
Files 12 12
Lines 7307 7314 +7
==========================================
+ Hits 6710 6733 +23
+ Misses 597 581 -16
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Wonderful benchmark! The issue with has precendence over see line 1023, because the latter is completely generic. So we need to hook in here to avoid that iterator-based implementation and redirect to |
Could you double check your benchmark? I stil can't get a local dev version running. |
nvm give me sec. |
yup looks good julia> using Revise, SparseArrays, LinearAlgebra
for f in [sum, any, all],
t in [Int, Float64, Bool],
a in [
sprand(t, 100000, 100000, 0.00000001),
sprand(t, 100000, 0.0001),
]
f != sum && t != Bool && continue
println("\n\n")
@show f, typeof(a)
f(a)
f(transpose(a))
f(a.nzval)
@time f(a)
# f(view(a, axes(a)...))
# @time f(view(a, axes(a)...))
@time f(transpose(a))
@time f(a.nzval)
end
[ Info: Precompiling SparseArrays [3f01184e-e22b-5df5-ae63-d93ebab69eaf]
(f, typeof(a)) = (sum, SparseMatrixCSC{Int64, Int64})
0.000004 seconds (1 allocation: 16 bytes)
0.000007 seconds (2 allocations: 64 bytes)
0.000008 seconds (2 allocations: 64 bytes)
(f, typeof(a)) = (sum, SparseVector{Int64, Int64})
0.000005 seconds (1 allocation: 16 bytes)
0.000004 seconds (2 allocations: 48 bytes)
0.000005 seconds (2 allocations: 48 bytes)
(f, typeof(a)) = (sum, SparseMatrixCSC{Float64, Int64})
0.000005 seconds (1 allocation: 16 bytes)
0.000004 seconds (2 allocations: 64 bytes)
0.000005 seconds (2 allocations: 64 bytes)
(f, typeof(a)) = (sum, SparseVector{Float64, Int64})
0.000006 seconds (1 allocation: 16 bytes)
0.000004 seconds (2 allocations: 48 bytes)
0.000005 seconds (2 allocations: 48 bytes)
(f, typeof(a)) = (sum, SparseMatrixCSC{Bool, Int64})
0.000004 seconds
0.000003 seconds (1 allocation: 48 bytes)
0.000004 seconds (1 allocation: 48 bytes)
(f, typeof(a)) = (sum, SparseVector{Bool, Int64})
0.000004 seconds
0.000004 seconds (1 allocation: 32 bytes)
0.000004 seconds (1 allocation: 32 bytes)
(f, typeof(a)) = (any, SparseMatrixCSC{Bool, Int64})
0.000012 seconds (2 allocations: 64 bytes)
0.000007 seconds (3 allocations: 112 bytes)
0.000003 seconds (1 allocation: 48 bytes)
(f, typeof(a)) = (any, SparseVector{Bool, Int64})
0.000003 seconds
0.000003 seconds (1 allocation: 32 bytes)
0.000001 seconds (1 allocation: 32 bytes)
(f, typeof(a)) = (all, SparseMatrixCSC{Bool, Int64})
0.000007 seconds (2 allocations: 64 bytes)
0.000004 seconds (3 allocations: 112 bytes)
0.000002 seconds (1 allocation: 48 bytes)
(f, typeof(a)) = (all, SparseVector{Bool, Int64})
0.000004 seconds
0.000004 seconds (1 allocation: 32 bytes)
0.000003 seconds (1 allocation: 32 bytes) |
count
w/o predicate
@SobhanMP Could you please check that performance is good, without the transpose cases? If yes, then I think this is ready to go. |
I realized we already have so the desired adjoint/transpose behavior should already be included. So, even if we don't have tests for which specific code route should be taken, we should test that reduction over adjoints of sparse matrices is fast. |
Together with JuliaLang/julia#46605, all benchmarks run within nanoseconds and plain sparse arrays and their transpose take pretty much the same amount of time. Let's go with this. |
This patch updates SparseArrays. In particular it contains JuliaSparse/SparseArrays.jl#260 which is necessary to make progress in #46759. All changes: - Fix ambiguities with Base. (JuliaSparse/SparseArrays.jl#268) - add == for vectors (JuliaSparse/SparseArrays.jl#248) - add undef initializers (JuliaSparse/SparseArrays.jl#263) - Make sure reductions benefit from sparsity (JuliaSparse/SparseArrays.jl#244) - Remove fkeep! from the documentation (JuliaSparse/SparseArrays.jl#261) - Fix direction of circshift (JuliaSparse/SparseArrays.jl#260) - Fix `vcat` of sparse vectors with numbers (JuliaSparse/SparseArrays.jl#253) - decrement should always return a vector (JuliaSparse/SparseArrays.jl#241) - change order of arguments in fkeep, fix bug with fixed elements (JuliaSparse/SparseArrays.jl#240) - Sparse matrix/vectors with fixed sparsity pattern. (JuliaSparse/SparseArrays.jl#201)
This patch updates SparseArrays. In particular it contains JuliaSparse/SparseArrays.jl#260 which is necessary to make progress in #46759. All changes: - Fix ambiguities with Base. (JuliaSparse/SparseArrays.jl#268) - add == for vectors (JuliaSparse/SparseArrays.jl#248) - add undef initializers (JuliaSparse/SparseArrays.jl#263) - Make sure reductions benefit from sparsity (JuliaSparse/SparseArrays.jl#244) - Remove fkeep! from the documentation (JuliaSparse/SparseArrays.jl#261) - Fix direction of circshift (JuliaSparse/SparseArrays.jl#260) - Fix `vcat` of sparse vectors with numbers (JuliaSparse/SparseArrays.jl#253) - decrement should always return a vector (JuliaSparse/SparseArrays.jl#241) - change order of arguments in fkeep, fix bug with fixed elements (JuliaSparse/SparseArrays.jl#240) - Sparse matrix/vectors with fixed sparsity pattern. (JuliaSparse/SparseArrays.jl#201)
Fixes #237.