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

reverse for sparse vector/matrix #450

Merged
merged 7 commits into from
Oct 31, 2023
Merged

reverse for sparse vector/matrix #450

merged 7 commits into from
Oct 31, 2023

Conversation

jishnub
Copy link
Collaborator

@jishnub jishnub commented Oct 3, 2023

This ensures that reverse doesn't add spurious zeros to a sparse array. Currently, it's only implemented for vectors Implemented for both vectors and matrices.
On main

julia> S = sparsevec([2, 4, 5 ,8], [0.1, 0.2, 0.3, 0.4], 10)
10-element SparseVector{Float64, Int64} with 4 stored entries:
  [2]  =  0.1
  [4]  =  0.2
  [5]  =  0.3
  [8]  =  0.4

julia> reverse(S)
10-element SparseVector{Float64, Int64} with 8 stored entries:
  [2]  =  0.0
  [3]  =  0.4
  [4]  =  0.0
  [5]  =  0.0
  [6]  =  0.3
  [7]  =  0.2
  [8]  =  0.0
  [9]  =  0.1

julia> @btime reverse($S);
  315.448 ns (4 allocations: 352 bytes)

This PR

julia> reverse(S)
10-element SparseVector{Float64, Int64} with 4 stored entries:
  [3]  =  0.4
  [6]  =  0.3
  [7]  =  0.2
  [9]  =  0.1

julia> @btime reverse($S);
  113.827 ns (2 allocations: 192 bytes)

@codecov
Copy link

codecov bot commented Oct 3, 2023

Codecov Report

Merging #450 (cac8c40) into main (e86b148) will increase coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #450      +/-   ##
==========================================
+ Coverage   85.40%   85.51%   +0.11%     
==========================================
  Files          13       13              
  Lines        8734     8803      +69     
==========================================
+ Hits         7459     7528      +69     
  Misses       1275     1275              
Files Coverage Δ
src/SparseArrays.jl 83.33% <ø> (ø)
src/sparsematrix.jl 95.78% <100.00%> (+0.09%) ⬆️
src/sparsevector.jl 95.48% <100.00%> (+0.05%) ⬆️

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

@jishnub jishnub changed the title reverse for sparse vector reverse for sparse vector/matrix Oct 6, 2023
@jishnub
Copy link
Collaborator Author

jishnub commented Oct 6, 2023

Fixes JuliaLang/julia#51420

julia> A = sprand(5,5,0.3)
5×5 SparseMatrixCSC{Float64, Int64} with 8 stored entries:
          0.860008                 
                       0.569948    
 0.604659  0.428         0.139034  0.205955
 0.673227                          
                       0.367848    

julia> reverse(A)
5×5 SparseMatrixCSC{Float64, Int64} with 8 stored entries:
          0.367848                 
                                0.673227
 0.205955  0.139034      0.428     0.604659
          0.569948                 
                       0.860008    

@vtjnash vtjnash merged commit 911cf6a into main Oct 31, 2023
8 checks passed
@vtjnash vtjnash deleted the jishnub/reversesparsevec branch October 31, 2023 01:16
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