Skip to content

Commit

Permalink
Use flintify some more
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Sep 30, 2024
1 parent 8b486cc commit aed53df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 47 deletions.
10 changes: 5 additions & 5 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ for T in (ZZRingElem, Int, UInt)
end
end

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

+(a::QQFieldElem, b::Rational{T}) where {T <: Integer} = a + QQFieldElem(b)
Expand All @@ -312,8 +312,8 @@ for T in (ZZRingElem, Int, UInt)
end
end

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

Check warning on line 316 in src/flint/fmpq.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq.jl#L316

Added line #L316 was not covered by tests

-(a::QQFieldElem, b::Rational{T}) where {T <: Integer} = a - QQFieldElem(b)
-(a::Rational{T}, b::QQFieldElem) where {T <: Integer} = QQFieldElem(a) - b
Expand All @@ -325,7 +325,7 @@ for T in (ZZRingElem, Int, UInt)
end
end

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

Check warning on line 328 in src/flint/fmpq.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq.jl#L328

Added line #L328 was not covered by tests
*(a::Integer, b::QQFieldElem) = b * a

*(a::QQFieldElem, b::Rational{T}) where {T <: Integer} = a * QQFieldElem(b)
Expand Down Expand Up @@ -356,7 +356,7 @@ function cmp(a::QQFieldElemOrPtr, b::UInt)
@ccall libflint.fmpq_cmp_ui(a::Ref{QQFieldElem}, b::UInt)::Cint
end

cmp(a::QQFieldElemOrPtr, b::Integer) = cmp(a, ZZRingElem(b))
cmp(a::QQFieldElemOrPtr, b::Integer) = cmp(a, flintify(b))

Check warning on line 359 in src/flint/fmpq.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpq.jl#L359

Added line #L359 was not covered by tests

cmp(a::Union{ZZRingElemOrPtr, Integer}, b::QQFieldElemOrPtr) = -cmp(b, a)

Expand Down
28 changes: 2 additions & 26 deletions src/flint/fmpq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,11 @@ end
return v
end

@inline function setindex!(a::QQMatrix, d::ZZRingElem, r::Int, c::Int)
@inline function setindex!(a::QQMatrix, d::RationalUnion, r::Int, c::Int)
@boundscheck _checkbounds(a, r, c)
GC.@preserve a begin
z = mat_entry_ptr(a, r, c)
set!(z, d)
end
end

@inline function setindex!(a::QQMatrix, d::QQFieldElem, r::Int, c::Int)
@boundscheck _checkbounds(a, r, c)
GC.@preserve a begin
z = mat_entry_ptr(a, r, c)
set!(z, d)
end
end

Base.@propagate_inbounds setindex!(a::QQMatrix, d::Integer,
r::Int, c::Int) =
setindex!(a, ZZRingElem(d), r, c)

@inline function setindex!(a::QQMatrix, d::Int, r::Int, c::Int)
@boundscheck _checkbounds(a, r, c)
GC.@preserve a begin
z = mat_entry_ptr(a, r, c)
set!(z, d)
set!(z, flintify(d))
end
end

Expand All @@ -136,10 +116,6 @@ function setindex!(a::QQMatrix, b::QQMatrix, r::UnitRange{Int64}, c::UnitRange{I
(Ref{QQMatrix}, Ref{QQMatrix}), A, b)
end

Base.@propagate_inbounds setindex!(a::QQMatrix, d::Rational,
r::Int, c::Int) =
setindex!(a, QQFieldElem(d), r, c)

number_of_rows(a::QQMatrix) = a.r

number_of_columns(a::QQMatrix) = a.c
Expand Down
8 changes: 4 additions & 4 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2569,8 +2569,8 @@ function add!(a::ZZRingElem, b::ZZRingElem, c::Ptr{Int})
return a
end

add!(z::ZZRingElem, a::ZZRingElem, b::Integer) = add!(z, a, ZZRingElem(b))
add!(z::ZZRingElem, x::Int, y::ZZRingElem) = add!(z, y, x)
add!(z::ZZRingElemOrPtr, a::ZZRingElemOrPtr, b::Integer) = add!(z, a, flintify(b))
add!(z::ZZRingElemOrPtr, x::Int, y::ZZRingElemOrPtr) = add!(z, y, x)

function neg!(z::ZZRingElemOrPtr, a::ZZRingElemOrPtr)
ccall((:fmpz_neg, libflint), Nothing,
Expand Down Expand Up @@ -2603,7 +2603,7 @@ function sub!(z::ZZRingElemOrPtr, a::ZZRingElemOrPtr, b::UInt)
end

function sub!(z::ZZRingElemOrPtr, a::ZZRingElemOrPtr, b::Integer)
return sub!(z, a, ZZRingElem(b))
return sub!(z, a, flintify(b))
end

function sub!(z::ZZRingElemOrPtr, b::Integer, a::ZZRingElemOrPtr)
Expand All @@ -2630,7 +2630,7 @@ function mul!(z::ZZRingElemOrPtr, x::ZZRingElemOrPtr, y::UInt)
return z
end

mul!(z::ZZRingElemOrPtr, a::ZZRingElemOrPtr, b::Integer) = mul!(z, a, ZZRingElem(b))
mul!(z::ZZRingElemOrPtr, a::ZZRingElemOrPtr, b::Integer) = mul!(z, a, flintify(b))

Check warning on line 2633 in src/flint/fmpz.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz.jl#L2633

Added line #L2633 was not covered by tests

mul!(z::ZZRingElemOrPtr, x::Integer, y::ZZRingElemOrPtr) = mul!(z, y, x)

Expand Down
14 changes: 2 additions & 12 deletions src/flint/fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,11 @@ end
return v
end

@inline function setindex!(a::ZZMatrix, d::ZZRingElem, r::Int, c::Int)
@inline function setindex!(a::ZZMatrix, d::IntegerUnion, r::Int, c::Int)
@boundscheck _checkbounds(a, r, c)
GC.@preserve a begin
z = mat_entry_ptr(a, r, c)
set!(z, d)
end
end

@inline setindex!(a::ZZMatrix, d::Integer, r::Int, c::Int) = setindex!(a, ZZRingElem(d), r, c)

@inline function setindex!(a::ZZMatrix, d::Int, r::Int, c::Int)
@boundscheck _checkbounds(a, r, c)
GC.@preserve a begin
z = mat_entry_ptr(a, r, c)
set!(z, d)
set!(z, flintify(d))
end
end

Expand Down

0 comments on commit aed53df

Please sign in to comment.