Skip to content

Commit

Permalink
Unsafe ops for QQ/ZZPolyRingElem, QQ/ZZMatrix
Browse files Browse the repository at this point in the history
Move flintify calls down into unsafe ops
  • Loading branch information
fingolfin committed Oct 17, 2024
1 parent 50132ae commit d7405fb
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 510 deletions.
72 changes: 16 additions & 56 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,37 +253,20 @@ mutable struct ZZPolyRingElem <: PolyRingElem{ZZRingElem}
return z
end

function ZZPolyRingElem(a::Vector{ZZRingElem})
function ZZPolyRingElem(a::Vector{<:Union{Integer,ZZRingElem}})
z = new()
ccall((:fmpz_poly_init2, libflint), Nothing,
(Ref{ZZPolyRingElem}, Int), z, length(a))
for i = 1:length(a)
ccall((:fmpz_poly_set_coeff_fmpz, libflint), Nothing,
(Ref{ZZPolyRingElem}, Int, Ref{ZZRingElem}), z, i - 1, a[i])
setcoeff!(z, i - 1, a[i])
end
finalizer(_fmpz_poly_clear_fn, z)
return z
end

function ZZPolyRingElem(a::Int)
z = ZZPolyRingElem()
ccall((:fmpz_poly_set_si, libflint), Nothing, (Ref{ZZPolyRingElem}, Int), z, a)
return z
end

function ZZPolyRingElem(a::ZZRingElem)
z = ZZPolyRingElem()
ccall((:fmpz_poly_set_fmpz, libflint), Nothing,
(Ref{ZZPolyRingElem}, Ref{ZZRingElem}), z, a)
return z
end

function ZZPolyRingElem(a::ZZPolyRingElem)
z = ZZPolyRingElem()
ccall((:fmpz_poly_set, libflint), Nothing,
(Ref{ZZPolyRingElem}, Ref{ZZPolyRingElem}), z, a)
return z
end
ZZPolyRingElem(a::Integer) = set!(ZZPolyRingElem(), a)
ZZPolyRingElem(a::ZZRingElem) = set!(ZZPolyRingElem(), a)
ZZPolyRingElem(a::ZZPolyRingElem) = set!(ZZPolyRingElem(), a)
end

function _fmpz_poly_clear_fn(a::ZZPolyRingElem)
Expand Down Expand Up @@ -346,51 +329,25 @@ mutable struct QQPolyRingElem <: PolyRingElem{QQFieldElem}
return z
end

function QQPolyRingElem(a::Vector{QQFieldElem})
function QQPolyRingElem(a::Vector{<:Union{Integer,Rational,ZZRingElem,QQFieldElem}})
z = new()
ccall((:fmpq_poly_init2, libflint), Nothing,
(Ref{QQPolyRingElem}, Int), z, length(a))
for i = 1:length(a)
ccall((:fmpq_poly_set_coeff_fmpq, libflint), Nothing,
(Ref{QQPolyRingElem}, Int, Ref{QQFieldElem}), z, i - 1, a[i])
setcoeff!(z, i - 1, a[i])
end
finalizer(_fmpq_poly_clear_fn, z)
return z
end

function QQPolyRingElem(a::Int)
z = QQPolyRingElem()
ccall((:fmpq_poly_set_si, libflint), Nothing, (Ref{QQPolyRingElem}, Int), z, a)
return z
end
QQPolyRingElem(a::Integer) = set!(QQPolyRingElem(), a)
QQPolyRingElem(a::Rational) = set!(QQPolyRingElem(), a)

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

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L344

Added line #L344 was not covered by tests

function QQPolyRingElem(a::ZZRingElem)
z = QQPolyRingElem()
ccall((:fmpq_poly_set_fmpz, libflint), Nothing,
(Ref{QQPolyRingElem}, Ref{ZZRingElem}), z, a)
return z
end

function QQPolyRingElem(a::QQFieldElem)
z = QQPolyRingElem()
ccall((:fmpq_poly_set_fmpq, libflint), Nothing,
(Ref{QQPolyRingElem}, Ref{QQFieldElem}), z, a)
return z
end

function QQPolyRingElem(a::ZZPolyRingElem)
z = QQPolyRingElem()
ccall((:fmpq_poly_set_fmpz_poly, libflint), Nothing,
(Ref{QQPolyRingElem}, Ref{ZZPolyRingElem}), z, a)
return z
end
QQPolyRingElem(a::ZZRingElem) = set!(QQPolyRingElem(), a)
QQPolyRingElem(a::QQFieldElem) = set!(QQPolyRingElem(), a)

function QQPolyRingElem(a::QQPolyRingElem)
z = QQPolyRingElem()
ccall((:fmpq_poly_set, libflint), Nothing,
(Ref{QQPolyRingElem}, Ref{QQPolyRingElem}), z, a)
return z
end
QQPolyRingElem(a::ZZPolyRingElem) = set!(QQPolyRingElem(), a)
QQPolyRingElem(a::QQPolyRingElem) = set!(QQPolyRingElem(), a)
end

function _fmpq_poly_clear_fn(a::QQPolyRingElem)
Expand Down Expand Up @@ -6302,6 +6259,9 @@ const FlintPuiseuxSeriesFieldElemOrPtr{T <: RingElem} = Union{FlintPuiseuxSeries
const PadicFieldElemOrPtr = Union{PadicFieldElem, Ref{PadicFieldElem}, Ptr{PadicFieldElem}}
const QadicFieldElemOrPtr = Union{QadicFieldElem, Ref{QadicFieldElem}, Ptr{QadicFieldElem}}

const IntegerUnionOrPtr = Union{Integer, ZZRingElemOrPtr}
const RationalUnionOrPtr = Union{Integer, ZZRingElemOrPtr, Rational, QQFieldElemOrPtr}

###############################################################################
#
# Docstrings for the systematically added types in this file
Expand Down
Loading

0 comments on commit d7405fb

Please sign in to comment.