Skip to content

Commit

Permalink
feat: improvements for inplace operations (#2037)
Browse files Browse the repository at this point in the history
* add inplace divides! for ZZRingElem/fmpz
* fix set! to return the correct value
  • Loading branch information
fieker authored Feb 23, 2025
1 parent d1c1e1b commit ffd6e31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
AbstractAlgebra = "0.44.2"
AbstractAlgebra = "0.44.8"
FLINT_jll = "^300.100.100"
Libdl = "1.6"
LinearAlgebra = "1.6"
Expand Down
8 changes: 6 additions & 2 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,16 @@ function divexact(x::ZZRingElem, y::ZZRingElem; check::Bool=true)
return z
end

function divides(x::ZZRingElem, y::ZZRingElem)
z = ZZRingElem()
function AbstractAlgebra.divides!(z::ZZRingElem, x::ZZRingElem, y::ZZRingElem)
res = @ccall libflint.fmpz_divides(z::Ref{ZZRingElem}, x::Ref{ZZRingElem}, y::Ref{ZZRingElem})::Bool
return res, z
end

function AbstractAlgebra.divides(x::ZZRingElem, y::ZZRingElem)
z = ZZRingElem()
return divides!(z, x, y)
end

divides(x::ZZRingElem, y::Integer) = divides(x, ZZRingElem(y))

@doc raw"""
Expand Down
9 changes: 9 additions & 0 deletions src/flint/fq_default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,48 +601,57 @@ end
function set!(z::FqFieldElem, a::FqFieldElemOrPtr)
@ccall libflint.fq_default_set(z::Ref{FqFieldElem}, a::Ref{FqFieldElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::Int)
@ccall libflint.fq_default_set_si(z::Ref{FqFieldElem}, a::Int, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::UInt)
@ccall libflint.fq_default_set_ui(z::Ref{FqFieldElem}, a::UInt, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::ZZRingElemOrPtr)
@ccall libflint.fq_default_set_fmpz(z::Ref{FqFieldElem}, a::Ref{ZZRingElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

set!(z::FqFieldElem, a::Integer) = set!(z, flintify(a))

function set!(z::FqFieldElem, a::ZZPolyRingElemOrPtr)
@ccall libflint.fq_default_set_fmpz_poly(z::Ref{FqFieldElem}, a::Ref{ZZPolyRingElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::zzModPolyRingElemOrPtr)
@ccall libflint.fq_default_set_nmod_poly(z::Ref{FqFieldElem}, a::Ref{zzModPolyRingElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::fpPolyRingElemOrPtr)
@ccall libflint.fq_default_set_nmod_poly(z::Ref{FqFieldElem}, a::Ref{fpPolyRingElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::ZZModPolyRingElemOrPtr)
@ccall libflint.fq_default_set_fmpz_mod_poly(z::Ref{FqFieldElem}, a::Ref{ZZModPolyRingElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function set!(z::FqFieldElem, a::FpPolyRingElemOrPtr)
@ccall libflint.fq_default_set_fmpz_mod_poly(z::Ref{FqFieldElem}, a::Ref{FpPolyRingElem}, parent(z)::Ref{FqField})::Nothing
z.poly = nothing
return z
end

#
Expand Down

0 comments on commit ffd6e31

Please sign in to comment.