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

Add and use zero!, one!, neg! methods #1869

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,6 @@ function numerator(a::AbsSimpleNumFieldElem)
return z
end

function one!(r::AbsSimpleNumFieldElem)
a = parent(r)
ccall((:nf_elem_one, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}), r, a)
return r
end

function divexact!(z::AbsSimpleNumFieldElem, x::AbsSimpleNumFieldElem, y::ZZRingElem)
ccall((:nf_elem_scalar_div_fmpz, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{ZZRingElem}, Ref{AbsSimpleNumField}),
Expand Down
34 changes: 15 additions & 19 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,9 @@ function gen(a::AbsSimpleNumField)
return r
end

function one(a::AbsSimpleNumField)
r = AbsSimpleNumFieldElem(a)
ccall((:nf_elem_one, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}), r, a)
return r
end
one(a::AbsSimpleNumField) = one!(AbsSimpleNumFieldElem(a))

function zero(a::AbsSimpleNumField)
r = AbsSimpleNumFieldElem(a)
ccall((:nf_elem_zero, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}), r, a)
return r
end
zero(a::AbsSimpleNumField) = zero!(AbsSimpleNumFieldElem(a))

@doc raw"""
is_gen(a::AbsSimpleNumFieldElem)
Expand Down Expand Up @@ -274,13 +264,7 @@ canonical_unit(x::AbsSimpleNumFieldElem) = x
#
###############################################################################

function -(a::AbsSimpleNumFieldElem)
r = a.parent()
ccall((:nf_elem_neg, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}),
r, a, a.parent)
return r
end
-(a::AbsSimpleNumFieldElem) = neg!(a.parent(), a)

###############################################################################
#
Expand Down Expand Up @@ -743,6 +727,18 @@ function zero!(a::AbsSimpleNumFieldElem)
return a
end

function one!(a::AbsSimpleNumFieldElem)
ccall((:nf_elem_one, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}), a, parent(a))
return a
end

function neg!(z::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem)
ccall((:nf_elem_neg, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}), z, a, parent(a))
return z
end

function mul!(z::AbsSimpleNumFieldElem, x::AbsSimpleNumFieldElem, y::AbsSimpleNumFieldElem)
ccall((:nf_elem_mul, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}),
Expand Down
5 changes: 5 additions & 0 deletions src/arb/Complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,11 @@
return z
end

function one!(z::ComplexFieldElem)
ccall((:acb_one, libflint), Nothing, (Ref{ComplexFieldElem},), z)
return z

Check warning on line 1591 in src/arb/Complex.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/Complex.jl#L1589-L1591

Added lines #L1589 - L1591 were not covered by tests
end

function add!(z::ComplexFieldElem, x::ComplexFieldElem, y::ComplexFieldElem, prec::Int = precision(Balls))
ccall((:acb_add, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}, Ref{ComplexFieldElem}, Int),
z, x, y, prec)
Expand Down
5 changes: 5 additions & 0 deletions src/arb/ComplexPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@
return z
end

function one!(z::ComplexPolyRingElem)
ccall((:acb_poly_one, libflint), Nothing, (Ref{ComplexPolyRingElem},), z)
return z

Check warning on line 712 in src/arb/ComplexPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/ComplexPoly.jl#L710-L712

Added lines #L710 - L712 were not covered by tests
end

function fit!(z::ComplexPolyRingElem, n::Int)
ccall((:acb_poly_fit_length, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int), z, n)
Expand Down
5 changes: 5 additions & 0 deletions src/arb/Real.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,11 @@
return z
end

function one!(z::RealFieldElem)
ccall((:arb_one, libflint), Nothing, (Ref{RealFieldElem},), z)
return z

Check warning on line 1939 in src/arb/Real.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/Real.jl#L1937-L1939

Added lines #L1937 - L1939 were not covered by tests
end

for (s,f) in (("add!","arb_add"), ("mul!","arb_mul"), ("div!", "arb_div"),
("sub!","arb_sub"))
@eval begin
Expand Down
6 changes: 6 additions & 0 deletions src/arb/RealPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@
return z
end

function one!(z::RealPolyRingElem)
ccall((:arb_poly_one, libflint), Nothing,

Check warning on line 611 in src/arb/RealPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/RealPoly.jl#L610-L611

Added lines #L610 - L611 were not covered by tests
(Ref{RealPolyRingElem}, ), z)
return z

Check warning on line 613 in src/arb/RealPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/RealPoly.jl#L613

Added line #L613 was not covered by tests
end

function fit!(z::RealPolyRingElem, n::Int)
ccall((:arb_poly_fit_length, libflint), Nothing,
(Ref{RealPolyRingElem}, Int), z, n)
Expand Down
5 changes: 5 additions & 0 deletions src/arb/acb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,11 @@
return z
end

function one!(z::AcbFieldElem)
ccall((:acb_one, libflint), Nothing, (Ref{AcbFieldElem},), z)
return z

Check warning on line 1579 in src/arb/acb.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/acb.jl#L1577-L1579

Added lines #L1577 - L1579 were not covered by tests
end

function add!(z::AcbFieldElem, x::AcbFieldElem, y::AcbFieldElem)
ccall((:acb_add, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}, Ref{AcbFieldElem}, Int),
z, x, y, parent(z).prec)
Expand Down
5 changes: 5 additions & 0 deletions src/arb/acb_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,11 @@
return z
end

function one!(z::AcbPolyRingElem)
ccall((:acb_poly_one, libflint), Nothing, (Ref{AcbPolyRingElem},), z)
return z

Check warning on line 707 in src/arb/acb_poly.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/acb_poly.jl#L705-L707

Added lines #L705 - L707 were not covered by tests
end

function fit!(z::AcbPolyRingElem, n::Int)
ccall((:acb_poly_fit_length, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int), z, n)
Expand Down
5 changes: 5 additions & 0 deletions src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,11 @@
return z
end

function one!(z::ArbFieldElem)
ccall((:arb_one, libflint), Nothing, (Ref{ArbFieldElem},), z)
return z

Check warning on line 1941 in src/arb/arb.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/arb.jl#L1939-L1941

Added lines #L1939 - L1941 were not covered by tests
end

for (s,f) in (("add!","arb_add"), ("mul!","arb_mul"), ("div!", "arb_div"),
("sub!","arb_sub"))
@eval begin
Expand Down
6 changes: 6 additions & 0 deletions src/arb/arb_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@
return z
end

function one!(z::ArbPolyRingElem)
ccall((:arb_poly_one, libflint), Nothing,

Check warning on line 611 in src/arb/arb_poly.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/arb_poly.jl#L610-L611

Added lines #L610 - L611 were not covered by tests
(Ref{ArbPolyRingElem}, ), z)
return z

Check warning on line 613 in src/arb/arb_poly.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/arb_poly.jl#L613

Added line #L613 was not covered by tests
end

function fit!(z::ArbPolyRingElem, n::Int)
ccall((:arb_poly_fit_length, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int), z, n)
Expand Down
23 changes: 14 additions & 9 deletions src/calcium/ca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ end

zero(C::CalciumField) = C()

function one(C::CalciumField)
z = CalciumFieldElem(C)
ccall((:ca_one, libflint), Nothing, (Ref{CalciumFieldElem}, Ref{CalciumField}), z, C)
return z
end
one(C::CalciumField) = one!(CalciumFieldElem(C))

###############################################################################
#
Expand Down Expand Up @@ -350,10 +346,7 @@ end
###############################################################################

function -(a::CalciumFieldElem)
C = a.parent
r = C()
ccall((:ca_neg, libflint), Nothing,
(Ref{CalciumFieldElem}, Ref{CalciumFieldElem}, Ref{CalciumField}), r, a, C)
r = neg!(a.parent(), a)
check_special(r)
return r
end
Expand Down Expand Up @@ -1391,6 +1384,18 @@ function zero!(z::CalciumFieldElem)
return z
end

function one!(z::CalciumFieldElem)
C = z.parent
ccall((:ca_one, libflint), Nothing, (Ref{CalciumFieldElem}, Ref{CalciumField}), z, C)
return z
end

function neg!(z::CalciumFieldElem, a::CalciumFieldElem)
C = z.parent
ccall((:ca_neg, libflint), Nothing, (Ref{CalciumFieldElem}, Ref{CalciumFieldElem}, Ref{CalciumField}), z, a, C)
return z
end

function mul!(z::CalciumFieldElem, x::CalciumFieldElem, y::CalciumFieldElem)
if z.parent != x.parent || x.parent != y.parent
error("different parents in in-place operation")
Expand Down
16 changes: 11 additions & 5 deletions src/calcium/qqbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,7 @@
#
###############################################################################

function -(a::QQBarFieldElem)
z = QQBarFieldElem()
ccall((:qqbar_neg, libflint), Nothing, (Ref{QQBarFieldElem}, Ref{QQBarFieldElem}), z, a)
return z
end
-(a::QQBarFieldElem) = neg!(QQBarFieldElem(), a)

###############################################################################
#
Expand Down Expand Up @@ -1499,6 +1495,16 @@
return z
end

function one!(z::QQBarFieldElem)
ccall((:qqbar_one, libflint), Nothing, (Ref{QQBarFieldElem},), z)
return z

Check warning on line 1500 in src/calcium/qqbar.jl

View check run for this annotation

Codecov / codecov/patch

src/calcium/qqbar.jl#L1498-L1500

Added lines #L1498 - L1500 were not covered by tests
end

function neg!(z::QQBarFieldElem, a::QQBarFieldElem)
ccall((:qqbar_neg, libflint), Nothing, (Ref{QQBarFieldElem}, Ref{QQBarFieldElem}), z, a)
return z
end

function mul!(z::QQBarFieldElem, x::QQBarFieldElem, y::QQBarFieldElem)
ccall((:qqbar_mul, libflint), Nothing,
(Ref{QQBarFieldElem}, Ref{QQBarFieldElem}, Ref{QQBarFieldElem}), z, x, y)
Expand Down
10 changes: 5 additions & 5 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,11 @@ function one!(c::QQFieldElemOrPtr)
set!(c, 1)
end

function neg!(z::QQFieldElemOrPtr, a::QQFieldElemOrPtr)
ccall((:fmpq_neg, libflint), Nothing, (Ref{QQFieldElem}, Ref{QQFieldElem}), z, a)
return z
end

function set!(c::QQFieldElemOrPtr, a::QQFieldElemOrPtr)
@ccall libflint.fmpq_set(c::Ref{QQFieldElem}, a::Ref{QQFieldElem})::Nothing
return c
Expand Down Expand Up @@ -1170,11 +1175,6 @@ function sub!(z::QQFieldElemOrPtr, a::QQFieldElemOrPtr, b::UInt)
return z
end

function neg!(z::QQFieldElemOrPtr, a::QQFieldElemOrPtr)
ccall((:fmpq_neg, libflint), Nothing, (Ref{QQFieldElem}, Ref{QQFieldElem}), z, a)
return z
end

function divexact!(z::QQFieldElemOrPtr, a::QQFieldElemOrPtr, b::QQFieldElemOrPtr)
ccall((:fmpq_div, libflint), Nothing, (Ref{QQFieldElem}, Ref{QQFieldElem}, Ref{QQFieldElem}), z, a, b)
return z
Expand Down
7 changes: 7 additions & 0 deletions src/flint/fmpq_abs_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,13 @@
return z
end

function one!(z::QQAbsPowerSeriesRingElem)
ccall((:fmpq_poly_one, libflint), Nothing,

Check warning on line 725 in src/flint/fmpq_abs_series.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_abs_series.jl#L724-L725

Added lines #L724 - L725 were not covered by tests
(Ref{QQAbsPowerSeriesRingElem},), z)
z.prec = parent(z).prec_max
return z

Check warning on line 728 in src/flint/fmpq_abs_series.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_abs_series.jl#L727-L728

Added lines #L727 - L728 were not covered by tests
end

function fit!(z::QQAbsPowerSeriesRingElem, n::Int)
ccall((:fmpq_poly_fit_length, libflint), Nothing,
(Ref{QQAbsPowerSeriesRingElem}, Int), z, n)
Expand Down
31 changes: 19 additions & 12 deletions src/flint/fmpq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,7 @@
#
###############################################################################

function -(x::QQMatrix)
z = similar(x)
ccall((:fmpq_mat_neg, libflint), Nothing,
(Ref{QQMatrix}, Ref{QQMatrix}), z, x)
return z
end
-(x::QQMatrix) = neg!(similar(x), x)

###############################################################################
#
Expand Down Expand Up @@ -752,6 +747,24 @@
#
###############################################################################

function zero!(z::QQMatrix)
ccall((:fmpq_mat_zero, libflint), Nothing,

Check warning on line 751 in src/flint/fmpq_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_mat.jl#L750-L751

Added lines #L750 - L751 were not covered by tests
(Ref{QQMatrix},), z)
return z

Check warning on line 753 in src/flint/fmpq_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_mat.jl#L753

Added line #L753 was not covered by tests
end

function one!(z::QQMatrix)
ccall((:fmpq_mat_one, libflint), Nothing,

Check warning on line 757 in src/flint/fmpq_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_mat.jl#L756-L757

Added lines #L756 - L757 were not covered by tests
(Ref{QQMatrix},), z)
return z

Check warning on line 759 in src/flint/fmpq_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_mat.jl#L759

Added line #L759 was not covered by tests
end

function neg!(z::QQMatrix, a::QQMatrix)
ccall((:fmpq_mat_neg, libflint), Nothing,
(Ref{QQMatrix}, Ref{QQMatrix}), z, a)
return z
end

function mul!(z::QQMatrix, x::QQMatrix, y::QQMatrix)
ccall((:fmpq_mat_mul, libflint), Nothing,
(Ref{QQMatrix}, Ref{QQMatrix}, Ref{QQMatrix}), z, x, y)
Expand Down Expand Up @@ -815,12 +828,6 @@

mul!(z::QQMatrix, y::QQMatrix, x::Integer) = mul!(z, y, ZZ(x))

function zero!(z::QQMatrix)
ccall((:fmpq_mat_zero, libflint), Nothing,
(Ref{QQMatrix},), z)
return z
end

function Generic.add_one!(a::QQMatrix, i::Int, j::Int)
@boundscheck _checkbounds(a, i, j)
GC.@preserve a begin
Expand Down
2 changes: 0 additions & 2 deletions src/flint/fmpq_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,6 @@ function neg!(a::QQMPolyRingElem, b::QQMPolyRingElem)
return a
end

neg!(a::QQMPolyRingElem) = neg!(a, a)

function add!(a::QQMPolyRingElem, b::QQMPolyRingElem, c::QQMPolyRingElem)
ccall((:fmpq_mpoly_add, libflint), Nothing,
(Ref{QQMPolyRingElem}, Ref{QQMPolyRingElem},
Expand Down
19 changes: 13 additions & 6 deletions src/flint/fmpq_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@
#
###############################################################################

function -(x::QQPolyRingElem)
z = parent(x)()
ccall((:fmpq_poly_neg, libflint), Nothing,
(Ref{QQPolyRingElem}, Ref{QQPolyRingElem}), z, x)
return z
end
-(x::QQPolyRingElem) = neg!(parent(x)(), x)

###############################################################################
#
Expand Down Expand Up @@ -783,6 +778,18 @@
return z
end

function one!(z::QQPolyRingElem)
ccall((:fmpq_poly_one, libflint), Nothing,

Check warning on line 782 in src/flint/fmpq_poly.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L781-L782

Added lines #L781 - L782 were not covered by tests
(Ref{QQPolyRingElem},), z)
return z

Check warning on line 784 in src/flint/fmpq_poly.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L784

Added line #L784 was not covered by tests
end

function neg!(z::QQPolyRingElem, a::QQPolyRingElem)
ccall((:fmpq_poly_neg, libflint), Nothing,
(Ref{QQPolyRingElem}, Ref{QQPolyRingElem}), z, a)
return z
end

function fit!(z::QQPolyRingElem, n::Int)
ccall((:fmpq_poly_fit_length, libflint), Nothing,
(Ref{QQPolyRingElem}, Int), z, n)
Expand Down
8 changes: 8 additions & 0 deletions src/flint/fmpq_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,14 @@
return z
end

function one!(z::QQRelPowerSeriesRingElem)
ccall((:fmpq_poly_one, libflint), Nothing,

Check warning on line 904 in src/flint/fmpq_rel_series.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_rel_series.jl#L903-L904

Added lines #L903 - L904 were not covered by tests
(Ref{QQRelPowerSeriesRingElem},), z)
z.prec = parent(z).prec_max
z.val = parent(z).prec_max
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
return z

Check warning on line 908 in src/flint/fmpq_rel_series.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_rel_series.jl#L906-L908

Added lines #L906 - L908 were not covered by tests
end

function fit!(z::QQRelPowerSeriesRingElem, n::Int)
ccall((:fmpq_poly_fit_length, libflint), Nothing,
(Ref{QQRelPowerSeriesRingElem}, Int), z, n)
Expand Down
Loading
Loading