Skip to content

Commit

Permalink
Clean up fq_nmod_mat_entry_set calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Oct 18, 2024
1 parent bafe7b9 commit 0909192
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
57 changes: 19 additions & 38 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5827,72 +5827,54 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem}

function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{fqPolyRepFieldElem}, ctx::fqPolyRepField)
z = fqPolyRepMatrix(r, c, ctx)
GC.@preserve z for i = 1:r
for j = 1:c
ccall((:fq_nmod_mat_entry_set, libflint), Nothing,
(Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
z, i - 1, j - 1, arr[i, j], ctx)
end
for i = 1:r, j = 1:c
el = arr[i, j]
@inbounds z[i, j] = el
end
return z
end

function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{fqPolyRepFieldElem}, ctx::fqPolyRepField)
z = fqPolyRepMatrix(r, c, ctx)
GC.@preserve z for i = 1:r
for j = 1:c
ccall((:fq_nmod_mat_entry_set, libflint), Nothing,
(Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
z, i - 1, j - 1, arr[(i - 1) * c + j], ctx)
end
for i = 1:r, j = 1:c
el = arr[(i - 1) * c + j]
@inbounds z[i, j] = el
end
return z
end

function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::fqPolyRepField)
z = fqPolyRepMatrix(r, c, ctx)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
ccall((:fq_nmod_set_fmpz, libflint), Nothing,
(Ptr{fqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{fqPolyRepField}), el, arr[i, j], ctx)
end
for i = 1:r, j = 1:c
el = arr[i, j]
@inbounds z[i, j] = el
end
return z
end

function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::fqPolyRepField)
z = fqPolyRepMatrix(r, c, ctx)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
ccall((:fq_nmod_set_fmpz, libflint), Nothing,
(Ptr{fqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{fqPolyRepField}), el, arr[(i - 1) * c + j], ctx)
end
for i = 1:r, j = 1:c
el = arr[(i - 1) * c + j]
@inbounds z[i, j] = el
end
return z
end

function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::fqPolyRepField) where {T <: Integer}
z = fqPolyRepMatrix(r, c, ctx)
GC.@preserve z for i = 1:r
for j = 1:c
ccall((:fq_nmod_mat_entry_set, libflint), Nothing,
(Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
z, i - 1, j - 1, ctx(arr[i, j]), ctx)
end
for i = 1:r, j = 1:c
el = ctx(arr[i, j])
@inbounds z[i, j] = el
end
return z
end

function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::fqPolyRepField) where {T <: Integer}
z = fqPolyRepMatrix(r, c, ctx)
GC.@preserve z for i = 1:r
for j = 1:c
ccall((:fq_nmod_mat_entry_set, libflint), Nothing,
(Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
z, i - 1, j - 1, ctx(arr[(i - 1) * c + j]), ctx)
end
for i = 1:r, j = 1:c
el = ctx(arr[(i - 1) * c + j])
@inbounds z[i, j] = el
end
return z
end
Expand All @@ -5901,8 +5883,7 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem}
ctx = parent(d)
z = fqPolyRepMatrix(r, c, ctx)
for i = 1:min(r, c)
ccall((:fq_nmod_mat_entry_set, libflint), Nothing,
(Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), z, i - 1, i- 1, d, ctx)
@inbounds z[i, i] = d
end
return z
end
Expand Down
8 changes: 4 additions & 4 deletions src/flint/fq_nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ end
return z
end

@inline function setindex!(a::fqPolyRepMatrix, u::fqPolyRepFieldElem, i::Int, j::Int)
@inline function setindex!(a::fqPolyRepMatrix, u::fqPolyRepFieldElemOrPtr, i::Int, j::Int)
@boundscheck _checkbounds(a, i, j)
ccall((:fq_nmod_mat_entry_set, libflint), Nothing,
(Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
a, i - 1, j - 1, u, base_ring(a))
@ccall libflint.fq_nmod_mat_entry_set(
a::Ref{fqPolyRepMatrix}, (i-1)::Int, (j-1)::Int, u::Ref{fqPolyRepFieldElem}, base_ring(a)::Ref{fqPolyRepField}
)::Nothing
end

@inline function setindex!(a::fqPolyRepMatrix, u::ZZRingElem, i::Int, j::Int)
Expand Down

0 comments on commit 0909192

Please sign in to comment.