diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index d00defb5e6648..d9af41a9ab18b 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -1522,7 +1522,8 @@ function Base.isone(A::SparseMatrixCSC) return true end -sparse(s::UniformScaling, m::Integer, n::Integer) = SparseMatrixCSC(s, Dims((m, n))) +sparse(s::UniformScaling, dims::Dims{2}) = SparseMatrixCSC(s, dims) +sparse(s::UniformScaling, m::Integer, n::Integer) = sparse(s, Dims((m, n))) # TODO: More appropriate location? conj!(A::SparseMatrixCSC) = (@inbounds broadcast!(conj, A.nzval, A.nzval); A) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index 5c9e12c946987..81dcf3702236c 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -48,6 +48,12 @@ end @test SparseMatrixCSC{Float64,Int32}(2I, 3, 3)::SparseMatrixCSC{Float64,Int32} == Matrix(2I, 3, 3) @test SparseMatrixCSC{Float64,Int32}(0I, 3, 3)::SparseMatrixCSC{Float64,Int32} == Matrix(0I, 3, 3) end +@testset "sparse(S::UniformScaling, shape...) convenience constructors" begin + # we exercise these methods only lightly as these methods call the SparseMatrixCSC + # constructor methods well-exercised by the immediately preceding testset + @test sparse(2I, 3, 4)::SparseMatrixCSC{Int,Int} == Matrix(2I, 3, 4) + @test sparse(2I, (3, 4))::SparseMatrixCSC{Int,Int} == Matrix(2I, 3, 4) +end se33 = SparseMatrixCSC{Float64}(I, 3, 3) do33 = ones(3)