Skip to content

Commit 2f8e35d

Browse files
Merge pull request #2181 from fredrik-johansson/matrix5
Refactor fq_*_mat solving code using generics
2 parents a889164 + 998d52f commit 2f8e35d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+115
-1834
lines changed

doc/source/fq_mat.rst

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,6 @@ LU decomposition
355355
will abandon the output matrix in an undefined state and return 0
356356
if `A` is detected to be rank-deficient.
357357

358-
This function calls ``fq_mat_lu_recursive``.
359-
360-
.. function:: slong fq_mat_lu_classical(slong * P, fq_mat_t A, int rank_check, const fq_ctx_t ctx)
361-
362-
Computes a generalised LU decomposition `LU = PA` of a given
363-
matrix `A`, returning the rank of `A`. The behavior of this
364-
function is identical to that of ``fq_mat_lu``. Uses Gaussian
365-
elimination.
366-
367-
.. function:: slong fq_mat_lu_recursive(slong * P, fq_mat_t A, int rank_check, const fq_ctx_t ctx)
368-
369-
Computes a generalised LU decomposition `LU = PA` of a given
370-
matrix `A`, returning the rank of `A`. The behavior of this
371-
function is identical to that of ``fq_mat_lu``. Uses recursive
372-
block decomposition, switching to classical Gaussian elimination
373-
for sufficiently small blocks.
374-
375358

376359
Reduced row echelon form
377360
--------------------------------------------------------------------------------
@@ -413,33 +396,6 @@ Triangular solving
413396
is allowed. Automatically chooses between the classical and
414397
recursive algorithms.
415398

416-
.. function:: void fq_mat_solve_tril_classical(fq_mat_t X, const fq_mat_t L, const fq_mat_t B, int unit, const fq_ctx_t ctx)
417-
418-
Sets `X = L^{-1} B` where `L` is a full rank lower triangular
419-
square matrix. If ``unit`` = 1, `L` is assumed to have ones on
420-
its main diagonal, and the main diagonal will not be read. `X`
421-
and `B` are allowed to be the same matrix, but no other aliasing
422-
is allowed. Uses forward substitution.
423-
424-
.. function:: void fq_mat_solve_tril_recursive(fq_mat_t X, const fq_mat_t L, const fq_mat_t B, int unit, const fq_ctx_t ctx)
425-
426-
Sets `X = L^{-1} B` where `L` is a full rank lower triangular
427-
square matrix. If ``unit`` = 1, `L` is assumed to have ones on
428-
its main diagonal, and the main diagonal will not be read. `X`
429-
and `B` are allowed to be the same matrix, but no other aliasing
430-
is allowed.
431-
432-
Uses the block inversion formula
433-
434-
.. math::
435-
\begin{pmatrix} A & 0 \\ C & D \end{pmatrix}^{-1}
436-
\begin{pmatrix} X \\ Y \end{pmatrix} =
437-
\begin{pmatrix} A^{-1} X \\ D^{-1} ( Y - C A^{-1} X ) \end{pmatrix}
438-
439-
440-
to reduce the problem to matrix multiplication and triangular
441-
solving of smaller systems.
442-
443399
.. function:: void fq_mat_solve_triu(fq_mat_t X, const fq_mat_t U, const fq_mat_t B, int unit, const fq_ctx_t ctx)
444400

445401
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
@@ -449,33 +405,6 @@ Triangular solving
449405
is allowed. Automatically chooses between the classical and
450406
recursive algorithms.
451407

452-
.. function:: void fq_mat_solve_triu_classical(fq_mat_t X, const fq_mat_t U, const fq_mat_t B, int unit, const fq_ctx_t ctx)
453-
454-
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
455-
square matrix. If ``unit`` = 1, `U` is assumed to have ones on
456-
its main diagonal, and the main diagonal will not be read. `X`
457-
and `B` are allowed to be the same matrix, but no other aliasing
458-
is allowed. Uses forward substitution.
459-
460-
.. function:: void fq_mat_solve_triu_recursive(fq_mat_t X, const fq_mat_t U, const fq_mat_t B, int unit, const fq_ctx_t ctx)
461-
462-
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
463-
square matrix. If ``unit`` = 1, `U` is assumed to have ones on
464-
its main diagonal, and the main diagonal will not be read. `X`
465-
and `B` are allowed to be the same matrix, but no other aliasing
466-
is allowed.
467-
468-
Uses the block inversion formula
469-
470-
.. math::
471-
\begin{pmatrix} A & B \\ 0 & D \end{pmatrix}^{-1}
472-
\begin{pmatrix} X \\ Y \end{pmatrix} =
473-
\begin{pmatrix} A^{-1} (X - B D^{-1} Y) \\ D^{-1} Y \end{pmatrix}
474-
475-
476-
to reduce the problem to matrix multiplication and triangular
477-
solving of smaller systems.
478-
479408

