Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/SparseMatrixCSR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct SparseMatrixCSR{Bi,Tv,Ti} <: AbstractSparseMatrix{Tv,Ti}
throw(ArgumentError("$str must be $r, got $k"))
m < 0 && throwsz("m",">=0",m)
n < 0 && throwsz("n",">=0", n)
length(rowptr) != m+1 && throwsz("lengh(rowptr)",m+1,length(rowptr))
length(rowptr) != m+1 && throwsz("length(rowptr)",m+1,length(rowptr))
rowptr[end]-Bi != length(nzval) && throwsz("rowptr[end]-Bi",rowptr[m+1]-Bi, length(nzval))
new{Bi,Tv,Ti}(Int(m), Int(n), rowptr, colval, nzval)
end
Expand All @@ -58,14 +58,14 @@ end
"""
SparseMatrixCSR(a::SparseMatrixCSC}

Build a 1-based `SparseMatrixCSR` from a `SparseMatrixCSC`.
Build a 1-based `SparseMatrixCSR` from a `SparseMatrixCSC`.
"""
SparseMatrixCSR(a::SparseMatrixCSC) = SparseMatrixCSR(transpose(sparse(transpose(a))))

"""
SparseMatrixCSR(a::AbstractMatrix}

Build a 1-based `SparseMatrixCSR` from an `AbstractMatrix`.
Build a 1-based `SparseMatrixCSR` from an `AbstractMatrix`.
"""
SparseMatrixCSR(a::AbstractMatrix) = SparseMatrixCSR(sparse(a))

Expand Down Expand Up @@ -141,6 +141,11 @@ function LinearAlgebra.fillstored!(a::SparseMatrixCSR,v)
a
end

function Base.fill!(a::SparseMatrixCSR,v)
iszero(v) && return LinearAlgebra.fillstored!(a,v)
invoke(Base.fill!,Tuple{AbstractMatrix,typeof(v)},a,v)
end

function LinearAlgebra.rmul!(a::SparseMatrixCSR,v::Number)
rmul!(a.nzval,v)
a
Expand Down
4 changes: 4 additions & 0 deletions test/SparseMatrixCSR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ function test_csr(Bi,Tv,Ti)
mul!(z,CSC,x)
@test y ≈ z

@test_throws ArgumentError fill!(CSR2,3.33)
fill!(CSR2, 0)
@test all(iszero, CSR2)

# test constructors
@test CSR == SparseMatrixCSR(CSC)
@test CSR == SparseMatrixCSR(Matrix(CSC))
Expand Down