Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Nov 6, 2024
1 parent 8473c78 commit 79f833f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/SparseMatrixCSR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ issparse(S::SparseMatrixCSR) = true
Returns the number of stored (filled) elements in a sparse array.
"""
nnz(S::SparseMatrixCSR) = Int(getrowptr(S)[size(S, 1) + 1]) - 1
nnz(S::SparseMatrixCSR{Bi}) where Bi = Int(S.rowptr[size(S, 1) + 1] - Bi)

"""
nonzeros(S::SparseMatrixCSR)
Expand Down
22 changes: 11 additions & 11 deletions test/SparseMatrixCSR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function test_csr(Bi,Tv,Ti)
@test getBi(CSR) == Bi
@test getoffset(CSR) == 1-Bi
@test nnz(CSR) == nnz(CSC)
@test length(nonzeros(CSR)) == nnz(CSR)
@test length(SparseArrays.nzvalview(CSR)) == nnz(CSR)
@test nonzeros(CSR) === CSR.nzval
@test colvals(CSR) === CSR.colval
i,j,v = findnz(CSR)
Expand Down Expand Up @@ -117,10 +117,10 @@ function test_csr(Bi,Tv,Ti)

# Test overlong buffers
let A = sparsecsr([1, 2, 3], [1, 2, 3], [4., 5, 6])
push!(A.nzval, 4.0)
push!(A.rowptr, -1)
@test nnz(A) == length(SparseArrays.nzvalview(A)) == 3
@test SparseArrays.nzvalview(A) == [4., 5, 6]
push!(A.nzval, 4.0)
push!(A.rowptr, -1)
@test nnz(A) == length(SparseArrays.nzvalview(A)) == 3
@test SparseArrays.nzvalview(A) == [4., 5, 6]
end
end

Expand All @@ -146,13 +146,13 @@ for Bi in (0,1)
end

if Base.USE_GPL_LIBS # `lu!` requires `SuiteSparse.UMFPACK`
I = [1,1,2,2,2,3,3]
J = [1,2,1,2,3,2,3]
V = [4.0,1.0,-1.0,4.0,1.0,-1.0,4.0]
test_lu(0,I,J,V)
test_lu(1,I,J,V)
I = [1,1,2,2,2,3,3]
J = [1,2,1,2,3,2,3]
V = [4.0,1.0,-1.0,4.0,1.0,-1.0,4.0]
test_lu(0,I,J,V)
test_lu(1,I,J,V)
else
@warn "Tests run without GPL libraries."
@warn "Tests run without GPL libraries."
end

end # module

0 comments on commit 79f833f

Please sign in to comment.