Skip to content

Commit

Permalink
Unsafe ops for fq_default (#1906)
Browse files Browse the repository at this point in the history
Co-authored-by: Lars Göttgens <[email protected]>
  • Loading branch information
fingolfin and lgoettgens authored Oct 18, 2024
1 parent 6848ca3 commit 7535e21
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions src/flint/fq_default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,29 +403,23 @@ end
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 @@ end
#
###############################################################################

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

-(x::FqFieldElem, y::$jT) = x - parent(x)(y)
-(x::$jT, y::FqFieldElem) = parent(y)(x) - y
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 @@ -672,23 +642,57 @@ end
function neg!(z::FqFieldElem, a::FqFieldElem)
ccall((:fq_default_neg, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, a, a.parent)
z.poly = nothing
return z
end

#

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 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((:fq_default_mul, libflint), Nothing,
(Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqFieldElem}, Ref{FqField}), z, x, y, y.parent)
@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 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 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
z.poly = 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
z.poly = 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
z.poly = nothing
return z
end

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

0 comments on commit 7535e21

Please sign in to comment.