Skip to content

Commit

Permalink
Use setcoeff! in zzModPolyRingElem/fpPolyRingElem constructors (#1903)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Oct 18, 2024
1 parent 0c2c84d commit 633112d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
38 changes: 14 additions & 24 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,7 @@ mutable struct zzModPolyRingElem <: PolyRingElem{zzModRingElem}

function zzModPolyRingElem(n::UInt, a::UInt)
z = zzModPolyRingElem(n)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{zzModPolyRingElem}, Int, UInt), z, 0, a)
setcoeff!(z, 0, a)
return z
end

Expand All @@ -578,36 +577,32 @@ mutable struct zzModPolyRingElem <: PolyRingElem{zzModRingElem}
z = new()
ccall((:nmod_poly_init2, libflint), Nothing,
(Ref{zzModPolyRingElem}, UInt, Int), z, n, length(arr))
finalizer(_nmod_poly_clear_fn, z)
for i in 1:length(arr)
tt = ccall((:fmpz_fdiv_ui, libflint), UInt, (Ref{ZZRingElem}, UInt), arr[i], n)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{zzModPolyRingElem}, Int, UInt), z, i - 1, tt)
setcoeff!(z, i - 1, arr[i])
end
finalizer(_nmod_poly_clear_fn, z)
return z
end

function zzModPolyRingElem(n::UInt, arr::Vector{UInt})
z = new()
ccall((:nmod_poly_init2, libflint), Nothing,
(Ref{zzModPolyRingElem}, UInt, Int), z, n, length(arr))
finalizer(_nmod_poly_clear_fn, z)
for i in 1:length(arr)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{zzModPolyRingElem}, Int, UInt), z, i - 1, arr[i])
setcoeff!(z, i - 1, arr[i])
end
finalizer(_nmod_poly_clear_fn, z)
return z
end

function zzModPolyRingElem(n::UInt, arr::Vector{zzModRingElem})
z = new()
ccall((:nmod_poly_init2, libflint), Nothing,
(Ref{zzModPolyRingElem}, UInt, Int), z, n, length(arr))
finalizer(_nmod_poly_clear_fn, z)
for i in 1:length(arr)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{zzModPolyRingElem}, Int, UInt), z, i-1, arr[i].data)
setcoeff!(z, i-1, arr[i].data)
end
finalizer(_nmod_poly_clear_fn, z)
return z
end

Expand Down Expand Up @@ -697,8 +692,7 @@ mutable struct fpPolyRingElem <: PolyRingElem{fpFieldElem}

function fpPolyRingElem(n::UInt, a::UInt)
z = fpPolyRingElem(n)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{fpPolyRingElem}, Int, UInt), z, 0, a)
setcoeff!(z, 0, a)
return z
end

Expand All @@ -710,36 +704,32 @@ mutable struct fpPolyRingElem <: PolyRingElem{fpFieldElem}
z = new()
ccall((:nmod_poly_init2, libflint), Nothing,
(Ref{fpPolyRingElem}, UInt, Int), z, n, length(arr))
finalizer(_gfp_poly_clear_fn, z)
for i in 1:length(arr)
tt = ccall((:fmpz_fdiv_ui, libflint), UInt, (Ref{ZZRingElem}, UInt), arr[i], n)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{fpPolyRingElem}, Int, UInt), z, i - 1, tt)
setcoeff!(z, i - 1, arr[i])
end
finalizer(_gfp_poly_clear_fn, z)
return z
end

function fpPolyRingElem(n::UInt, arr::Vector{UInt})
z = new()
ccall((:nmod_poly_init2, libflint), Nothing,
(Ref{fpPolyRingElem}, UInt, Int), z, n, length(arr))
finalizer(_gfp_poly_clear_fn, z)
for i in 1:length(arr)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{fpPolyRingElem}, Int, UInt), z, i - 1, arr[i])
setcoeff!(z, i - 1, arr[i])
end
finalizer(_gfp_poly_clear_fn, z)
return z
end

function fpPolyRingElem(n::UInt, arr::Vector{fpFieldElem})
z = new()
ccall((:nmod_poly_init2, libflint), Nothing,
(Ref{fpPolyRingElem}, UInt, Int), z, n, length(arr))
finalizer(_gfp_poly_clear_fn, z)
for i in 1:length(arr)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{fpPolyRingElem}, Int, UInt), z, i-1, arr[i].data)
setcoeff!(z, i-1, arr[i].data)
end
finalizer(_gfp_poly_clear_fn, z)
return z
end

Expand Down
3 changes: 1 addition & 2 deletions src/flint/nmod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,7 @@ end

function setcoeff!(x::T, n::Int, y::ZZRingElem) where T <: Zmodn_poly
r = ccall((:fmpz_fdiv_ui, libflint), UInt, (Ref{ZZRingElem}, UInt), y, x.mod_n)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{T}, Int, UInt), x, n, r)
setcoeff!(x, n, r)
return x
end

Expand Down

0 comments on commit 633112d

Please sign in to comment.