From 20858ebc3dd0bf417c1fe72acfd2843db15f5ba7 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sun, 19 Nov 2017 15:47:41 -0800 Subject: [PATCH] Add sparse(S::UniformScaling, dims::Dims{2}) method. --- base/sparse/sparsematrix.jl | 3 ++- test/sparse/sparse.jl | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index cee0f6d56f839..6f860bf58fc4b 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 bdce9ef415a2b..ce9e741eeccc5 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} == 2*eye(3) @test SparseMatrixCSC{Float64,Int32}(0I, 3, 3)::SparseMatrixCSC{Float64,Int32} == spzeros(Float64, Int32, 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)