Skip to content

Commit

Permalink
Restrict unsafe ops for ResElem to EuclideanRingResidueRingElem (#1836)
Browse files Browse the repository at this point in the history
They rely on implementation details and thus are not truly generic.
In practice they cause problems for ResElem subtypes in Nemo.
  • Loading branch information
fingolfin authored Oct 7, 2024
1 parent 63d54c2 commit 1d0ef5a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,27 +404,6 @@ end
# interface)
_div_for_howell_form(a::T, b::T) where {T <: RingElement} = div(a, b)

###############################################################################
#
# Unsafe functions
#
###############################################################################

function zero!(a::ResElem{T}) where {T <: RingElement}
a.data = zero!(a.data)
return a
end

function mul!(c::ResElem{T}, a::ResElem{T}, b::ResElem{T}) where {T <: RingElement}
c.data = mod(data(a)*data(b), modulus(a))
return c
end

function add!(c::ResElem{T}, a::ResElem{T}, b::ResElem{T}) where {T <: RingElement}
c.data = mod(data(a) + data(b), modulus(a))
return c
end

###############################################################################
#
# Random functions
Expand Down
21 changes: 21 additions & 0 deletions src/generic/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,24 @@ function rand(R::Union{EuclideanRingResidueRing{T}, EuclideanRingResidueField{T}
end
return r
end

###############################################################################
#
# Unsafe functions
#
###############################################################################

function zero!(a::T) where {T <: EuclideanRingResidueRingElem}
a.data = zero!(a.data)
return a
end

function mul!(c::T, a::T, b::T) where {T <: EuclideanRingResidueRingElem}
c.data = mod(data(a)*data(b), modulus(a))
return c
end

function add!(c::T, a::T, b::T) where {T <: EuclideanRingResidueRingElem}
c.data = mod(data(a) + data(b), modulus(a))
return c
end

0 comments on commit 1d0ef5a

Please sign in to comment.