Skip to content

Commit 405a8d5

Browse files
authored
make zero preserve indextype (#710)
Closes #574 The appropriate function to extract the index type is `indtype`, not `keytype`. Since it already works correctly the only thing to do is fix the `zero` method.
1 parent 6de7bed commit 405a8d5

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/SparseArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if Base.USE_GPL_LIBS
8787
include("solvers/spqr.jl")
8888
end
8989

90-
zero(a::AbstractSparseArray) = spzeros(eltype(a), size(a)...)
90+
zero(a::AbstractSparseArray{Tv,Ti}) where {Tv,Ti} = spzeros(Tv, Ti, size(a)...)
9191

9292
LinearAlgebra.diagzero(D::Diagonal{<:AbstractSparseMatrix{T}},i,j) where {T} =
9393
spzeros(T, size(D.diag[i], 1), size(D.diag[j], 2))

test/issues.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,13 @@ end
805805
7 16 4])
806806
end
807807

808+
@testset "Issue #574" begin
809+
a = spzeros(Float32, Int16, 2, 3)
810+
v = spzeros(Float32, Int16, 2)
811+
@test eltype(rowvals(zero(a))) <: Int16
812+
@test eltype(rowvals(zero(v))) <: Int16
813+
end
814+
808815
end # SparseTestsBase
809816

810817
end # module

0 commit comments

Comments
 (0)