From f2d4633226252f06b5cb16e00a0ea2cb7b7726ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 5 Nov 2024 11:57:24 +0100 Subject: [PATCH] Add preliminary tests --- src/Sparse/Row.jl | 8 ++++++++ test/Sparse/Row.jl | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Sparse/Row.jl b/src/Sparse/Row.jl index 6ace77342a..447c7cc4b4 100644 --- a/src/Sparse/Row.jl +++ b/src/Sparse/Row.jl @@ -105,6 +105,14 @@ function Base.empty!(A::SRow) return A end +function Base.empty(A::SRow) + return sparse_row(base_ring(A)) +end + +function zero(A::SRow) + return empty(A) +end + function swap!(A::SRow, B::SRow) A.pos, B.pos = B.pos, A.pos A.values, B.values = B.values, A.values diff --git a/test/Sparse/Row.jl b/test/Sparse/Row.jl index 5b1e10f9be..06df0fd0c3 100644 --- a/test/Sparse/Row.jl +++ b/test/Sparse/Row.jl @@ -204,4 +204,33 @@ B = sparse_row(F,[1],[y]) C = add_scaled_row(A,B,F(1)) @test C == A+B + + # mutating arithmetic + randcoeff() = rand(-20:20) + Main.equality(A::SRow, B::SRow) = A == B + for _ in 1:10 + maxind_A = rand(0:10) + inds_A = Hecke.Random.randsubseq(1:maxind_A, rand()) + vals_A = [rand(ZZ, -10:10) for _ in 1:length(inds_A)] + A = sparse_row(FlintZZ, inds_A, vals_A) + + maxind_B = rand(0:10) + inds_B = Hecke.Random.randsubseq(1:maxind_B, rand()) + vals_B = [rand(ZZ, -10:10) for _ in 1:length(inds_B)] + B = sparse_row(FlintZZ, inds_B, vals_B) + + test_mutating_op_like_zero(zero, zero!, A) + + test_mutating_op_like_neg(-, neg!, A) + + test_mutating_op_like_add(+, add!, A, B) + test_mutating_op_like_add(-, sub!, A, B) + # test_mutating_op_like_add(*, mul!, A, randcoeff()) + # test_mutating_op_like_add(*, mul!, randcoeff(), A) + # test_mutating_op_like_add(*, mul!, A, ZZ(randcoeff())) + # test_mutating_op_like_add(*, mul!, ZZ(randcoeff()), A) + + # test_mutating_op_like_addmul((a, b, c) -> a + b*c, addmul!, A, B, randcoeff()) + # test_mutating_op_like_addmul((a, b, c) -> a - b*c, submul!, A, B, randcoeff()) + end end