Skip to content

Commit

Permalink
Remove outdated linear solving methods
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt committed Feb 23, 2024
1 parent c3a3d46 commit 42fd431
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 754 deletions.
8 changes: 0 additions & 8 deletions src/arb/ComplexMat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,6 @@ function _solve!(z::ComplexMat, x::ComplexMat, y::ComplexMat)
nothing
end

function _solve(x::ComplexMat, y::ComplexMat)
ncols(x) != nrows(x) && error("First argument must be square")
ncols(x) != nrows(y) && error("Matrix dimensions are wrong")
z = similar(y)
_solve!(z, x, y)
return z
end

function _solve_lu_precomp!(z::ComplexMat, P::Generic.Perm, LU::ComplexMat, y::ComplexMat)
Q = inv(P)
ccall((:acb_mat_solve_lu_precomp, libarb), Nothing,
Expand Down
8 changes: 0 additions & 8 deletions src/arb/RealMat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,6 @@ function _solve!(z::RealMat, x::RealMat, y::RealMat)
nothing
end

function _solve(x::RealMat, y::RealMat)
ncols(x) != nrows(x) && error("First argument must be square")
ncols(x) != nrows(y) && error("Matrix dimensions are wrong")
z = similar(y)
_solve!(z, x, y)
return z
end

function _solve_lu_precomp!(z::RealMat, P::Generic.Perm, LU::RealMat, y::RealMat)
Q = inv(P)
ccall((:arb_mat_solve_lu_precomp, libarb), Nothing,
Expand Down
8 changes: 0 additions & 8 deletions src/arb/acb_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,6 @@ function _solve!(z::AcbMatrix, x::AcbMatrix, y::AcbMatrix)
nothing
end

function _solve(x::AcbMatrix, y::AcbMatrix)
ncols(x) != nrows(x) && error("First argument must be square")
ncols(x) != nrows(y) && error("Matrix dimensions are wrong")
z = similar(y)
_solve!(z, x, y)
return z
end

function _solve_lu_precomp!(z::AcbMatrix, P::Generic.Perm, LU::AcbMatrix, y::AcbMatrix)
Q = inv(P)
ccall((:acb_mat_solve_lu_precomp, libarb), Nothing,
Expand Down
8 changes: 0 additions & 8 deletions src/arb/arb_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,6 @@ function _solve!(z::ArbMatrix, x::ArbMatrix, y::ArbMatrix)
nothing
end

function _solve(x::ArbMatrix, y::ArbMatrix)
ncols(x) != nrows(x) && error("First argument must be square")
ncols(x) != nrows(y) && error("Matrix dimensions are wrong")
z = similar(y)
_solve!(z, x, y)
return z
end

function _solve_lu_precomp!(z::ArbMatrix, P::Generic.Perm, LU::ArbMatrix, y::ArbMatrix)
Q = inv(P)
ccall((:arb_mat_solve_lu_precomp, libarb), Nothing,
Expand Down
28 changes: 0 additions & 28 deletions src/flint/fmpq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,6 @@ end
#
###############################################################################

function _solve(a::QQMatrix, b::QQMatrix)
nrows(b) != nrows(a) && error("Incompatible dimensions in solve")
fl, z = _can_solve_with_solution(a, b)
!fl && error("System is inconsistent")
return z
end

@doc raw"""
_solve_dixon(a::QQMatrix, b::QQMatrix)
Expand All @@ -683,27 +676,6 @@ function _solve_dixon(a::QQMatrix, b::QQMatrix)
return z
end

function _can_solve_with_solution(a::QQMatrix, b::QQMatrix; side::Symbol = :right)
if side == :left
(ncols(a) != ncols(b)) && error("Matrices must have same number of columns")
(f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right)
return (f, transpose(x))
elseif side == :right
(nrows(a) != nrows(b)) && error("Matrices must have same number of rows")
x = similar(a, ncols(a), ncols(b))
r = ccall((:fmpq_mat_can_solve_multi_mod, libflint), Cint,
(Ref{QQMatrix}, Ref{QQMatrix}, Ref{QQMatrix}), x, a, b)
return Bool(r), x
else
error("Unsupported argument :$side for side: Must be :left or :right.")
end
end

function _can_solve(a::QQMatrix, b::QQMatrix; side::Symbol = :right)
fl, _ = _can_solve_with_solution(a, b, side = side)
return fl
end

function Solve._can_solve_internal_no_check(A::QQMatrix, b::QQMatrix, task::Symbol; side::Symbol = :left)
if side === :left
fl, sol, K = Solve._can_solve_internal_no_check(transpose(A), transpose(b), task, side = :right)
Expand Down
25 changes: 0 additions & 25 deletions src/flint/fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1250,21 +1250,6 @@ end
#
###############################################################################

@doc raw"""
_solve(a::ZZMatrix, b::ZZMatrix) -> ZZMatrix
Return a matrix $x$ such that $ax = b$. An exception is raised
if this is not possible.
"""
function _solve(a::ZZMatrix, b::ZZMatrix)
nrows(b) != nrows(a) && error("Incompatible dimensions in solve")
fl, z = _cansolve(a, b)
if !fl
error("system is inconsistent")
end
return z
end

@doc raw"""
_cansolve(a::ZZMatrix, b::ZZMatrix) -> Bool, ZZMatrix
Expand Down Expand Up @@ -1443,16 +1428,6 @@ function AbstractAlgebra._hcat(A::AbstractVector{ZZMatrix})
return M
end

#to override the generic one in AA
function _can_solve_with_solution(a::ZZMatrix, b::ZZMatrix; side::Symbol = :right)
if side == :left
fl, x = Nemo._cansolve(transpose(a), transpose(b))
return fl, transpose(x)
end
return Nemo._cansolve(a, b)
end


@doc raw"""
_cansolve_with_nullspace(a::ZZMatrix, b::ZZMatrix) -> Bool, ZZMatrix, ZZMatrix
Expand Down
16 changes: 1 addition & 15 deletions src/flint/fmpz_mod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -485,21 +485,6 @@ end
#
################################################################################

#= Not implemented in Flint yet
function _solve(x::T, y::T) where T <: Zmod_fmpz_mat
(base_ring(x) != base_ring(y)) && error("Matrices must have same base ring")
!is_square(x)&& error("First argument not a square matrix in solve")
(y.r != x.r) || y.c != 1 && ("Not a column vector in solve")
z = similar(y)
r = ccall((:fmpz_mod_mat_solve, libflint), Int,
(Ref{T}, Ref{T}, Ref{T}), z, x, y)
!Bool(r) && error("Singular matrix in solve")
return z
end
=#

function Solve._can_solve_internal_no_check(A::ZZModMatrix, b::ZZModMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
Expand All @@ -508,6 +493,7 @@ function Solve._can_solve_internal_no_check(A::ZZModMatrix, b::ZZModMatrix, task
end

x = similar(A, ncols(A), ncols(b))
# This is probably only correct if the characteristic is prime
fl = ccall((:fmpz_mod_mat_can_solve, libflint), Cint,
(Ref{ZZModMatrix}, Ref{ZZModMatrix}, Ref{ZZModMatrix}), x, A, b)
if task === :only_check || task === :with_solution
Expand Down
35 changes: 0 additions & 35 deletions src/flint/fq_default_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,41 +415,6 @@ end
#
################################################################################

function _solve(x::FqMatrix, y::FqMatrix)
(base_ring(x) != base_ring(y)) && error("Matrices must have same base ring")
!is_square(x)&& error("First argument not a square matrix in _solve")
(nrows(y) != nrows(x)) || ncols(y) != 1 && ("Not a column vector in _solve")
z = similar(y)
r = ccall((:fq_default_mat_solve, libflint), Int,
(Ref{FqMatrix}, Ref{FqMatrix}, Ref{FqMatrix}, Ref{FqField}),
z, x, y, base_ring(x))
!Bool(r) && error("Singular matrix in _solve")
return z
end

function _can_solve_with_solution(a::FqMatrix, b::FqMatrix; side::Symbol = :right)
(base_ring(a) != base_ring(b)) && error("Matrices must have same base ring")
if side == :left
(ncols(a) != ncols(b)) && error("Matrices must have same number of columns")
(f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right)
return (f, transpose(x))
elseif side == :right
(nrows(a) != nrows(b)) && error("Matrices must have same number of rows")
x = similar(a, ncols(a), ncols(b))
r = ccall((:fq_default_mat_can_solve, libflint), Cint,
(Ref{FqMatrix}, Ref{FqMatrix}, Ref{FqMatrix},
Ref{FqField}), x, a, b, base_ring(a))
return Bool(r), x
else
error("Unsupported argument :$side for side: Must be :left or :right.")
end
end

function _can_solve(a::FqMatrix, b::FqMatrix; side::Symbol = :right)
fl, _ = _can_solve_with_solution(a, b, side = side)
return fl
end

function Solve._can_solve_internal_no_check(A::FqMatrix, b::FqMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
Expand Down
35 changes: 0 additions & 35 deletions src/flint/fq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,41 +422,6 @@ end
#
################################################################################

function _solve(x::FqPolyRepMatrix, y::FqPolyRepMatrix)
(base_ring(x) != base_ring(y)) && error("Matrices must have same base ring")
!is_square(x)&& error("First argument not a square matrix in _solve")
(nrows(y) != nrows(x)) || ncols(y) != 1 && ("Not a column vector in _solve")
z = similar(y)
r = ccall((:fq_mat_solve, libflint), Int,
(Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, Ref{FqPolyRepField}),
z, x, y, base_ring(x))
!Bool(r) && error("Singular matrix in _solve")
return z
end

function _can_solve_with_solution(a::FqPolyRepMatrix, b::FqPolyRepMatrix; side::Symbol = :right)
(base_ring(a) != base_ring(b)) && error("Matrices must have same base ring")
if side == :left
(ncols(a) != ncols(b)) && error("Matrices must have same number of columns")
(f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right)
return (f, transpose(x))
elseif side == :right
(nrows(a) != nrows(b)) && error("Matrices must have same number of rows")
x = similar(a, ncols(a), ncols(b))
r = ccall((:fq_mat_can_solve, libflint), Cint,
(Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix},
Ref{FqPolyRepField}), x, a, b, base_ring(a))
return Bool(r), x
else
error("Unsupported argument :$side for side: Must be :left or :right.")
end
end

function _can_solve(a::FqPolyRepMatrix, b::FqPolyRepMatrix; side::Symbol = :right)
fl, _ = _can_solve_with_solution(a, b, side = side)
return fl
end

function Solve._can_solve_internal_no_check(A::FqPolyRepMatrix, b::FqPolyRepMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
Expand Down
35 changes: 0 additions & 35 deletions src/flint/fq_nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,41 +410,6 @@ end
#
################################################################################

function _solve(x::fqPolyRepMatrix, y::fqPolyRepMatrix)
(base_ring(x) != base_ring(y)) && error("Matrices must have same base ring")
!is_square(x)&& error("First argument not a square matrix in _solve")
(nrows(y) != nrows(x)) || ncols(y) != 1 && ("Not a column vector in _solve")
z = similar(y)
r = ccall((:fq_nmod_mat_solve, libflint), Int,
(Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, Ref{fqPolyRepField}),
z, x, y, base_ring(x))
!Bool(r) && error("Singular matrix in _solve")
return z
end

function _can_solve_with_solution(a::fqPolyRepMatrix, b::fqPolyRepMatrix; side::Symbol = :right)
(base_ring(a) != base_ring(b)) && error("Matrices must have same base ring")
if side == :left
(ncols(a) != ncols(b)) && error("Matrices must have same number of columns")
(f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right)
return (f, transpose(x))
elseif side == :right
(nrows(a) != nrows(b)) && error("Matrices must have same number of rows")
x = similar(a, ncols(a), ncols(b))
r = ccall((:fq_nmod_mat_can_solve, libflint), Cint,
(Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix},
Ref{fqPolyRepField}), x, a, b, base_ring(a))
return Bool(r), x
else
error("Only side = :right or :left is supported (:$side)")
end
end

function _can_solve(a::fqPolyRepMatrix, b::fqPolyRepMatrix; side::Symbol = :right)
fl, _ = _can_solve_with_solution(a, b, side = side)
return fl
end

function Solve._can_solve_internal_no_check(A::fqPolyRepMatrix, b::fqPolyRepMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
Expand Down
22 changes: 22 additions & 0 deletions src/flint/gfp_fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,25 @@ function nullspace(M::FpMatrix)
(Ref{FpMatrix}, Ref{FpMatrix}, Ref{FpField}), N, M, base_ring(M))
return nullity, view(N, 1:nrows(N), 1:nullity)
end

################################################################################
#
# Linear solving
#
################################################################################

function Solve._can_solve_internal_no_check(A::FpMatrix, b::FpMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
fl, sol, K = Solve._can_solve_internal_no_check(transpose(A), transpose(b), task, side = :right)
return fl, transpose(sol), transpose(K)
end

x = similar(A, ncols(A), ncols(b))
fl = ccall((:fmpz_mod_mat_can_solve, libflint), Cint,
(Ref{FpMatrix}, Ref{FpMatrix}, Ref{FpMatrix}), x, A, b)
if task === :only_check || task === :with_solution
return Bool(fl), x, zero(A, 0, 0)
end
return Bool(fl), x, kernel(A, side = :right)
end
22 changes: 0 additions & 22 deletions src/flint/gfp_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,28 +290,6 @@ end
#
################################################################################

function _can_solve_with_solution(a::fpMatrix, b::fpMatrix; side::Symbol = :right)
(base_ring(a) != base_ring(b)) && error("Matrices must have same base ring")
if side == :left
(ncols(a) != ncols(b)) && error("Matrices must have same number of columns")
(f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right)
return (f, transpose(x))
elseif side == :right
(nrows(a) != nrows(b)) && error("Matrices must have same number of rows")
x = similar(a, ncols(a), ncols(b))
r = ccall((:nmod_mat_can_solve, libflint), Cint,
(Ref{fpMatrix}, Ref{fpMatrix}, Ref{fpMatrix}), x, a, b)
return Bool(r), x
else
error("Unsupported argument :$side for side: Must be :left or :right.")
end
end

function _can_solve(a::fpMatrix, b::fpMatrix; side::Symbol = :right)
fl, _ = _can_solve_with_solution(a, b, side = side)
return fl
end

function Solve._can_solve_internal_no_check(A::fpMatrix, b::fpMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
Expand Down
29 changes: 18 additions & 11 deletions src/flint/nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,6 @@ end
#
################################################################################

function _solve(x::T, y::T) where T <: Zmodn_mat
(base_ring(x) != base_ring(y)) && error("Matrices must have same base ring")
!is_square(x)&& error("First argument not a square matrix in _solve")
(y.r != x.r) || y.c != 1 && ("Not a column vector in _solve")
z = similar(y)
r = ccall((:nmod_mat_solve, libflint), Int,
(Ref{T}, Ref{T}, Ref{T}), z, x, y)
!Bool(r) && error("Singular matrix in _solve")
return z
end

function AbstractAlgebra._solve_triu(x::T, y::T) where T <: Zmodn_mat
(base_ring(x) != base_ring(y)) && error("Matrices must have same base ring")
is_upper_trangular(x) || error("Matrix must be upper triangular")
Expand All @@ -523,6 +512,24 @@ function AbstractAlgebra._solve_tril!(A::T, B::T, C::T, unit::Int = 0) where T <
ccall((:nmod_mat_solve_tril, Nemo.libflint), Cvoid, (Ref{T}, Ref{T}, Ref{T}, Cint), A, B, C, unit)
end

function Solve._can_solve_internal_no_check(A::zzModMatrix, b::zzModMatrix, task::Symbol; side::Symbol = :left)
check_parent(A, b)
if side === :left
fl, sol, K = Solve._can_solve_internal_no_check(transpose(A), transpose(b), task, side = :right)
return fl, transpose(sol), transpose(K)
end

x = similar(A, ncols(A), ncols(b))
# This is probably only correct if the characteristic is prime
fl = ccall((:nmod_mat_can_solve, libflint), Cint,
(Ref{zzModMatrix}, Ref{zzModMatrix}, Ref{zzModMatrix}),
x, A, b)
if task === :only_check || task === :with_solution
return Bool(fl), x, zero(A, 0, 0)
end
return Bool(fl), x, kernel(A, side = :right)
end

################################################################################
#
# LU decomposition
Expand Down
Loading

0 comments on commit 42fd431

Please sign in to comment.