Skip to content

Commit

Permalink
More set! methods for fqPolyRepFieldElem (#1810)
Browse files Browse the repository at this point in the history
Also set parent already in the constructors.

Note how all those constructors using set! now have identical
implementation besides the differing argument types.
  • Loading branch information
fingolfin authored Jul 1, 2024
1 parent bb40c3f commit 79c9770
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
6 changes: 0 additions & 6 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,6 @@ function ^(a::ResElem, f::ZZRingElem)
return b
end

function set!(z::fqPolyRepFieldElem, x::fqPolyRepFieldElem)
ccall((:fq_nmod_set, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
z, x, parent(z))
end

characteristic(F::EuclideanRingResidueField{ZZRingElem}) = abs(F.modulus)

#@doc raw"""
Expand Down
18 changes: 9 additions & 9 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,7 @@ mutable struct fqPolyRepFieldElem <: FinFieldElem
d = new()
ccall((:fq_nmod_init2, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), d, ctx)
d.parent = ctx
finalizer(_fq_nmod_clear_fn, d)
return d
end
Expand All @@ -2283,40 +2284,39 @@ mutable struct fqPolyRepFieldElem <: FinFieldElem
d = new()
ccall((:fq_nmod_init2, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), d, ctx)
d.parent = ctx
finalizer(_fq_nmod_clear_fn, d)
ccall((:fq_nmod_set_si, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Int, Ref{fqPolyRepField}), d, x, ctx)
set!(d, x)
return d
end

function fqPolyRepFieldElem(ctx::fqPolyRepField, x::ZZRingElem)
d = new()
ccall((:fq_nmod_init2, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), d, ctx)
d.parent = ctx
finalizer(_fq_nmod_clear_fn, d)
ccall((:fq_nmod_set_fmpz, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{fqPolyRepField}), d, x, ctx)
set!(d, x)
return d
end

function fqPolyRepFieldElem(ctx::fqPolyRepField, x::fqPolyRepFieldElem)
d = new()
ccall((:fq_nmod_init2, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), d, ctx)
d.parent = ctx
finalizer(_fq_nmod_clear_fn, d)
ccall((:fq_nmod_set, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), d, x, ctx)
set!(d, x)
return d
end

function fqPolyRepFieldElem(ctx::fqPolyRepField, x::fpPolyRingElem)
d = new()
ccall((:fq_nmod_init2, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), d, ctx)
d.parent = ctx
finalizer(_fq_nmod_clear_fn, d)
ccall((:fq_nmod_set_nmod_poly, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fpPolyRingElem}, Ref{fqPolyRepField}),
d, x, ctx)
set!(d, x)
return d
end
end
Expand Down
35 changes: 30 additions & 5 deletions src/flint/fq_nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ end

function deepcopy_internal(d::fqPolyRepFieldElem, dict::IdDict)
z = fqPolyRepFieldElem(parent(d), d)
z.parent = parent(d)
return z
end

Expand Down Expand Up @@ -460,6 +459,36 @@ end
#
###############################################################################

function set!(z::fqPolyRepFieldElem, x::fqPolyRepFieldElem)
ccall((:fq_nmod_set, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}),
z, x, parent(z))
end

function set!(z::fqPolyRepFieldElem, x::ZZRingElem)
ccall((:fq_nmod_set_fmpz, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{fqPolyRepField}),
z, x, parent(z))
end

function set!(z::fqPolyRepFieldElem, x::Int)
ccall((:fq_nmod_set_si, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Int, Ref{fqPolyRepField}),
z, x, parent(z))
end

function set!(z::fqPolyRepFieldElem, x::UInt)
ccall((:fq_nmod_set_ui, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, UInt, Ref{fqPolyRepField}),
z, x, parent(z))
end

function set!(z::fqPolyRepFieldElem, x::fpPolyRingElem)
ccall((:fq_nmod_set_nmod_poly, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fpPolyRingElem}, Ref{fqPolyRepField}),
z, x, parent(z))
end

function zero!(z::fqPolyRepFieldElem)
ccall((:fq_nmod_zero, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), z, z.parent)
Expand Down Expand Up @@ -633,21 +662,18 @@ promote_rule(::Type{fqPolyRepFieldElem}, ::Type{fpFieldElem}) = fqPolyRepFieldEl

function (a::fqPolyRepField)()
z = fqPolyRepFieldElem(a)
z.parent = a
return z
end

(a::fqPolyRepField)(b::Integer) = a(ZZRingElem(b))

function (a::fqPolyRepField)(b::Int)
z = fqPolyRepFieldElem(a, b)
z.parent = a
return z
end

function (a::fqPolyRepField)(b::ZZRingElem)
z = fqPolyRepFieldElem(a, b)
z.parent = a
return z
end

Expand All @@ -674,7 +700,6 @@ function (a::fqPolyRepField)(b::Vector{<:IntegerUnion})
da == db || error("Coercion impossible")
F = Native.GF(Int(characteristic(a)), cached = false)
z = fqPolyRepFieldElem(a, polynomial(F, b))
z.parent = a
return z
end

Expand Down

0 comments on commit 79c9770

Please sign in to comment.