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 QQ/ZZPolyRingElem, QQ/ZZMatrix #1907

Merged
merged 1 commit into from
Oct 18, 2024
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
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 @@
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 @@
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 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
Loading