Skip to content
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

add == for vectors #248

Merged
merged 6 commits into from
Sep 22, 2022
Merged

add == for vectors #248

merged 6 commits into from
Sep 22, 2022

Conversation

SobhanMP
Copy link
Member

@SobhanMP SobhanMP commented Sep 6, 2022

merge on green.
Closes #246

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2022

Codecov Report

Merging #248 (f7cc5c9) into main (dfcc48a) will decrease coverage by 0.02%.
The diff coverage is 82.60%.

@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
- Coverage   91.82%   91.80%   -0.03%     
==========================================
  Files          12       12              
  Lines        7307     7330      +23     
==========================================
+ Hits         6710     6729      +19     
- Misses        597      601       +4     
Impacted Files Coverage Δ
src/sparsevector.jl 94.90% <82.60%> (-0.23%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@dkarrasch
Copy link
Member

This reminds of our broadcast code. Couldn't we replace the code by all(A .== B) after the size check?

@SobhanMP
Copy link
Member Author

SobhanMP commented Sep 6, 2022

julia> using SparseArrays

julia> a = sprandn(100000, 0.9);

julia> b = sprandn(100000, 0.9);

julia> @time a .== b;
  0.002611 seconds (7 allocations: 879.344 KiB)

i agree that they are similar but that would make it allocating. i don't think we want that.

@dkarrasch
Copy link
Member

What I had in mind is something lazy like all(Broadcast.broadcasted(==, Y, Y)), which is allocation-free, but doesn't seem to use any sparse technology. It seems to just iterate via slow getindex.

@dkarrasch
Copy link
Member

Do we have tests for this? Including things like equal vectors where one has a stored zero?

@SobhanMP
Copy link
Member Author

SobhanMP commented Sep 7, 2022

i added a test with explicit zero

@SobhanMP
Copy link
Member Author

SobhanMP commented Sep 7, 2022

if you have something specific in mind, do share

test/sparsematrix_ops.jl Outdated Show resolved Hide resolved
@ViralBShah
Copy link
Member

Do we really need all the @inbounds? Does it have a noticeable impact here?

Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
@SobhanMP
Copy link
Member Author

@ViralBShah on really large examples, yeah

julia> @benchmark eq1($A, $B)
BenchmarkTools.Trial: 29 samples with 1 evaluation.
 Range (min  max):  168.045 ms  186.107 ms  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     173.698 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   174.602 ms ±   4.069 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▁     ▁▁▁▁█  ██ ▁ █▁▁ ▁▁▁█  ▁▁   ▁ ▁   ▁  ▁      ▁          ▁  
  █▁▁▁▁▁█████▁▁██▁█▁███▁████▁▁██▁▁▁█▁█▁▁▁█▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁█ ▁
  168 ms           Histogram: frequency by time          186 ms <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark eq2($A, $B)
BenchmarkTools.Trial: 23 samples with 1 evaluation.
 Range (min  max):  189.635 ms  370.411 ms  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     200.284 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   221.056 ms ±  49.187 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%

   █▅                                                            
  ▅███▁██▅▁▁▁▁▅▁▁▁▁▅▅▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅▁▅ ▁
  190 ms           Histogram: frequency by time          370 ms <

@SobhanMP
Copy link
Member Author

i could replace the last two loops with

return all(iszero, view(nonzeros(A), i:nnz(A))) && all(iszero, view(nonzeros(B), j:nnz(B)))

@SobhanMP
Copy link
Member Author

SobhanMP commented Sep 22, 2022

@ViralBShah so do i replace it or no?

@ViralBShah
Copy link
Member

I think either way is fine.

@SobhanMP SobhanMP merged commit 711a0af into main Sep 22, 2022
@SobhanMP SobhanMP deleted the so/veceq branch September 22, 2022 14:59
fredrikekre added a commit to JuliaLang/julia that referenced this pull request Sep 22, 2022
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)
fredrikekre added a commit to JuliaLang/julia that referenced this pull request Sep 27, 2022
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)
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.

Missing method for == on sparse vectors
4 participants