Skip to content

Commit

Permalink
Do add_one! differently and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt committed Apr 11, 2024
1 parent 7faebe1 commit 1c32a42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/flint/fq_default_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ function setindex!(a::FqMatrix, b::FqMatrix, r::UnitRange{Int64}, c::UnitRange{I
end

function Generic.add_one!(a::FqMatrix, i::Int, j::Int)
k = base_ring(a)
if _fq_default_ctx_type(k) == _FQ_DEFAULT_NMOD
x = ccall((:nmod_mat_get_entry, libflint), Int, (Ref{FqMatrix}, Int, Int), a, i-1, j-1)
x = ccall((:nmod_add, libflint), Int, (Int, Int, Ref{FqField}), x, 1, k)
ccall((:nmod_mat_set_entry, libflint), Int, (Ref{FqMatrix}, Int, Int, Int), a, i-1, j-1, x)
else
a[i, j] += 1
@boundscheck Generic._checkbounds(a, i, j)
F = base_ring(a)
GC.@preserve a begin
x = fq_default_mat_entry_ptr(a, i, j)
ccall((:fq_default_add, libflint), Nothing,
(Ptr{FqFieldElem}, Ptr{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), x, x, one(F), F)
end
return a
end

function deepcopy_internal(a::FqMatrix, dict::IdDict)
Expand Down
3 changes: 3 additions & 0 deletions test/flint/fq_default_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ end

@test_throws DimensionMismatch C[1:2, 2:3] = F9[3 3]
@test_throws BoundsError C[1:2, 3:4] = F9[3 3; 3 3]

Generic.add_one!(C, 1, 1)
@test C == F9[2 3 3; 4 3 3; 7 7 5]
end

@testset "FqMatrix.unary_ops" begin
Expand Down

0 comments on commit 1c32a42

Please sign in to comment.