Skip to content

Commit

Permalink
Keep parametric information when constructing a SparseMatrixCSC from …
Browse files Browse the repository at this point in the history
…a SparseMatrixCSC. (#28642)

(cherry picked from commit 686ffdb)
  • Loading branch information
pkofod authored and KristofferC committed Aug 19, 2018
1 parent 035f320 commit 7a71b07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ similar(S::SparseMatrixCSC, ::Type{TvNew}, ::Type{TiNew}, m::Integer, n::Integer


# converting between SparseMatrixCSC types
SparseMatrixCSC(S::SparseMatrixCSC) = copy(S)
AbstractMatrix{Tv}(A::SparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(A)
SparseMatrixCSC{Tv}(S::SparseMatrixCSC{Tv}) where {Tv} = copy(S)
SparseMatrixCSC{Tv}(S::SparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv,eltype(S.colptr)}(S)
Expand Down
6 changes: 6 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2289,4 +2289,10 @@ end
@test adjoint(MC) == copy(adjoint(SC))
end

@testset "Issue #28634" begin
a = SparseMatrixCSC{Int8, Int16}([1 2; 3 4])
na = SparseMatrixCSC(a)
@test typeof(a) === typeof(na)
end

end # module

0 comments on commit 7a71b07

Please sign in to comment.