Skip to content

Commit

Permalink
Don't call nullspace for RingElem and add a deepcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt committed Feb 7, 2024
1 parent cd38e14 commit 12717eb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ is, $KA$ is the zero matrix.
If a context object `C` is supplied, then the above applies for `A = matrix(C)`.
"""
function kernel(A::MatElem; side::Symbol = :right)
function kernel(A::MatElem{<:FieldElement}; side::Symbol = :right)
check_option(side, [:right, :left], "side")

if side === :left
Expand All @@ -310,6 +310,21 @@ function kernel(A::MatElem; side::Symbol = :right)
return K
end

function kernel(A::MatElem{<:RingElement}; side::Symbol = :right)
check_option(side, [:right, :left], "side")

R, U = hnf_with_transform(lazy_transpose(A))
if side === :right
R, U = hnf_with_transform(lazy_transpose(A))
return _kernel_of_hnf(A, R, U)[2]
else
R, U = hnf_with_transform(A)
_, X = _kernel_of_hnf(lazy_transpose(A), R, U)
# X is of type LazyTransposeMatElem
return data(X)
end
end

function kernel(C::SolveCtx{<:FieldElement}; side::Symbol = :right)
check_option(side, [:right, :left], "side")

Expand Down Expand Up @@ -432,7 +447,7 @@ function _can_solve_internal_no_check(A::MatElem{T}, b::MatElem{T}, task::Symbol
return fl, data(sol), data(K)
end

mu = hcat(A, b)
mu = hcat(deepcopy(A), deepcopy(b))

rk = rref!(mu)
p = pivot_and_non_pivot_cols(mu, rk)
Expand Down Expand Up @@ -621,7 +636,7 @@ end

# Copied from Hecke, to be replaced with echelon_form_with_transformation eventually
function _rref_with_transformation(M::MatElem{T}) where T <: FieldElement
n = hcat(M, identity_matrix(base_ring(M), nrows(M)))
n = hcat(deepcopy(M), identity_matrix(base_ring(M), nrows(M)))
rref!(n)
s = nrows(n)
while s > 0 && iszero(sub(n, s:s, 1:ncols(M)))
Expand Down

0 comments on commit 12717eb

Please sign in to comment.