From 45635268fe76e34eedf9b145dbd5a5d8380dcc0f Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Fri, 26 Feb 2016 09:06:10 +0100 Subject: [PATCH 1/2] Remove throwing squeeze(::SparseMatrixCSC, ::Dims). The default implementation in abstractarray.jl does the right thing now, so no need to throw an error instead of letting it work. --- base/sparse/sparsematrix.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 61f62b5b421e0..8a9c86792f17a 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -2692,8 +2692,6 @@ function blkdiag(X::SparseMatrixCSC...) SparseMatrixCSC(m, n, colptr, rowval, nzval) end -squeeze(S::SparseMatrixCSC, dims::Dims) = throw(ArgumentError("squeeze is not available for sparse matrices")) - ## Structure query functions issym(A::SparseMatrixCSC) = is_hermsym(A, IdFun()) From 7c54abdb275f260ad4005afa3d025316fafb3446 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Fri, 26 Feb 2016 09:50:25 +0100 Subject: [PATCH 2/2] Add test for squeeze on sparse matrices. --- test/sparsedir/sparse.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/sparsedir/sparse.jl b/test/sparsedir/sparse.jl index 61daeccb638df..30ac264e89af1 100644 --- a/test/sparsedir/sparse.jl +++ b/test/sparsedir/sparse.jl @@ -74,6 +74,18 @@ a116[p, p] = reshape(1:9, 3, 3) s116[p, p] = reshape(1:9, 3, 3) @test a116 == s116 +# squeeze +for i = 1:5 + am = sprand(20, 1, 0.2) + av = squeeze(am, 2) + @test ndims(av) == 1 + @test all(av.==am) + am = sprand(1, 20, 0.2) + av = squeeze(am, 1) + @test ndims(av) == 1 + @test all(av.'.==am) +end + # matrix-vector multiplication (non-square) for i = 1:5 a = sprand(10, 5, 0.5)