From 3efa482dc8ce983bab1955b89712b123dec5e916 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 19 Dec 2024 00:15:10 +0100 Subject: [PATCH] nmod_mat.jl: some more add!/sub!/mul! changes --- src/flint/nmod_mat.jl | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/flint/nmod_mat.jl b/src/flint/nmod_mat.jl index 1a1ed2e84..b1d5df622 100644 --- a/src/flint/nmod_mat.jl +++ b/src/flint/nmod_mat.jl @@ -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 @@ -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) +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) @@ -279,10 +284,6 @@ 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 @@ -290,9 +291,7 @@ end ################################################################################ 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