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

Yet more flinitfy (and related tweaks) #1876

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,6 @@ function Base.rem(a::ZZModRingElem, b::ZZModRingElem)
return r
end

jacobi_symbol(x::Integer, y::ZZRingElem) = jacobi_symbol(ZZRingElem(x), y)

@doc raw"""
zeros(f::ZZPolyRingElem) -> Vector{ZZRingElem}

Expand Down
24 changes: 12 additions & 12 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@
return r
end

+(a::AbsSimpleNumFieldElem, b::Integer) = a + ZZRingElem(b)
+(a::AbsSimpleNumFieldElem, b::Integer) = a + flintify(b)

Check warning on line 399 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L399

Added line #L399 was not covered by tests
Copy link
Member Author

Choose a reason for hiding this comment

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

test coverage for adhoc operations is really bad. Would be good to have more of those in the interface tests (possibly optionally, as I am not sure we mandate this in the ring interface?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

the ring interface states that it is optional to add explicit ad-hoc functions, but AA should take care of the fallback using promotion (see https://nemocas.github.io/AbstractAlgebra.jl/dev/ring_interface/#Optional-binary-ad-hoc-operators)


-(a::AbsSimpleNumFieldElem, b::Integer) = a - ZZRingElem(b)
-(a::AbsSimpleNumFieldElem, b::Integer) = a - flintify(b)

Check warning on line 401 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L401

Added line #L401 was not covered by tests

-(a::Integer, b::AbsSimpleNumFieldElem) = ZZRingElem(a) - b
-(a::Integer, b::AbsSimpleNumFieldElem) = flintify(a) - b

Check warning on line 403 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L403

Added line #L403 was not covered by tests

+(a::Integer, b::AbsSimpleNumFieldElem) = b + a

Expand Down Expand Up @@ -444,7 +444,7 @@

*(a::AbsSimpleNumFieldElem, b::Rational) = b * a

*(a::AbsSimpleNumFieldElem, b::Integer) = a * ZZRingElem(b)
*(a::AbsSimpleNumFieldElem, b::Integer) = a * flintify(b)

Check warning on line 447 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L447

Added line #L447 was not covered by tests

*(a::Integer, b::AbsSimpleNumFieldElem) = b * a

Expand All @@ -456,7 +456,7 @@

//(a::AbsSimpleNumFieldElem, b::ZZRingElem) = divexact(a, b)

//(a::AbsSimpleNumFieldElem, b::Integer) = a//ZZRingElem(b)
//(a::AbsSimpleNumFieldElem, b::Integer) = a//flintify(b)

Check warning on line 459 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L459

Added line #L459 was not covered by tests

//(a::AbsSimpleNumFieldElem, b::QQFieldElem) = divexact(a, b)

Expand Down Expand Up @@ -534,7 +534,7 @@
return Bool(b)
end

==(a::AbsSimpleNumFieldElem, b::Integer) = a == ZZRingElem(b)
==(a::AbsSimpleNumFieldElem, b::Integer) = a == flintify(b)

==(a::AbsSimpleNumFieldElem, b::Rational) = a == QQFieldElem(b)

Expand Down Expand Up @@ -611,7 +611,7 @@
return r
end

divexact(a::AbsSimpleNumFieldElem, b::Integer; check::Bool=true) = divexact(a, ZZRingElem(b); check=check)
divexact(a::AbsSimpleNumFieldElem, b::Integer; check::Bool=true) = divexact(a, flintify(b); check=check)

Check warning on line 614 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L614

Added line #L614 was not covered by tests

function divexact(a::AbsSimpleNumFieldElem, b::QQFieldElem; check::Bool=true)
iszero(b) && throw(DivideError())
Expand Down Expand Up @@ -814,7 +814,7 @@
return c
end

add!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = add!(c, a, ZZRingElem(b))
add!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = add!(c, a, flintify(b))

Check warning on line 817 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L817

Added line #L817 was not covered by tests

function sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::QQFieldElem)
ccall((:nf_elem_sub_fmpq, libflint), Nothing,
Expand All @@ -837,7 +837,7 @@
return c
end

sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = sub!(c, a, ZZRingElem(b))
sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = sub!(c, a, flintify(b))

Check warning on line 840 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L840

Added line #L840 was not covered by tests

function sub!(c::AbsSimpleNumFieldElem, a::QQFieldElem, b::AbsSimpleNumFieldElem)
ccall((:nf_elem_fmpq_sub, libflint), Nothing,
Expand All @@ -860,7 +860,7 @@
return c
end

sub!(c::AbsSimpleNumFieldElem, a::Integer, b::AbsSimpleNumFieldElem) = sub!(c, ZZRingElem(a), b)
sub!(c::AbsSimpleNumFieldElem, a::Integer, b::AbsSimpleNumFieldElem) = sub!(c, flintify(a), b)

Check warning on line 863 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L863

Added line #L863 was not covered by tests

function mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::QQFieldElem)
ccall((:nf_elem_scalar_mul_fmpq, libflint), Nothing,
Expand All @@ -883,7 +883,7 @@
return c
end

mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = mul!(c, a, ZZRingElem(b))
mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = mul!(c, a, flintify(b))

Check warning on line 886 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L886

Added line #L886 was not covered by tests

###############################################################################
#
Expand Down Expand Up @@ -1090,7 +1090,7 @@
return z
end

(a::AbsSimpleNumField)(c::Integer) = a(ZZRingElem(c))
(a::AbsSimpleNumField)(c::Integer) = a(flintify(c))

Check warning on line 1093 in src/antic/nf_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/antic/nf_elem.jl#L1093

Added line #L1093 was not covered by tests

function (a::AbsSimpleNumField)(c::ZZRingElem)
z = AbsSimpleNumFieldElem(a)
Expand Down
20 changes: 10 additions & 10 deletions src/arb/Complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,21 @@
return z
end

+(x::ComplexFieldElem, y::Integer) = x + ZZRingElem(y)
+(x::ComplexFieldElem, y::Integer) = x + flintify(y)

-(x::ComplexFieldElem, y::Integer) = x - ZZRingElem(y)
-(x::ComplexFieldElem, y::Integer) = x - flintify(y)

*(x::ComplexFieldElem, y::Integer) = x*ZZRingElem(y)
*(x::ComplexFieldElem, y::Integer) = x*flintify(y)

//(x::ComplexFieldElem, y::Integer) = x//ZZRingElem(y)
//(x::ComplexFieldElem, y::Integer) = x//flintify(y)

+(x::Integer, y::ComplexFieldElem) = ZZRingElem(x) + y
+(x::Integer, y::ComplexFieldElem) = flintify(x) + y

-(x::Integer, y::ComplexFieldElem) = ZZRingElem(x) - y
-(x::Integer, y::ComplexFieldElem) = flintify(x) - y

*(x::Integer, y::ComplexFieldElem) = ZZRingElem(x)*y
*(x::Integer, y::ComplexFieldElem) = flintify(x)*y

//(x::Integer, y::ComplexFieldElem) = ZZRingElem(x)//y
//(x::Integer, y::ComplexFieldElem) = flintify(x)//y

divexact(x::ComplexFieldElem, y::ComplexFieldElem; check::Bool=true) = x // y
divexact(x::ZZRingElem, y::ComplexFieldElem; check::Bool=true) = x // y
Expand Down Expand Up @@ -352,8 +352,8 @@
==(x::ComplexFieldElem,y::ZZRingElem) = (x == parent(x)(y))
==(x::ZZRingElem,y::ComplexFieldElem) = (y == parent(y)(x))

==(x::ComplexFieldElem,y::Integer) = x == ZZRingElem(y)
==(x::Integer,y::ComplexFieldElem) = ZZRingElem(x) == y
==(x::ComplexFieldElem,y::Integer) = x == flintify(y)
==(x::Integer,y::ComplexFieldElem) = flintify(x) == y

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

View check run for this annotation

Codecov / codecov/patch

src/arb/Complex.jl#L355-L356

Added lines #L355 - L356 were not covered by tests

==(x::ComplexFieldElem,y::Float64) = (x == parent(x)(y))
==(x::Float64,y::ComplexFieldElem) = (y == parent(y)(x))
Expand Down
132 changes: 0 additions & 132 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4715,85 +4715,6 @@ mutable struct QQMatrix <: MatElem{QQFieldElem}
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{QQFieldElem})
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[i, j])
end
end
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem})
z = QQMatrix(r, c)
b = ZZRingElem(1)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[i, j], b)
end
end
return z
end


function QQMatrix(r::Int, c::Int, arr::AbstractVector{QQFieldElem})
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[(i-1)*c+j])
end
end
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem})
z = QQMatrix(r, c)
b = ZZRingElem(1)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[(i-1)*c+j], b)
end
end
return z
end


function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{T}) where {T <: Integer}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, QQFieldElem(arr[i, j]))
end
end
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractVector{T}) where {T <: Integer}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, QQFieldElem(arr[(i-1)*c+j]))
end
end
return z
end

function QQMatrix(r::Int, c::Int, d::QQFieldElem)
z = QQMatrix(r, c)
GC.@preserve z for i = 1:min(r, c)
el = mat_entry_ptr(z, i, i)
set!(el, d)
end
return z
end

function QQMatrix(m::QQMatrix)
z = new()
ccall((:fmpq_mat_init_set, libflint), Nothing,
Expand Down Expand Up @@ -4837,59 +4758,6 @@ mutable struct ZZMatrix <: MatElem{ZZRingElem}
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem})
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[i, j])
end
end
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem})
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[(i-1)*c+j])
end
end
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractMatrix{T}) where {T <: Integer}
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, ZZRingElem(arr[i, j]))
end
end
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractVector{T}) where {T <: Integer}
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, ZZRingElem(arr[(i-1)*c+j]))
end
end
return z
end

function ZZMatrix(r::Int, c::Int, d::ZZRingElem)
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:min(r, c)
el = mat_entry_ptr(z, i, i)
set!(el, d)
end
return z
end

function ZZMatrix(m::ZZMatrix)
z = new()
ccall((:fmpz_mat_init_set, libflint), Nothing,
Expand Down
43 changes: 26 additions & 17 deletions src/flint/fmpq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -910,36 +910,45 @@ promote_rule(::Type{QQMatrix}, ::Type{Rational{T}}) where T <: Union{Int, BigInt
#
###############################################################################

function matrix(R::QQField, arr::AbstractMatrix{QQFieldElem})
function matrix(R::QQField, arr::AbstractMatrix{T}) where {T <: RationalUnion}
z = QQMatrix(size(arr, 1), size(arr, 2), arr)
return z
end

function matrix(R::QQField, arr::AbstractMatrix{<: Union{ZZRingElem, Int, BigInt}})
z = QQMatrix(size(arr, 1), size(arr, 2), arr)
return z
end

function matrix(R::QQField, arr::AbstractMatrix{Rational{T}}) where {T <: Integer}
z = QQMatrix(size(arr, 1), size(arr, 2), map(QQFieldElem, arr))
function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{T}) where {T <: RationalUnion}
_check_dim(r, c, arr)
z = QQMatrix(r, c, arr)
return z
end

function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{QQFieldElem})
_check_dim(r, c, arr)
z = QQMatrix(r, c, arr)
function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{T}) where {T <: RationalUnion}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, flintify(arr[i, j]))
end
end
return z
end

function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{<: Union{ZZRingElem, Int, BigInt}})
_check_dim(r, c, arr)
z = QQMatrix(r, c, arr)
function QQMatrix(r::Int, c::Int, arr::AbstractVector{T}) where {T <: RationalUnion}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, flintify(arr[(i-1)*c+j]))
end
end
return z
end

function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{Rational{T}}) where {T <: Union{ZZRingElem, Int, BigInt}}
_check_dim(r, c, arr)
z = QQMatrix(r, c, map(QQFieldElem, arr))
function QQMatrix(r::Int, c::Int, d::RationalUnion)
z = QQMatrix(r, c)
GC.@preserve z for i = 1:min(r, c)
el = mat_entry_ptr(z, i, i)
set!(el, d)
end
return z
end

Expand Down
14 changes: 7 additions & 7 deletions src/flint/fmpq_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@

*(x::QQPolyRingElem, y::QQFieldElem) = y*x

+(x::Integer, y::QQPolyRingElem) = y + ZZRingElem(x)
+(x::Integer, y::QQPolyRingElem) = y + flintify(x)

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L265

Added line #L265 was not covered by tests

-(x::Integer, y::QQPolyRingElem) = ZZRingElem(x) - y
-(x::Integer, y::QQPolyRingElem) = flintify(x) - y

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L267

Added line #L267 was not covered by tests

*(x::Integer, y::QQPolyRingElem) = ZZRingElem(x)*y
*(x::Integer, y::QQPolyRingElem) = flintify(x)*y

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L269

Added line #L269 was not covered by tests

+(x::QQPolyRingElem, y::Integer) = x + ZZRingElem(y)
+(x::QQPolyRingElem, y::Integer) = x + flintify(y)

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L271

Added line #L271 was not covered by tests

-(x::QQPolyRingElem, y::Integer) = x - ZZRingElem(y)
-(x::QQPolyRingElem, y::Integer) = x - flintify(y)

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L273

Added line #L273 was not covered by tests

*(x::QQPolyRingElem, y::Integer) = ZZRingElem(y)*x
*(x::QQPolyRingElem, y::Integer) = flintify(y)*x

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L275

Added line #L275 was not covered by tests

+(x::Rational, y::QQPolyRingElem) = QQFieldElem(x) + y

Expand Down Expand Up @@ -488,7 +488,7 @@
return z
end

divexact(x::QQPolyRingElem, y::Integer; check::Bool=true) = divexact(x, ZZRingElem(y); check=check)
divexact(x::QQPolyRingElem, y::Integer; check::Bool=true) = divexact(x, flintify(y); check=check)

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

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq_poly.jl#L491

Added line #L491 was not covered by tests

divexact(x::QQPolyRingElem, y::Rational{T}; check::Bool=true) where T <: Union{Int, BigInt} = divexact(x, QQFieldElem(y); check=check)

Expand Down
4 changes: 2 additions & 2 deletions src/flint/fmpq_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ end

*(x::QQRelPowerSeriesRingElem, y::QQFieldElem) = y * x

*(x::QQRelPowerSeriesRingElem, y::Integer) = x * ZZRingElem(y)
*(x::QQRelPowerSeriesRingElem, y::Integer) = x * flintify(y)

*(x::Integer, y::QQRelPowerSeriesRingElem) = ZZRingElem(x) * y
*(x::Integer, y::QQRelPowerSeriesRingElem) = flintify(x) * y

*(x::QQRelPowerSeriesRingElem, y::Rational) = x * QQFieldElem(y)

Expand Down
Loading
Loading