From 686ffdb98bab3e9a3db7c5654bcbf85ecf56cee7 Mon Sep 17 00:00:00 2001 From: Patrick Kofod Mogensen Date: Tue, 14 Aug 2018 20:30:39 +0200 Subject: [PATCH] Keep parametric information when constructing a SparseMatrixCSC from a SparseMatrixCSC. (#28642) --- stdlib/SparseArrays/src/sparsematrix.jl | 1 + stdlib/SparseArrays/test/sparse.jl | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index a88f27edd90d1..f954d33393d61 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -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) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index f88c6dde06493..0c17946d7a5d8 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -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