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

nmod_mat.jl: some more add!/sub!/mul! changes #1981

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
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 @@

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 @@
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 @@
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
Loading