From 97433a4bc0efd261c24590a4e107dd2a5cb42f55 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 17 Jan 2025 13:03:45 +0100 Subject: [PATCH] Add set! methods for QQ/ZZMPolyRingElem --- src/flint/FlintTypes.jl | 47 ++++++----------------------------------- src/flint/fmpq_mpoly.jl | 34 +++++++++++++++++++++++++++-- src/flint/fmpz_mpoly.jl | 30 ++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 45 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index 085ad2e853..9c08590680 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -1158,25 +1158,8 @@ mutable struct ZZMPolyRingElem <: MPolyRingElem{ZZRingElem} return z end - function ZZMPolyRingElem(ctx::ZZMPolyRing, a::ZZRingElem) - z = ZZMPolyRingElem(ctx) - @ccall libflint.fmpz_mpoly_set_fmpz(z::Ref{ZZMPolyRingElem}, a::Ref{ZZRingElem}, ctx::Ref{ZZMPolyRing})::Nothing - return z - end - - function ZZMPolyRingElem(ctx::ZZMPolyRing, a::Int) - z = ZZMPolyRingElem(ctx) - @ccall libflint.fmpz_mpoly_set_si(z::Ref{ZZMPolyRingElem}, a::Int, ctx::Ref{ZZMPolyRing})::Nothing - return z - end - - function ZZMPolyRingElem(ctx::ZZMPolyRing, a::UInt) - z = ZZMPolyRingElem(ctx) - @ccall libflint.fmpz_mpoly_set_ui(z::Ref{ZZMPolyRingElem}, a::UInt, ctx::Ref{ZZMPolyRing})::Nothing - return z - end - - ZZMPolyRingElem(ctx::ZZMPolyRing, a::Integer) = ZZMPolyRingElem(ctx, flintify(a)) + ZZMPolyRingElem(ctx::ZZMPolyRing, a::ZZRingElem) = set!(ZZMPolyRingElem(ctx), a) + ZZMPolyRingElem(ctx::ZZMPolyRing, a::Integer) = set!(ZZMPolyRingElem(ctx), a) end function _fmpz_mpoly_clear_fn(a::ZZMPolyRingElem) @@ -1316,29 +1299,11 @@ mutable struct QQMPolyRingElem <: MPolyRingElem{QQFieldElem} return z end - function QQMPolyRingElem(ctx::QQMPolyRing, a::ZZRingElem) - z = QQMPolyRingElem(ctx) - @ccall libflint.fmpq_mpoly_set_fmpz(z::Ref{QQMPolyRingElem}, a::Ref{ZZRingElem}, ctx::Ref{QQMPolyRing})::Nothing - return z - end + QQMPolyRingElem(ctx::QQMPolyRing, a::ZZRingElem) = set!(QQMPolyRingElem(ctx), a) + QQMPolyRingElem(ctx::QQMPolyRing, a::QQFieldElem) = set!(QQMPolyRingElem(ctx), a) + QQMPolyRingElem(ctx::QQMPolyRing, a::Integer) = set!(QQMPolyRingElem(ctx), a) + QQMPolyRingElem(ctx::QQMPolyRing, a::Rational) = set!(QQMPolyRingElem(ctx), a) - function QQMPolyRingElem(ctx::QQMPolyRing, a::QQFieldElem) - z = QQMPolyRingElem(ctx) - @ccall libflint.fmpq_mpoly_set_fmpq(z::Ref{QQMPolyRingElem}, a::Ref{QQFieldElem}, ctx::Ref{QQMPolyRing})::Nothing - return z - end - - function QQMPolyRingElem(ctx::QQMPolyRing, a::Int) - z = QQMPolyRingElem(ctx) - @ccall libflint.fmpq_mpoly_set_si(z::Ref{QQMPolyRingElem}, a::Int, ctx::Ref{QQMPolyRing})::Nothing - return z - end - - function QQMPolyRingElem(ctx::QQMPolyRing, a::UInt) - z = QQMPolyRingElem(ctx) - @ccall libflint.fmpq_mpoly_set_ui(z::Ref{QQMPolyRingElem}, a::UInt, ctx::Ref{QQMPolyRing})::Nothing - return z - end end function _fmpq_mpoly_clear_fn(a::QQMPolyRingElem) diff --git a/src/flint/fmpq_mpoly.jl b/src/flint/fmpq_mpoly.jl index cab8b11af7..d3bd7d51bc 100644 --- a/src/flint/fmpq_mpoly.jl +++ b/src/flint/fmpq_mpoly.jl @@ -65,8 +65,7 @@ end function deepcopy_internal(a::QQMPolyRingElem, dict::IdDict) z = parent(a)() - @ccall libflint.fmpq_mpoly_set(z::Ref{QQMPolyRingElem}, a::Ref{QQMPolyRingElem}, a.parent::Ref{QQMPolyRing})::Nothing - return z + return set!(z, a) end function length(a::QQMPolyRingElem) @@ -673,6 +672,37 @@ function neg!(a::QQMPolyRingElem, b::QQMPolyRingElem) return a end +# + +function set!(z::QQMPolyRingElem, a::QQMPolyRingElem) + @ccall libflint.fmpq_mpoly_set(z::Ref{QQMPolyRingElem}, a::Ref{QQMPolyRingElem}, parent(z)::Ref{QQMPolyRing})::Nothing + return z +end + +function set!(z::QQMPolyRingElem, a::QQFieldElemOrPtr) + @ccall libflint.fmpq_mpoly_set_fmpq(z::Ref{QQMPolyRingElem}, a::Ref{QQFieldElem}, parent(z)::Ref{QQMPolyRing})::Nothing + return z +end + +function set!(z::QQMPolyRingElem, a::ZZRingElemOrPtr) + @ccall libflint.fmpq_mpoly_set_fmpz(z::Ref{QQMPolyRingElem}, a::Ref{ZZRingElem}, parent(z)::Ref{QQMPolyRing})::Nothing + return z +end + +function set!(z::QQMPolyRingElem, a::Int) + @ccall libflint.fmpq_mpoly_set_si(z::Ref{QQMPolyRingElem}, a::Int, parent(z)::Ref{QQMPolyRing})::Nothing + return z +end + +function set!(z::QQMPolyRingElem, a::UInt) + @ccall libflint.fmpq_mpoly_set_ui(z::Ref{QQMPolyRingElem}, a::UInt, parent(z)::Ref{QQMPolyRing})::Nothing + return z +end + +set!(z::QQMPolyRingElem, a::Union{Integer, Rational}) = set!(z, flintify(a)) + +# + function add!(a::QQMPolyRingElem, b::QQMPolyRingElem, c::QQMPolyRingElem) @ccall libflint.fmpq_mpoly_add(a::Ref{QQMPolyRingElem}, b::Ref{QQMPolyRingElem}, c::Ref{QQMPolyRingElem}, a.parent::Ref{QQMPolyRing})::Nothing return a diff --git a/src/flint/fmpz_mpoly.jl b/src/flint/fmpz_mpoly.jl index 73bb15c4d1..042de53e84 100644 --- a/src/flint/fmpz_mpoly.jl +++ b/src/flint/fmpz_mpoly.jl @@ -64,8 +64,7 @@ end function deepcopy_internal(a::ZZMPolyRingElem, dict::IdDict) z = parent(a)() - @ccall libflint.fmpz_mpoly_set(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, a.parent::Ref{ZZMPolyRing})::Nothing - return z + return set!(z, a) end function length(a::ZZMPolyRingElem) @@ -636,6 +635,33 @@ function neg!(z::ZZMPolyRingElem, a::ZZMPolyRingElem) return z end +# + +function set!(z::ZZMPolyRingElem, a::ZZMPolyRingElem) + @ccall libflint.fmpz_mpoly_set(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, parent(z)::Ref{ZZMPolyRing})::Nothing + return z +end + +function set!(z::ZZMPolyRingElem, a::ZZRingElemOrPtr) + @ccall libflint.fmpz_mpoly_set_fmpz(z::Ref{ZZMPolyRingElem}, a::Ref{ZZRingElem}, parent(z)::Ref{ZZMPolyRing})::Nothing + return z +end + +function set!(z::ZZMPolyRingElem, a::Int) + @ccall libflint.fmpz_mpoly_set_si(z::Ref{ZZMPolyRingElem}, a::Int, parent(z)::Ref{ZZMPolyRing})::Nothing + return z +end + +function set!(z::ZZMPolyRingElem, a::UInt) + @ccall libflint.fmpz_mpoly_set_ui(z::Ref{ZZMPolyRingElem}, a::UInt, parent(z)::Ref{ZZMPolyRing})::Nothing + return z +end + +set!(z::ZZMPolyRingElem, a::Union{Integer, Rational}) = set!(z, flintify(a)) + +# + + function add!(z::ZZMPolyRingElem, a::ZZMPolyRingElem, b::ZZMPolyRingElem) @ccall libflint.fmpz_mpoly_add(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, b::Ref{ZZMPolyRingElem}, a.parent::Ref{ZZMPolyRing})::Nothing return z