Skip to content

Add set! methods for QQ/ZZMPolyRingElem #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 6 additions & 41 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1158,25 +1158,8 @@
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)
Expand Down Expand Up @@ -1316,29 +1299,11 @@
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)

Check warning on line 1305 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L1305

Added line #L1305 was not covered by tests

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)
Expand Down
34 changes: 32 additions & 2 deletions src/flint/fmpq_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions src/flint/fmpz_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -636,6 +635,33 @@ function neg!(z::ZZMPolyRingElem, a::ZZMPolyRingElem)
return z
end

#

function set!(z::ZZMPolyRingElem, a::ZZMPolyRingElem)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should also do this to make it more generally useful (based on a concrete need I just had ;-) )

Suggested change
function set!(z::ZZMPolyRingElem, a::ZZMPolyRingElem)
function set!(z::ZZMPolyRingElemOrPtr, a::ZZMPolyRingElemOrPtr; parent::ZZMPolyRing=parent(a))
@ccall libflint.fmpz_mpoly_set(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, parent::Ref{ZZMPolyRing})::Nothing

Or maybe the kwarg should be ctx to better fit with that @lgoettgens does in PR #1911 (which I kinda forgot about, I thought this was long merged... perhaps we can get together on gather later or next week to discuss this)

@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
Expand Down
Loading