Skip to content

Commit

Permalink
Clean up fq_default_mat_entry_set uses
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Oct 18, 2024
1 parent 4fd7b1a commit bafe7b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 52 deletions.
64 changes: 19 additions & 45 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5574,78 +5574,54 @@ mutable struct FqMatrix <: MatElem{FqFieldElem}

function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{FqFieldElem}, ctx::FqField)
z = FqMatrix(r, c, ctx)
for i = 1:r
for j = 1:c
ccall((:fq_default_mat_entry_set, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{FqFieldElem},
Ref{FqField}),
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 FqMatrix(r::Int, c::Int, arr::AbstractVector{FqFieldElem}, ctx::FqField)
z = FqMatrix(r, c, ctx)
for i = 1:r
for j = 1:c
ccall((:fq_default_mat_entry_set, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{FqFieldElem},
Ref{FqField}),
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 FqMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::FqField)
z = FqMatrix(r, c, ctx)
for i = 1:r
for j = 1:c
ccall((:fq_default_mat_entry_set_fmpz, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{ZZRingElem},
Ref{FqField}),
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 FqMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::FqField)
z = FqMatrix(r, c, ctx)
for i = 1:r
for j = 1:c
ccall((:fq_default_mat_entry_set_fmpz, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{ZZRingElem},
Ref{FqField}),
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 FqMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::FqField) where {T <: Integer}
z = FqMatrix(r, c, ctx)
for i = 1:r
for j = 1:c
ccall((:fq_default_mat_entry_set, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{FqFieldElem},
Ref{FqField}),
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 FqMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::FqField) where {T <: Integer}
z = FqMatrix(r, c, ctx)
for i = 1:r
for j = 1:c
ccall((:fq_default_mat_entry_set, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{FqFieldElem},
Ref{FqField}),
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 @@ -5654,9 +5630,7 @@ mutable struct FqMatrix <: MatElem{FqFieldElem}
ctx = parent(d)
z = FqMatrix(r, c, ctx)
for i = 1:min(r, c)
ccall((:fq_default_mat_entry_set, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{FqFieldElem},
Ref{FqField}), z, i - 1, i - 1, d, ctx)
@inbounds z[i, i] = d
end
return z
end
Expand Down
11 changes: 4 additions & 7 deletions src/flint/fq_default_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ end
return z
end

@inline function setindex!(a::FqMatrix, u::FqFieldElem, i::Int, j::Int)
@inline function setindex!(a::FqMatrix, u::FqFieldElemOrPtr, i::Int, j::Int)
@boundscheck _checkbounds(a, i, j)
K = base_ring(a)
uu = K(u)
ccall((:fq_default_mat_entry_set, libflint), Nothing,
(Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, Ref{FqField}),
a, i - 1, j - 1, uu, base_ring(a))
nothing
@ccall libflint.fq_default_mat_entry_set(
a::Ref{FqMatrix}, (i-1)::Int, (j-1)::Int, u::Ref{FqFieldElem}, base_ring(a)::Ref{FqField}
)::Nothing
end

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

0 comments on commit bafe7b9

Please sign in to comment.