diff --git a/src/SparseMatrixCSR.jl b/src/SparseMatrixCSR.jl index 58f31f0..b3731bd 100644 --- a/src/SparseMatrixCSR.jl +++ b/src/SparseMatrixCSR.jl @@ -55,6 +55,20 @@ function SparseMatrixCSR(a::Transpose{Tv,<:SparseMatrixCSC} where Tv) SparseMatrixCSR{1}(size(a,1),size(a,2),at.colptr,rowvals(at),nonzeros(at)) end +""" + SparseMatrixCSR(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`. +""" +SparseMatrixCSR(a::AbstractMatrix) = SparseMatrixCSR(sparse(a)) + """ SparseMatrixCSR{Bi}(a::Transpose{Tv,<:SparseMatrixCSC} where Tv) where Bi diff --git a/test/SparseMatrixCSR.jl b/test/SparseMatrixCSR.jl index f9ef797..79363a4 100644 --- a/test/SparseMatrixCSR.jl +++ b/test/SparseMatrixCSR.jl @@ -105,6 +105,10 @@ function test_csr(Bi,Tv,Ti) mul!(z,CSC,x) @test y ≈ z + # test constructors + @test CSR == SparseMatrixCSR(CSC) + @test CSR == SparseMatrixCSR(Matrix(CSC)) + _CSR = copy(CSR) out = LinearAlgebra.rmul!(CSR,-1) @test out === CSR