Skip to content
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

Unsafe ops for fq_default #1906

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from 1 commit
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
100 changes: 50 additions & 50 deletions src/flint/fq_default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,29 +403,23 @@
function +(x::FqFieldElem, y::FqFieldElem)
if parent(x) === parent(y)
z = parent(y)()
ccall((:fq_default_add, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, x, y, y.parent)
return z
return add!(z, x, y)
end
return +(_promote(x, y)...)
end

function -(x::FqFieldElem, y::FqFieldElem)
if parent(x) === parent(y)
z = parent(y)()
ccall((:fq_default_sub, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, x, y, y.parent)
return z
return sub!(z, x, y)
end
return -(_promote(x, y)...)
end

function *(x::FqFieldElem, y::FqFieldElem)
if parent(x) === parent(y)
z = parent(y)()
ccall((:fq_default_mul, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, x, y, y.parent)
return z
return mul!(z, x, y)
end
return *(_promote(x, y)...)
end
Expand All @@ -436,43 +430,19 @@
#
###############################################################################

function *(x::Int, y::FqFieldElem)
z = parent(y)()
ccall((:fq_default_mul_si, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Int, Ref{FqField}), z, y, x, y.parent)
return z
end

*(x::Integer, y::FqFieldElem) = ZZRingElem(x)*y

*(x::FqFieldElem, y::Integer) = y*x

function *(x::ZZRingElem, y::FqFieldElem)
z = parent(y)()
ccall((:fq_default_mul_fmpz, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{ZZRingElem}, Ref{FqField}),
z, y, x, y.parent)
return z
for jT in (Integer, ZZRingElem)
@eval begin
*(x::FqFieldElem, y::$jT) = mul!(parent(x)(), x, y)
*(x::$jT, y::FqFieldElem) = mul!(parent(y)(), x, y)

+(x::FqFieldElem, y::$jT) = x + parent(x)(y)
+(x::$jT, y::FqFieldElem) = y + x

Check warning on line 439 in src/flint/fq_default.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fq_default.jl#L439

Added line #L439 was not covered by tests

-(x::FqFieldElem, y::$jT) = x - parent(x)(y)
-(x::$jT, y::FqFieldElem) = parent(y)(x) - y

Check warning on line 442 in src/flint/fq_default.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fq_default.jl#L441-L442

Added lines #L441 - L442 were not covered by tests
Comment on lines +438 to +442
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't these delegate to add! or sub! as well?
Edit: I just noticed that there are no corresponding flint functions for these, but we have fallbacks in place in AA.
Edit: but this would be an endless loop...

maybe just add a comment here that these wait for a change in FLINT?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could implement add! and sub! already now without an endless loop by inserting the coercions there. But there are already tons of changes and I have to draw the line somewhere. So here I just took the code that was there, the only change is that it is now in an for ... @begin eval construct.

Someone can make these additional changes in a future iteration. There are a gazillion other things one could do in this file alone (e.g. adding set! methods to simplify the constructors). For now I'd like to move on

end
end

*(x::FqFieldElem, y::ZZRingElem) = y*x

+(x::FqFieldElem, y::Integer) = x + parent(x)(y)

+(x::Integer, y::FqFieldElem) = y + x

+(x::FqFieldElem, y::ZZRingElem) = x + parent(x)(y)

+(x::ZZRingElem, y::FqFieldElem) = y + x

-(x::FqFieldElem, y::Integer) = x - parent(x)(y)

-(x::Integer, y::FqFieldElem) = parent(y)(x) - y

-(x::FqFieldElem, y::ZZRingElem) = x - parent(x)(y)

-(x::ZZRingElem, y::FqFieldElem) = parent(y)(x) - y

###############################################################################
#
# Powering
Expand Down Expand Up @@ -675,20 +645,50 @@
return z
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
end

function mul!(z::FqFieldElem, x::FqFieldElem, y::FqFieldElem)
ccall((:fq_default_mul, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, x, y, y.parent)
#

function add!(z::FqFieldElem, x::FqFieldElem, y::FqFieldElem)
@ccall libflint.fq_default_add(z::Ref{FqFieldElem}, x::Ref{FqFieldElem}, y::Ref{FqFieldElem}, x.parent::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function add!(z::FqFieldElem, x::FqFieldElem, y::FqFieldElem)
ccall((:fq_default_add, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, x, y, x.parent)
#

function sub!(z::FqFieldElem, x::FqFieldElem, y::FqFieldElem)
@ccall libflint.fq_default_sub(z::Ref{FqFieldElem}, x::Ref{FqFieldElem}, y::Ref{FqFieldElem}, x.parent::Ref{FqField})::Nothing
z.poly = nothing
return z
end

#

function mul!(z::FqFieldElem, x::FqFieldElem, y::FqFieldElem)
@ccall libflint.fq_default_mul(z::Ref{FqFieldElem}, x::Ref{FqFieldElem}, y::Ref{FqFieldElem}, y.parent::Ref{FqField})::Nothing
z.poly = nothing
return z
end

function mul!(z::FqFieldElem, x::FqFieldElem, y::ZZRingElemOrPtr)
@ccall libflint.fq_default_mul_fmpz(z::Ref{FqFieldElem}, x::Ref{FqFieldElem}, y::Ref{ZZRingElem}, x.parent::Ref{FqField})::Nothing
return z
end

function mul!(z::FqFieldElem, x::FqFieldElem, y::Int)
@ccall libflint.fq_default_mul_si(z::Ref{FqFieldElem}, x::Ref{FqFieldElem}, y::Int, x.parent::Ref{FqField})::Nothing
return z
end

function mul!(z::FqFieldElem, x::FqFieldElem, y::UInt)
@ccall libflint.fq_default_mul_ui(z::Ref{FqFieldElem}, x::Ref{FqFieldElem}, y::Int, x.parent::Ref{FqField})::Nothing
return z

Check warning on line 684 in src/flint/fq_default.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fq_default.jl#L682-L684

Added lines #L682 - L684 were not covered by tests
end
fingolfin marked this conversation as resolved.
Show resolved Hide resolved

mul!(z::FqFieldElem, x::FqFieldElem, y::Integer) = mul!(z, x, flintify(y))

mul!(z::FqFieldElem, x::ZZRingElemOrPtr, y::FqFieldElem) = mul!(z, y, x)
mul!(z::FqFieldElem, x::Integer, y::FqFieldElem) = mul!(z, y, x)

###############################################################################
#
# Random functions
Expand Down
Loading