480409
Solving
481410
--------------------------------------------------------------------------------

doc/source/fq_nmod_mat.rst

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -354,23 +354,6 @@ LU decomposition
354354
will abandon the output matrix in an undefined state and return 0
355355
if `A` is detected to be rank-deficient.
356356

357-
This function calls ``fq_nmod_mat_lu_recursive``.
358-
359-
.. function:: slong fq_nmod_mat_lu_classical(slong * P, fq_nmod_mat_t A, int rank_check, const fq_nmod_ctx_t ctx)
360-
361-
Computes a generalised LU decomposition `LU = PA` of a given
362-
matrix `A`, returning the rank of `A`. The behavior of this
363-
function is identical to that of ``fq_nmod_mat_lu``. Uses Gaussian
364-
elimination.
365-
366-
.. function:: slong fq_nmod_mat_lu_recursive(slong * P, fq_nmod_mat_t A, int rank_check, const fq_nmod_ctx_t ctx)
367-
368-
Computes a generalised LU decomposition `LU = PA` of a given
369-
matrix `A`, returning the rank of `A`. The behavior of this
370-
function is identical to that of ``fq_nmod_mat_lu``. Uses recursive
371-
block decomposition, switching to classical Gaussian elimination
372-
for sufficiently small blocks.
373-
374357

375358
Reduced row echelon form
376359
--------------------------------------------------------------------------------
@@ -412,33 +395,6 @@ Triangular solving
412395
is allowed. Automatically chooses between the classical and
413396
recursive algorithms.
414397

415-
.. function:: void fq_nmod_mat_solve_tril_classical(fq_nmod_mat_t X, const fq_nmod_mat_t L, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx)
416-
417-
Sets `X = L^{-1} B` where `L` is a full rank lower triangular
418-
square matrix. If ``unit`` = 1, `L` is assumed to have ones on
419-
its main diagonal, and the main diagonal will not be read. `X`
420-
and `B` are allowed to be the same matrix, but no other aliasing
421-
is allowed. Uses forward substitution.
422-
423-
.. function:: void fq_nmod_mat_solve_tril_recursive(fq_nmod_mat_t X, const fq_nmod_mat_t L, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx)
424-
425-
Sets `X = L^{-1} B` where `L` is a full rank lower triangular
426-
square matrix. If ``unit`` = 1, `L` is assumed to have ones on
427-
its main diagonal, and the main diagonal will not be read. `X`
428-
and `B` are allowed to be the same matrix, but no other aliasing
429-
is allowed.
430-
431-
Uses the block inversion formula
432-
433-
.. math::
434-
\begin{pmatrix} A & 0 \\ C & D \end{pmatrix}^{-1}
435-
\begin{pmatrix} X \\ Y \end{pmatrix} =
436-
\begin{pmatrix} A^{-1} X \\ D^{-1} ( Y - C A^{-1} X ) \end{pmatrix}
437-
438-
439-
to reduce the problem to matrix multiplication and triangular
440-
solving of smaller systems.
441-
442398
.. function:: void fq_nmod_mat_solve_triu(fq_nmod_mat_t X, const fq_nmod_mat_t U, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx)
443399

444400
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
@@ -448,33 +404,6 @@ Triangular solving
448404
is allowed. Automatically chooses between the classical and
449405
recursive algorithms.
450406

451-
.. function:: void fq_nmod_mat_solve_triu_classical(fq_nmod_mat_t X, const fq_nmod_mat_t U, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx)
452-
453-
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
454-
square matrix. If ``unit`` = 1, `U` is assumed to have ones on
455-
its main diagonal, and the main diagonal will not be read. `X`
456-
and `B` are allowed to be the same matrix, but no other aliasing
457-
is allowed. Uses forward substitution.
458-
459-
.. function:: void fq_nmod_mat_solve_triu_recursive(fq_nmod_mat_t X, const fq_nmod_mat_t U, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx)
460-
461-
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
462-
square matrix. If ``unit`` = 1, `U` is assumed to have ones on
463-
its main diagonal, and the main diagonal will not be read. `X`
464-
and `B` are allowed to be the same matrix, but no other aliasing
465-
is allowed.
466-
467-
Uses the block inversion formula
468-
469-
.. math::
470-
\begin{pmatrix} A & B \\ 0 & D \end{pmatrix}^{-1}
471-
\begin{pmatrix} X \\ Y \end{pmatrix} =
472-
\begin{pmatrix} A^{-1} (X - B D^{-1} Y) \\ D^{-1} Y \end{pmatrix}
473-
474-
475-
to reduce the problem to matrix multiplication and triangular
476-
solving of smaller systems.
477-
478407

