From d44095a27455e2babe1a4b4a790c4db9cc6aef65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 26 Sep 2023 15:51:23 +0200 Subject: [PATCH] Add tests --- src/Sparse/Matrix.jl | 2 +- src/Sparse/Row.jl | 2 +- src/Sparse/ZZRow.jl | 2 +- test/Sparse/Matrix.jl | 11 +++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Sparse/Matrix.jl b/src/Sparse/Matrix.jl index 912bdce5b3..c510ebaa63 100644 --- a/src/Sparse/Matrix.jl +++ b/src/Sparse/Matrix.jl @@ -1241,7 +1241,7 @@ similar(A::SMat, m::Int, n::Int) = sparse_matrix(base_ring(A), m, n) ################################################################################ # -# (Block) diagonal matrices +# Block diagonal matrices # ################################################################################ diff --git a/src/Sparse/Row.jl b/src/Sparse/Row.jl index 79a10c479f..8b12dad349 100644 --- a/src/Sparse/Row.jl +++ b/src/Sparse/Row.jl @@ -89,7 +89,7 @@ end Constructs the sparse row $(a_i)_i$ over $R$ with $a_{i_j} = x_j$, where $J = (i_j)_j$ and $V = (x_j)_j$. """ -function sparse_row(R::Ring, pos::Vector{Int}, val::Vector{T}; sort::Bool = true) where T +function sparse_row(R::Ring, pos::Vector{Int}, val::AbstractVector{T}; sort::Bool = true) where T if sort p = sortperm(pos) pos = pos[p] diff --git a/src/Sparse/ZZRow.jl b/src/Sparse/ZZRow.jl index 64074b63e1..10ff5cd026 100644 --- a/src/Sparse/ZZRow.jl +++ b/src/Sparse/ZZRow.jl @@ -249,7 +249,7 @@ function sparse_row(R::ZZRing, A::Vector{Tuple{Int64, ZZRingElem}}; sort::Bool = return SRow(R, l, a) end -function sparse_row(R::ZZRing, pos::Vector{Int64}, val::Vector{ZZRingElem}; sort::Bool = true) +function sparse_row(R::ZZRing, pos::Vector{Int64}, val::AbstractVector{ZZRingElem}; sort::Bool = true) if sort p = sortperm(pos) pos = pos[p] diff --git a/test/Sparse/Matrix.jl b/test/Sparse/Matrix.jl index 47dd6c0b6b..a21589269c 100644 --- a/test/Sparse/Matrix.jl +++ b/test/Sparse/Matrix.jl @@ -264,6 +264,17 @@ using Hecke.SparseArrays @test D == sparse_matrix(FlintZZ, [0 0 0; 0 0 0; 0 0 0; 0 0 0]); @test D == sparse_matrix(FlintZZ, 4, 3) + # Block diag matrix + + D1 = sparse_matrix(FlintZZ, [1 5; 0 1]) + D2 = sparse_matrix(FlintZZ, [2 3 8; 4 0 0]) + D = @inferred block_diagonal_matrix([D1, D2]) + @test D == sparse_matrix(FlintZZ, [1 5 0 0 0; 0 1 0 0 0; 0 0 2 3 8; 0 0 4 0 0]) + D = @inferred diagonal_matrix([D1, D2]) + @test D == sparse_matrix(FlintZZ, [1 5 0 0 0; 0 1 0 0 0; 0 0 2 3 8; 0 0 4 0 0]) + D = @inferred diagonal_matrix(D1, D2) + @test D == sparse_matrix(FlintZZ, [1 5 0 0 0; 0 1 0 0 0; 0 0 2 3 8; 0 0 4 0 0]) + # Concatenation syntax D = sparse_matrix(FlintZZ, [1 5 3; 0 -10 0; 0 1 0])