Skip to content

Commit

Permalink
Add is_zero_entry method; remove is_zero_row methods (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Jun 25, 2024
1 parent fbaf374 commit 5ec098c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 36 deletions.
25 changes: 0 additions & 25 deletions src/HeckeMiscMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,6 @@ function Array(a::ZZMatrix; S::Type{T}=ZZRingElem) where {T}
return A
end

function is_zero_row(M::ZZMatrix, i::Int)
!(1 <= i <= nrows(M)) && error("Not a valid index")
GC.@preserve M begin
for j = 1:ncols(M)
m = ccall((:fmpz_mat_entry, libflint), Ptr{ZZRingElem}, (Ref{ZZMatrix}, Int, Int), M, i - 1, j - 1)
fl = ccall((:fmpz_is_zero, libflint), Bool, (Ptr{ZZRingElem},), m)
if !fl
return false
end
end
end
return true
end

function is_zero_row(M::zzModMatrix, i::Int)
zero = UInt(0)
for j in 1:ncols(M)
t = ccall((:nmod_mat_get_entry, libflint), Base.GMP.Limb, (Ref{zzModMatrix}, Int, Int), M, i - 1, j - 1)
if t != zero
return false
end
end
return true
end

################################################################################
#
################################################################################
Expand Down
7 changes: 0 additions & 7 deletions src/flint/gfp_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ function one(a::fpMatrixSpace)
return z
end

@inline function is_zero_entry(A::fpMatrix, i::Int, j::Int)
@boundscheck _checkbounds(A, i, j)
x = ccall((:nmod_mat_get_entry, libflint), UInt,
(Ref{fpMatrix}, Int, Int), A, i - 1, j - 1)
return x == 0
end

################################################################################
#
# Ad hoc binary operators
Expand Down
8 changes: 6 additions & 2 deletions src/flint/nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ zero(m::zzModMatrix, R::zzModRing, r::Int, c::Int) = similar(m, R, r, c)

@inline function getindex(a::zzModMatrix, i::Int, j::Int)
@boundscheck _checkbounds(a, i, j)
u = ccall((:nmod_mat_get_entry, libflint), UInt,
(Ref{zzModMatrix}, Int, Int), a, i - 1 , j - 1)
u = getindex_raw(a, i, j)
return zzModRingElem(u, base_ring(a)) # no reduction needed
end

Expand Down Expand Up @@ -116,6 +115,11 @@ function iszero(a::T) where T <: Zmodn_mat
return Bool(r)
end

@inline function is_zero_entry(A::T, i::Int, j::Int) where T <: Zmodn_mat
@boundscheck _checkbounds(A, i, j)
return is_zero(getindex_raw(A, i, j))
end

################################################################################
#
# Comparison
Expand Down
9 changes: 8 additions & 1 deletion test/flint/fmpq_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ end
@testset "QQMatrix.is_zero_entry" begin
M = matrix(QQ, [1 2 3;4 0 6;0 8 9])
for i in 1:3, j in 1:3
@test is_zero_entry(M, i, j) == (M[i, j] == 0)
@test is_zero_entry(M, i, j) == is_zero(M[i, j])
end
end

@testset "QQMatrix.is_zero_row" begin
M = matrix(QQ, [1 2 3;4 0 6;0 8 9;0 0 0])
for i in 1:nrows(M)
@test is_zero_row(M, i) == all(j -> is_zero(M[i, j]), 1:ncols(M))
end
end

Expand Down
9 changes: 8 additions & 1 deletion test/flint/fmpz_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ end
@testset "ZZMatrix.is_zero_entry" begin
M = matrix(ZZ, [1 2 3;4 0 6;0 8 9])
for i in 1:3, j in 1:3
@test is_zero_entry(M, i, j) == (M[i, j] == 0)
@test is_zero_entry(M, i, j) == is_zero(M[i, j])
end
end

@testset "ZZMatrix.is_zero_row" begin
M = matrix(ZZ, [1 2 3;4 0 6;0 8 9;0 0 0])
for i in 1:nrows(M)
@test is_zero_row(M, i) == all(j -> is_zero(M[i, j]), 1:ncols(M))
end
end

Expand Down
16 changes: 16 additions & 0 deletions test/flint/gfp_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ end
end
end

@testset "fpMatrix.is_zero_entry" begin
R = Native.GF(13)
M = matrix(R, [1 2 3;4 0 6;0 8 9])
for i in 1:3, j in 1:3
@test is_zero_entry(M, i, j) == is_zero(M[i, j])
end
end

@testset "fpMatrix.is_zero_row" begin
R = Native.GF(13)
M = matrix(R, [1 2 3;4 0 6;0 8 9;0 0 0])
for i in 1:nrows(M)
@test is_zero_row(M, i) == all(j -> is_zero(M[i, j]), 1:ncols(M))
end
end

@testset "fpMatrix.printing" begin
Z2 = Native.GF(2)
R = fpMatrixSpace(Z2, 2, 2)
Expand Down
16 changes: 16 additions & 0 deletions test/flint/nmod_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ end
end
end

@testset "zzModMatrix.is_zero_entry" begin
R, = residue_ring(ZZ, 13)
M = matrix(R, [1 2 3;4 0 6;0 8 9])
for i in 1:3, j in 1:3
@test is_zero_entry(M, i, j) == is_zero(M[i, j])
end
end

@testset "zzModMatrix.is_zero_row" begin
R, = residue_ring(ZZ, 13)
M = matrix(R, [1 2 3;4 0 6;0 8 9;0 0 0])
for i in 1:nrows(M)
@test is_zero_row(M, i) == all(j -> is_zero(M[i, j]), 1:ncols(M))
end
end

@testset "zzModMatrix.printing" begin
Z2, = residue_ring(ZZ, 2)
R = zzModMatrixSpace(Z2, 2, 2)
Expand Down

0 comments on commit 5ec098c

Please sign in to comment.