479408
Solving
480409
--------------------------------------------------------------------------------

doc/source/fq_zech_mat.rst

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,6 @@ LU decomposition
321321
will abandon the output matrix in an undefined state and return 0
322322
if `A` is detected to be rank-deficient.
323323

324-
This function calls ``fq_zech_mat_lu_recursive``.
325-
326-
.. function:: slong fq_zech_mat_lu_classical(slong * P, fq_zech_mat_t A, int rank_check, const fq_zech_ctx_t ctx)
327-
328-
Computes a generalised LU decomposition `LU = PA` of a given
329-
matrix `A`, returning the rank of `A`. The behavior of this
330-
function is identical to that of ``fq_zech_mat_lu``. Uses Gaussian
331-
elimination.
332-
333-
.. function:: slong fq_zech_mat_lu_recursive(slong * P, fq_zech_mat_t A, int rank_check, const fq_zech_ctx_t ctx)
334-
335-
Computes a generalised LU decomposition `LU = PA` of a given
336-
matrix `A`, returning the rank of `A`. The behavior of this
337-
function is identical to that of ``fq_zech_mat_lu``. Uses recursive
338-
block decomposition, switching to classical Gaussian elimination
339-
for sufficiently small blocks.
340-
341324

342325
Reduced row echelon form
343326
--------------------------------------------------------------------------------
@@ -365,33 +348,6 @@ Triangular solving
365348
is allowed. Automatically chooses between the classical and
366349
recursive algorithms.
367350

368-
.. function:: void fq_zech_mat_solve_tril_classical(fq_zech_mat_t X, const fq_zech_mat_t L, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx)
369-
370-
Sets `X = L^{-1} B` where `L` is a full rank lower triangular
371-
square matrix. If ``unit`` = 1, `L` is assumed to have ones on
372-
its main diagonal, and the main diagonal will not be read. `X`
373-
and `B` are allowed to be the same matrix, but no other aliasing
374-
is allowed. Uses forward substitution.
375-
376-
.. function:: void fq_zech_mat_solve_tril_recursive(fq_zech_mat_t X, const fq_zech_mat_t L, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx)
377-
378-
Sets `X = L^{-1} B` where `L` is a full rank lower triangular
379-
square matrix. If ``unit`` = 1, `L` is assumed to have ones on
380-
its main diagonal, and the main diagonal will not be read. `X`
381-
and `B` are allowed to be the same matrix, but no other aliasing
382-
is allowed.
383-
384-
Uses the block inversion formula
385-
386-
.. math::
387-
\begin{pmatrix} A & 0 \\ C & D \end{pmatrix}^{-1}
388-
\begin{pmatrix} X \\ Y \end{pmatrix} =
389-
\begin{pmatrix} A^{-1} X \\ D^{-1} ( Y - C A^{-1} X ) \end{pmatrix}
390-
391-
392-
to reduce the problem to matrix multiplication and triangular
393-
solving of smaller systems.
394-
395351
.. function:: void fq_zech_mat_solve_triu(fq_zech_mat_t X, const fq_zech_mat_t U, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx)
396352

397353
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
@@ -401,32 +357,6 @@ Triangular solving
401357
is allowed. Automatically chooses between the classical and
402358
recursive algorithms.
403359

404-
.. function:: void fq_zech_mat_solve_triu_classical(fq_zech_mat_t X, const fq_zech_mat_t U, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx)
405-
406-
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
407-
square matrix. If ``unit`` = 1, `U` is assumed to have ones on
408-
its main diagonal, and the main diagonal will not be read. `X`
409-
and `B` are allowed to be the same matrix, but no other aliasing
410-
is allowed. Uses forward substitution.
411-
412-
.. function:: void fq_zech_mat_solve_triu_recursive(fq_zech_mat_t X, const fq_zech_mat_t U, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx)
413-
414-
Sets `X = U^{-1} B` where `U` is a full rank upper triangular
415-
square matrix. If ``unit`` = 1, `U` is assumed to have ones on
416-
its main diagonal, and the main diagonal will not be read. `X`
417-
and `B` are allowed to be the same matrix, but no other aliasing
418-
is allowed.
419-
420-
Uses the block inversion formula
421-
422-
.. math::
423-
\begin{pmatrix} A & B \\ 0 & D \end{pmatrix}^{-1}
424-
\begin{pmatrix} X \\ Y \end{pmatrix} =
425-
\begin{pmatrix} A^{-1} (X - B D^{-1} Y) \\ D^{-1} Y \end{pmatrix}
426-
427-
428-
to reduce the problem to matrix multiplication and triangular
429-
solving of smaller systems.
430360

