From e6356e0fd52a70936dc6f9ebfefbb54cc3970aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 27 Sep 2023 17:36:36 +0200 Subject: [PATCH] Add `-(::SMat)` --- src/Sparse/Matrix.jl | 6 +++++- test/Sparse/Matrix.jl | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Sparse/Matrix.jl b/src/Sparse/Matrix.jl index c510ebaa63..9b6cb3743a 100644 --- a/src/Sparse/Matrix.jl +++ b/src/Sparse/Matrix.jl @@ -643,10 +643,14 @@ end ################################################################################ # -# Addition +# Arithmetics # ################################################################################ +function -(A::SMat) + return map_entries(-, A) +end + function +(A::SMat{T}, B::SMat{T}) where T nrows(A) != nrows(B) && error("Matrices must have same number of rows") ncols(A) != ncols(B) && error("Matrices must have same number of columns") diff --git a/test/Sparse/Matrix.jl b/test/Sparse/Matrix.jl index a21589269c..54b6f192dc 100644 --- a/test/Sparse/Matrix.jl +++ b/test/Sparse/Matrix.jl @@ -171,6 +171,9 @@ using Hecke.SparseArrays DminusE = @inferred D - E @test DminusE == sparse_matrix(FlintZZ, [0 0 3; -1 1 -1; 0 1 0]) + minusD = @inferred -D + @test minusD == sparse_matrix(FlintZZ, [-1 -5 -3; 0 -1 0; 0 -1 0]) + # Scalar multiplication D = sparse_matrix(FlintZZ, [1 5 3; 0 0 0; 0 1 0])