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

Add more special Solve.* methods #1668

Merged
merged 8 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
More (simple) tests
  • Loading branch information
joschmitt committed Feb 9, 2024
commit 7548477664c540dc711881aa81832ecced0dd0a2
14 changes: 14 additions & 0 deletions test/flint/fmpq_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,20 @@ end

@test_throws ArgumentError AbstractAlgebra.Solve.can_solve_with_solution(A, B, side = :garbage)
@test_throws ArgumentError AbstractAlgebra.Solve.can_solve(A, B, side = :garbage)

A = matrix(QQ, [ 1 2 3 ; 4 5 6 ])
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :right)
@test is_zero(A*K)
@test ncols(K) == 1

K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 0

A = transpose(A)
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 1
end

@testset "QQMatrix.concat" begin
Expand Down
14 changes: 14 additions & 0 deletions test/flint/fmpz_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,20 @@ end
@test x*A == B
@test is_zero(K*A)
@test nrows(K) + rank(A) == nrows(A)

A = matrix(ZZ, [ 1 2 3 ; 4 5 6 ])
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :right)
@test is_zero(A*K)
@test ncols(K) == 1

K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 0

A = transpose(A)
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 1
end

@testset "ZZMatrix.concat" begin
Expand Down
62 changes: 38 additions & 24 deletions test/flint/fmpz_mod_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,30 +588,44 @@ end
=#

@testset "ZZModMatrix.Solve.solve" begin
Z17, = residue_ring(ZZ, ZZ(17))
a = matrix(Z17, [1 2 3; 3 2 1; 0 0 2])
b = matrix(Z17, [2 1 0 1; 0 0 0 0; 0 1 2 0])
c = a*b
d = AbstractAlgebra.Solve.solve(a, c)
@test d == b

a = zero(a, 3, 3)
@test_throws ArgumentError AbstractAlgebra.Solve.solve(a, c)

A = matrix(Z17, [1 2 3; 4 5 6])
B = matrix(Z17, 2, 1, [1, 1])
fl, x, K = AbstractAlgebra.Solve.can_solve_with_solution_and_kernel(A, B)
@test fl
@test A*x == B
@test is_zero(A*K)
@test ncols(K) + rank(A) == ncols(A)

B = matrix(Z17, 1, 3, [1, 2, 3])
fl, x, K = AbstractAlgebra.Solve.can_solve_with_solution_and_kernel(A, B, side = :left)
@test fl
@test x*A == B
@test is_zero(K*A)
@test nrows(K) + rank(A) == nrows(A)
Z17, = residue_ring(ZZ, ZZ(17))
a = matrix(Z17, [1 2 3; 3 2 1; 0 0 2])
b = matrix(Z17, [2 1 0 1; 0 0 0 0; 0 1 2 0])
c = a*b
d = AbstractAlgebra.Solve.solve(a, c)
@test d == b

a = zero(a, 3, 3)
@test_throws ArgumentError AbstractAlgebra.Solve.solve(a, c)

A = matrix(Z17, [1 2 3; 4 5 6])
B = matrix(Z17, 2, 1, [1, 1])
fl, x, K = AbstractAlgebra.Solve.can_solve_with_solution_and_kernel(A, B)
@test fl
@test A*x == B
@test is_zero(A*K)
@test ncols(K) + rank(A) == ncols(A)

B = matrix(Z17, 1, 3, [1, 2, 3])
fl, x, K = AbstractAlgebra.Solve.can_solve_with_solution_and_kernel(A, B, side = :left)
@test fl
@test x*A == B
@test is_zero(K*A)
@test nrows(K) + rank(A) == nrows(A)

A = matrix(Z17, [ 1 2 3 ; 4 5 6 ])
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :right)
@test is_zero(A*K)
@test ncols(K) == 1

K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 0

A = transpose(A)
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 1
end

#= Not implemented in Flint yet
Expand Down
14 changes: 14 additions & 0 deletions test/flint/gfp_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@ end

@test_throws ArgumentError AbstractAlgebra.Solve.can_solve_with_solution(A, B, side = :garbage)
@test_throws ArgumentError AbstractAlgebra.Solve.can_solve(A, B, side = :garbage)

A = matrix(Z17, [ 1 2 3 ; 4 5 6 ])
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :right)
@test is_zero(A*K)
@test ncols(K) == 1

K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 0

A = transpose(A)
K = @inferred AbstractAlgebra.Solve.kernel(A, side = :left)
@test is_zero(K*A)
@test nrows(K) == 1
end

@testset "fpMatrix.lu" begin
Expand Down
37 changes: 37 additions & 0 deletions test/flint/nmod_mat-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,40 @@ end
M = rand(S)
@test parent(M) == S
end


@testset "zzModMatrix.Solve.kernel" begin
# Prime modulus
R, _ = residue_ring(ZZ, 17)
M = matrix(R, [ 1 2 3 ; 4 5 6 ])

K = @inferred AbstractAlgebra.Solve.kernel(M, side = :right)
@test is_zero(M*K)
@test ncols(K) == 1

K = @inferred AbstractAlgebra.Solve.kernel(M, side = :left)
@test is_zero(K*M)
@test nrows(K) == 0

M = transpose(M)
K = @inferred AbstractAlgebra.Solve.kernel(M, side = :left)
@test is_zero(K*M)
@test nrows(K) == 1

# Composite modulus
R, _ = residue_ring(ZZ, 18)
M = matrix(R, [ 1 2 3 ; 4 5 6 ])

K = @inferred AbstractAlgebra.Solve.kernel(M, side = :right)
@test is_zero(M*K)
@test ncols(K) == 2

K = @inferred AbstractAlgebra.Solve.kernel(M, side = :left)
@test is_zero(K*M)
@test nrows(K) == 1

M = transpose(M)
K = @inferred AbstractAlgebra.Solve.kernel(M, side = :left)
@test is_zero(K*M)
@test nrows(K) == 2
end
Loading