431361
Solving
432362
--------------------------------------------------------------------------------

src/fq/mat_templates.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include "fq_mat_templates/is_one.c"
4343
#include "fq_mat_templates/is_zero.c"
4444
#include "fq_mat_templates/lu.c"
45-
#include "fq_mat_templates/lu_classical.c"
46-
#include "fq_mat_templates/lu_recursive.c"
4745
#include "fq_mat_templates/mat_entry_set.c"
4846
#include "fq_mat_templates/mat_invert_cols.c"
4947
#include "fq_mat_templates/mat_swap_cols.c"
@@ -70,11 +68,7 @@
7068
#include "fq_mat_templates/similarity.c"
7169
#include "fq_mat_templates/solve.c"
7270
#include "fq_mat_templates/solve_tril.c"
73-
#include "fq_mat_templates/solve_tril_classical.c"
74-
#include "fq_mat_templates/solve_tril_recursive.c"
7571
#include "fq_mat_templates/solve_triu.c"
76-
#include "fq_mat_templates/solve_triu_classical.c"
77-
#include "fq_mat_templates/solve_triu_recursive.c"
7872
#include "fq_mat_templates/sub.c"
7973
#include "fq_mat_templates/submul.c"
8074
#include "fq_mat_templates/swap.c"

src/fq_mat/test/main.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
#include "t-inv.c"
2121
#include "t-invert_rows_cols.c"
2222
#include "t-is_zero.c"
23-
#include "t-lu_classical.c"
24-
#include "t-lu_recursive.c"
23+
#include "t-lu.c"
2524
#include "t-minpoly.c"
2625
#include "t-mul.c"
2726
#include "t-mul_KS.c"
@@ -34,11 +33,7 @@
3433
#include "t-set_nmod_mat.c"
3534
#include "t-solve.c"
3635
#include "t-solve_tril.c"
37-
#include "t-solve_tril_classical.c"
38-
#include "t-solve_tril_recursive.c"
3936
#include "t-solve_triu.c"
40-
#include "t-solve_triu_classical.c"
41-
#include "t-solve_triu_recursive.c"
4237
#include "t-submul.c"
4338
#include "t-vec_mul.c"
4439
#include "t-window_init_clear.c"
@@ -57,8 +52,7 @@ test_struct tests[] =
5752
TEST_FUNCTION(fq_mat_inv),
5853
TEST_FUNCTION(fq_mat_invert_rows_cols),
5954
TEST_FUNCTION(fq_mat_is_zero),
60-
TEST_FUNCTION(fq_mat_lu_classical),
61-
TEST_FUNCTION(fq_mat_lu_recursive),
55+
TEST_FUNCTION(fq_mat_lu),
6256
TEST_FUNCTION(fq_mat_minpoly),
6357
TEST_FUNCTION(fq_mat_mul),
6458
TEST_FUNCTION(fq_mat_mul_KS),
@@ -71,11 +65,7 @@ test_struct tests[] =
7165
TEST_FUNCTION(fq_mat_set_nmod_mat),
7266
TEST_FUNCTION(fq_mat_solve),
7367
TEST_FUNCTION(fq_mat_solve_tril),
74-
TEST_FUNCTION(fq_mat_solve_tril_classical),
75-
TEST_FUNCTION(fq_mat_solve_tril_recursive),
7668
TEST_FUNCTION(fq_mat_solve_triu),
77-
TEST_FUNCTION(fq_mat_solve_triu_classical),
78-
TEST_FUNCTION(fq_mat_solve_triu_recursive),
7969
TEST_FUNCTION(fq_mat_submul),
8070
TEST_FUNCTION(fq_mat_vec_mul),
8171
TEST_FUNCTION(fq_mat_window_init_clear),

src/fq_mat/test/t-lu_classical.c renamed to src/fq_mat/test/t-lu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
#define T fq
2020
#define CAP_T FQ
21-
#include "fq_mat_templates/test/t-lu_classical.c"
21+
#include "fq_mat_templates/test/t-lu.c"
2222
#undef CAP_T
2323
#undef T

src/fq_mat/test/t-lu_recursive.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/fq_mat/test/t-solve_tril_classical.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)