Skip to content

Commit

Permalink
nmod_mat.jl: some more add!/sub!/mul! changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Dec 18, 2024
1 parent d12b72e commit 3efa482
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/flint/nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,21 @@ end

function +(x::T, y::T) where T <: Zmodn_mat
check_parent(x,y)
z = similar(x)
@ccall libflint.nmod_mat_add(z::Ref{T}, x::Ref{T}, y::Ref{T})::Nothing
return z
return add!(similar(x), x, y)
end

function -(x::T, y::T) where T <: Zmodn_mat
check_parent(x,y)
z = similar(x)
@ccall libflint.nmod_mat_sub(z::Ref{T}, x::Ref{T}, y::Ref{T})::Nothing
return z
return sub!(similar(x), x, y)
end

function *(x::T, y::T) where T <: Zmodn_mat
(base_ring(x) != base_ring(y)) && error("Base ring must be equal")
(ncols(x) != nrows(y)) && error("Dimensions are wrong")
z = similar(x, nrows(x), ncols(y))
@ccall libflint.nmod_mat_mul(z::Ref{T}, x::Ref{T}, y::Ref{T})::Nothing
return z
return mul!(z, x, y)
end


################################################################################
#
# Unsafe operations
Expand Down Expand Up @@ -249,18 +243,29 @@ function mul!(z::Vector{UInt}, a::Vector{UInt}, b::T) where T <: Zmodn_mat
return z
end

function mul!(a::zzModMatrix, b::zzModMatrix, c::zzModRingElem)
@ccall libflint.nmod_mat_scalar_mul(a::Ref{zzModMatrix}, b::Ref{zzModMatrix}, c.data::UInt)::Nothing
function mul!(a::T, b::T, c::UInt) where T <: Zmodn_mat
@ccall libflint.nmod_mat_scalar_mul(a::Ref{T}, b::Ref{T}, c::UInt)::Nothing
return a
end

function mul!(a::T, b::UInt, c::T) where T <: Zmodn_mat
return mul!(a, c, b)

Check warning on line 252 in src/flint/nmod_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/nmod_mat.jl#L251-L252

Added lines #L251 - L252 were not covered by tests
end

function mul!(a::zzModMatrix, b::zzModMatrix, c::zzModRingElem)
return mul!(a, b, c.data)
end

function mul!(a::zzModMatrix, b::zzModRingElem, c::zzModMatrix)
return mul!(a, c, b)
end

function mul!(A::fpMatrix, B::fpFieldElem, D::fpMatrix)
@ccall libflint.nmod_mat_scalar_mul(A::Ref{fpMatrix}, D::Ref{fpMatrix}, B.data::UInt)::Nothing
return A
function mul!(a::fpMatrix, b::fpMatrix, c::fpFieldElem)
return mul!(a, b, c.data)
end

function mul!(a::fpMatrix, b::fpFieldElem, c::fpMatrix)
return mul!(a, c, b)
end

function addmul!(A::fpMatrix, B::fpMatrix, C::fpFieldElem, D::fpMatrix)
Expand All @@ -279,20 +284,14 @@ function Generic.add_one!(a::T, i::Int, j::Int) where T <: Zmodn_mat
return a
end

function mul!(a::fpMatrix, b::fpMatrix, c::fpFieldElem)
return mul!(a, c, b)
end

################################################################################
#
# Ad hoc binary operators
#
################################################################################

function *(x::T, y::UInt) where T <: Zmodn_mat
z = similar(x)
@ccall libflint.nmod_mat_scalar_mul(z::Ref{T}, x::Ref{T}, y::UInt)::Nothing
return z
return mul!(similar(x), x, y)
end

*(x::UInt, y::T) where T <: Zmodn_mat = y*x
Expand Down

0 comments on commit 3efa482

Please sign in to comment.