From 2a39be906dd886e716ae7f8eb03fc3226a56fabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 11:50:17 +0100 Subject: [PATCH 01/13] Use TEST_FUNCTION_FAIL throughout nmod_mat --- src/nmod_mat/test/t-add.c | 6 +- src/nmod_mat/test/t-addmul.c | 36 ++++---- src/nmod_mat/test/t-can_solve.c | 44 ++++------ src/nmod_mat/test/t-charpoly.c | 30 +++---- src/nmod_mat/test/t-charpoly_berkowitz.c | 30 +++---- src/nmod_mat/test/t-charpoly_danilevsky.c | 30 +++---- src/nmod_mat/test/t-concat_horizontal.c | 16 ++-- src/nmod_mat/test/t-concat_vertical.c | 16 ++-- src/nmod_mat/test/t-det.c | 7 +- src/nmod_mat/test/t-det_howell.c | 11 +-- src/nmod_mat/test/t-howell_form.c | 26 +++--- src/nmod_mat/test/t-init_clear.c | 16 +--- src/nmod_mat/test/t-inv.c | 44 +++------- src/nmod_mat/test/t-invert_rows_cols.c | 14 ++-- src/nmod_mat/test/t-lu_classical.c | 56 ++++++------- src/nmod_mat/test/t-lu_classical_delayed.c | 86 ++++++++------------ src/nmod_mat/test/t-lu_recursive.c | 52 +++++------- src/nmod_mat/test/t-minpoly.c | 28 +++---- src/nmod_mat/test/t-mul.c | 34 +++----- src/nmod_mat/test/t-mul_blas.c | 13 +-- src/nmod_mat/test/t-mul_classical_threaded.c | 18 ++-- src/nmod_mat/test/t-mul_nmod_vec.c | 11 +-- src/nmod_mat/test/t-mul_strassen.c | 16 ++-- src/nmod_mat/test/t-neg.c | 12 +-- src/nmod_mat/test/t-nmod_vec_mul.c | 11 +-- src/nmod_mat/test/t-nullspace.c | 36 +++----- src/nmod_mat/test/t-permute_rows.c | 24 ++---- src/nmod_mat/test/t-pow.c | 14 ++-- src/nmod_mat/test/t-rank.c | 16 +--- src/nmod_mat/test/t-rref.c | 26 +++--- src/nmod_mat/test/t-scalar_addmul_ui.c | 15 ++-- src/nmod_mat/test/t-scalar_mul.c | 12 +-- src/nmod_mat/test/t-solve.c | 37 +++------ src/nmod_mat/test/t-solve_tril.c | 34 +++----- src/nmod_mat/test/t-solve_tril_classical.c | 34 +++----- src/nmod_mat/test/t-solve_tril_recursive.c | 34 +++----- src/nmod_mat/test/t-solve_triu.c | 34 +++----- src/nmod_mat/test/t-solve_triu_classical.c | 34 +++----- src/nmod_mat/test/t-solve_triu_recursive.c | 34 +++----- src/nmod_mat/test/t-solve_vec.c | 29 ++----- src/nmod_mat/test/t-submul.c | 36 ++++---- src/nmod_mat/test/t-trace.c | 19 ++--- src/nmod_mat/test/t-transpose.c | 18 +--- 43 files changed, 402 insertions(+), 747 deletions(-) diff --git a/src/nmod_mat/test/t-add.c b/src/nmod_mat/test/t-add.c index 7414ad62e0..7b6d39fcd6 100644 --- a/src/nmod_mat/test/t-add.c +++ b/src/nmod_mat/test/t-add.c @@ -36,11 +36,7 @@ TEST_FUNCTION_START(nmod_mat_add, state) nmod_mat_sub(C, C, B); if (!nmod_mat_equal(C, A)) - { - flint_printf("FAIL\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL(""); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-addmul.c b/src/nmod_mat/test/t-addmul.c index 50cd52c595..ed30addbc4 100644 --- a/src/nmod_mat/test/t-addmul.c +++ b/src/nmod_mat/test/t-addmul.c @@ -52,31 +52,27 @@ TEST_FUNCTION_START(nmod_mat_addmul, state) nmod_mat_add(E, C, T); if (!nmod_mat_equal(D, E)) - { - flint_printf("FAIL: results not equal\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - nmod_mat_print_pretty(E); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n" + "E = %{nmod_mat}\n", + A, B, C, D, E); /* Check aliasing */ nmod_mat_addmul(C, C, A, B); if (!nmod_mat_equal(C, E)) - { - flint_printf("FAIL: results not equal (aliasing)\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - nmod_mat_print_pretty(E); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal (aliasing)\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n" + "E = %{nmod_mat}\n", + A, B, C, D, E); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-can_solve.c b/src/nmod_mat/test/t-can_solve.c index 2188134c05..20af454006 100644 --- a/src/nmod_mat/test/t-can_solve.c +++ b/src/nmod_mat/test/t-can_solve.c @@ -46,21 +46,13 @@ TEST_FUNCTION_START(nmod_mat_can_solve, state) nmod_mat_mul(AX, A, X); if (solved && !nmod_mat_equal(AX, B)) - { - flint_printf("FAIL:\n"); - flint_printf("AX != B!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("AX:\n"); - nmod_mat_print_pretty(AX); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "AX != B\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "AX = %{nmod_mat}\n", + A, B, X, AX); nmod_mat_clear(A); nmod_mat_clear(B); @@ -92,21 +84,13 @@ TEST_FUNCTION_START(nmod_mat_can_solve, state) nmod_mat_mul(AX, A, X); if (!solved || !nmod_mat_equal(B, AX)) - { - flint_printf("FAIL:\n"); - flint_printf("AX != B!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("AX:\n"); - nmod_mat_print_pretty(AX); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "AX != B\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "AX = %{nmod_mat}\n", + A, B, X, AX); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-charpoly.c b/src/nmod_mat/test/t-charpoly.c index f94ac3f151..f572bc641a 100644 --- a/src/nmod_mat/test/t-charpoly.c +++ b/src/nmod_mat/test/t-charpoly.c @@ -46,15 +46,13 @@ TEST_FUNCTION_START(nmod_mat_charpoly, state) nmod_mat_charpoly(g, D); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: charpoly(AB) != charpoly(BA).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("Matrix B:\n"), nmod_mat_print_pretty(B), flint_printf("\n"); - flint_printf("cp(AB) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(BA) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "charpoly(AB) != charpoly(BA)\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "cp(AB) = %{nmod_poly}\n" + "cp(BA) = %{nmod_poly}\n", + A, B, f, g); nmod_mat_clear(A); nmod_mat_clear(B); @@ -88,14 +86,12 @@ TEST_FUNCTION_START(nmod_mat_charpoly, state) nmod_mat_charpoly(g, A); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: charpoly(P^{-1}AP) != charpoly(A).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("cp(A) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(P^{-1}AP) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "charpoly(P^{-1}AP) != charpoly(A)\n" + "A = %{nmod_mat}\n" + "cp(A) = %{nmod_poly}\n" + "cp(P^{-1}AP) = %{nmod_poly}\n", + A, f, g); nmod_mat_clear(A); nmod_poly_clear(f); diff --git a/src/nmod_mat/test/t-charpoly_berkowitz.c b/src/nmod_mat/test/t-charpoly_berkowitz.c index f75b6eb2bd..42aca830b8 100644 --- a/src/nmod_mat/test/t-charpoly_berkowitz.c +++ b/src/nmod_mat/test/t-charpoly_berkowitz.c @@ -46,15 +46,13 @@ TEST_FUNCTION_START(nmod_mat_charpoly_berkowitz, state) nmod_mat_charpoly_berkowitz(g, D); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: charpoly(AB) != charpoly(BA).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("Matrix B:\n"), nmod_mat_print_pretty(B), flint_printf("\n"); - flint_printf("cp(AB) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(BA) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "charpoly(AB) != charpoly(BA)\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "cp(AB) = %{nmod_poly}\n" + "cp(BA) = %{nmod_poly}\n", + A, B, f, g); nmod_mat_clear(A); nmod_mat_clear(B); @@ -88,14 +86,12 @@ TEST_FUNCTION_START(nmod_mat_charpoly_berkowitz, state) nmod_mat_charpoly(g, A); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: charpoly(P^{-1}AP) != charpoly(A).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("cp(A) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(P^{-1}AP) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "charpoly(P^{-1}AP) != charpoly(A)\n" + "A = %{nmod_mat}\n" + "cp(A) = %{nmod_poly}\n" + "cp(P^{-1}AP) = %{nmod_poly}\n", + A, f, g); nmod_mat_clear(A); nmod_poly_clear(f); diff --git a/src/nmod_mat/test/t-charpoly_danilevsky.c b/src/nmod_mat/test/t-charpoly_danilevsky.c index e210a25faa..b45afaf278 100644 --- a/src/nmod_mat/test/t-charpoly_danilevsky.c +++ b/src/nmod_mat/test/t-charpoly_danilevsky.c @@ -47,15 +47,13 @@ TEST_FUNCTION_START(nmod_mat_charpoly_danilevsky, state) nmod_mat_charpoly_danilevsky(g, D); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: charpoly(AB) != charpoly(BA).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("Matrix B:\n"), nmod_mat_print_pretty(B), flint_printf("\n"); - flint_printf("cp(AB) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(BA) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "charpoly(AB) != charpoly(BA)\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "cp(AB) = %{nmod_poly}\n" + "cp(BA) = %{nmod_poly}\n", + A, B, f, g); nmod_mat_clear(A); nmod_mat_clear(B); @@ -89,14 +87,12 @@ TEST_FUNCTION_START(nmod_mat_charpoly_danilevsky, state) nmod_mat_charpoly_danilevsky(g, A); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: charpoly(P^{-1}AP) != charpoly(A).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("cp(A) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(P^{-1}AP) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "charpoly(P^{-1}AP) != charpoly(A)\n" + "A = %{nmod_mat}\n" + "cp(A) = %{nmod_poly}\n" + "cp(P^{-1}AP) = %{nmod_poly}\n", + A, f, g); nmod_mat_clear(A); nmod_poly_clear(f); diff --git a/src/nmod_mat/test/t-concat_horizontal.c b/src/nmod_mat/test/t-concat_horizontal.c index f2da207010..305d28cd59 100644 --- a/src/nmod_mat/test/t-concat_horizontal.c +++ b/src/nmod_mat/test/t-concat_horizontal.c @@ -42,17 +42,11 @@ TEST_FUNCTION_START(nmod_mat_concat_horizontal, state) nmod_mat_window_init(window2, C, 0, c1, r1, c1 + c2); if (!(nmod_mat_equal(window1, A) && nmod_mat_equal(window2, B))) - { - flint_printf("A = \n"); - nmod_mat_print_pretty(A); - flint_printf("B = \n"); - nmod_mat_print_pretty(B); - flint_printf("A concat_horizontal B = \n"); - nmod_mat_print_pretty(C); - flint_printf("FAIL: results not equal\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "A concat_horizontal B = %{nmod_mat}\n", + A, B, C); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-concat_vertical.c b/src/nmod_mat/test/t-concat_vertical.c index 79887337a9..2d2d043083 100644 --- a/src/nmod_mat/test/t-concat_vertical.c +++ b/src/nmod_mat/test/t-concat_vertical.c @@ -42,17 +42,11 @@ TEST_FUNCTION_START(nmod_mat_concat_vertical, state) nmod_mat_window_init(window2, C, r1, 0, (r1+r2), c1); if (!(nmod_mat_equal(window1, A) && nmod_mat_equal(window2, B))) - { - flint_printf("A = \n"); - nmod_mat_print_pretty(A); - flint_printf("B = \n"); - nmod_mat_print_pretty(B); - flint_printf("A concat_vertical B = \n"); - nmod_mat_print_pretty(C); - flint_printf("FAIL: results not equal\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "A concat_vertical B = %{nmod_mat}\n", + A, B, C); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-det.c b/src/nmod_mat/test/t-det.c index 92ce8d9ff0..471f0aac84 100644 --- a/src/nmod_mat/test/t-det.c +++ b/src/nmod_mat/test/t-det.c @@ -58,12 +58,7 @@ TEST_FUNCTION_START(nmod_mat_det, state) fmpz_mod_ui(Bdet, Bdet, mod); if (Adet != fmpz_get_ui(Bdet)) - { - flint_printf("FAIL\n"); - flint_printf("Adet = %wu, Bdet = %wu\n", Adet, fmpz_get_ui(Bdet)); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("Adet = %wu, Bdet = %wu\n", Adet, fmpz_get_ui(Bdet)); nmod_mat_clear(A); fmpz_mat_clear(B); diff --git a/src/nmod_mat/test/t-det_howell.c b/src/nmod_mat/test/t-det_howell.c index 8ee65917a6..d7b4224efa 100644 --- a/src/nmod_mat/test/t-det_howell.c +++ b/src/nmod_mat/test/t-det_howell.c @@ -26,9 +26,9 @@ TEST_FUNCTION_START(nmod_mat_det_howell, state) fmpz_t Bdet; ulong t; - m = n_randint(state, 30); + m = n_randint(state, 30); mod = n_randtest(state); - mod += mod == 0; + mod += mod == 0; nmod_mat_init(A, m, m, mod); fmpz_mat_init(B, m, m); @@ -58,12 +58,7 @@ TEST_FUNCTION_START(nmod_mat_det_howell, state) fmpz_mod_ui(Bdet, Bdet, mod); if (Adet != fmpz_get_ui(Bdet)) - { - flint_printf("FAIL\n"); - flint_printf("Adet = %wu, Bdet = %wu\n", Adet, fmpz_get_ui(Bdet)); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("Adet = %wu, Bdet = %wu\n", Adet, fmpz_get_ui(Bdet)); nmod_mat_clear(A); fmpz_mat_clear(B); diff --git a/src/nmod_mat/test/t-howell_form.c b/src/nmod_mat/test/t-howell_form.c index 086897f20b..f3c717b3cf 100644 --- a/src/nmod_mat/test/t-howell_form.c +++ b/src/nmod_mat/test/t-howell_form.c @@ -172,13 +172,11 @@ TEST_FUNCTION_START(nmod_mat_howell_form, state) r1 = nmod_mat_howell_form(B); if (!nmod_mat_is_in_howell_form(B)) - { - flint_printf("FAIL (malformed Howell form)\n"); - nmod_mat_print_pretty(A); flint_printf("\n\n"); - nmod_mat_print_pretty(B); flint_printf("\n\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Malformed Howell form\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); _perm_randtest(perm, 2 * m, state); @@ -217,14 +215,12 @@ TEST_FUNCTION_START(nmod_mat_howell_form, state) } if (!equal) - { - flint_printf("FAIL (r1 = %wd, r2 = %wd)!\n", r1, r2); - nmod_mat_print_pretty(A); flint_printf("\n\n"); - nmod_mat_print_pretty(B); flint_printf("\n\n"); - nmod_mat_print_pretty(D); flint_printf("\n\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "r1 = %wd, r2 = %wd\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "D = %{nmod_mat}\n", + r1, r2, A, B, D); _perm_clear(perm); diff --git a/src/nmod_mat/test/t-init_clear.c b/src/nmod_mat/test/t-init_clear.c index db8a937ab8..2998d2d2c1 100644 --- a/src/nmod_mat/test/t-init_clear.c +++ b/src/nmod_mat/test/t-init_clear.c @@ -27,24 +27,12 @@ TEST_FUNCTION_START(nmod_mat_init_clear, state) nmod_mat_init(A, m, n, mod); for (i = 0; i < m; i++) - { for (j = 0; j < n; j++) - { if (A->rows[i][j] != UWORD(0)) - { - flint_printf("FAIL: entries not zero!\n"); - fflush(stdout); - flint_abort(); - } - } - } + TEST_FUNCTION_FAIL("entries not zero\n"); if (A->mod.n != mod) - { - flint_printf("FAIL: bad modulus\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("bad modulus\n"); nmod_mat_clear(A); } diff --git a/src/nmod_mat/test/t-inv.c b/src/nmod_mat/test/t-inv.c index de2d67b0a1..9fbe3fce8c 100644 --- a/src/nmod_mat/test/t-inv.c +++ b/src/nmod_mat/test/t-inv.c @@ -44,19 +44,12 @@ TEST_FUNCTION_START(nmod_mat_inv, state) nmod_mat_mul(C, A, B); if (!nmod_mat_equal(C, I) || !result) - { - flint_printf("FAIL:\n"); - flint_printf("A * A^-1 != I!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("A^-1:\n"); - nmod_mat_print_pretty(B); - flint_printf("A * A^-1:\n"); - nmod_mat_print_pretty(C); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A * A^-1 != I\n" + "A = %{nmod_mat}\n" + "A^-1 = %{nmod_mat}\n" + "A * A^-1 = %{nmod_mat}\n", + A, B, C); /* Test aliasing */ nmod_mat_set(C, A); @@ -64,13 +57,10 @@ TEST_FUNCTION_START(nmod_mat_inv, state) nmod_mat_mul(B, A, C); if (!nmod_mat_equal(B, I)) - { - flint_printf("FAIL:\n"); - flint_printf("aliasing failed!\n"); - nmod_mat_print_pretty(C); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing failed\n" + "A = %{nmod_mat}\n", + C); nmod_mat_clear(A); nmod_mat_clear(B); @@ -97,22 +87,12 @@ TEST_FUNCTION_START(nmod_mat_inv, state) result = nmod_mat_inv(B, A); if (result) - { - flint_printf("FAIL:\n"); - flint_printf("singular matrix reported as invertible\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("singular matrix reported as invertible\n"); /* Aliasing */ result = nmod_mat_inv(A, A); if (result) - { - flint_printf("FAIL:\n"); - flint_printf("singular matrix reported as invertible\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("singular matrix reported as invertible\n"); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-invert_rows_cols.c b/src/nmod_mat/test/t-invert_rows_cols.c index 880cd7194f..438e3a065f 100644 --- a/src/nmod_mat/test/t-invert_rows_cols.c +++ b/src/nmod_mat/test/t-invert_rows_cols.c @@ -41,15 +41,11 @@ TEST_FUNCTION_START(nmod_mat_invert_rows_cols, state) for (j =0; j < A->c; j++) { if (nmod_mat_entry(B, i, j) != nmod_mat_entry(A, A->r - i - 1, A->c - j - 1)) - { - flint_printf("FAIL: B != A\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "B != A\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); } } diff --git a/src/nmod_mat/test/t-lu_classical.c b/src/nmod_mat/test/t-lu_classical.c index 1bfe3f2230..872a271b2d 100644 --- a/src/nmod_mat/test/t-lu_classical.c +++ b/src/nmod_mat/test/t-lu_classical.c @@ -36,7 +36,7 @@ void perm(nmod_mat_t A, slong * P) /* Defined in t-lu_classical.c, t-lu_classical_delayed.c and t-lu_recursive.c */ #ifndef check #define check check -void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) +int check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) { nmod_mat_t B, L, U; slong m, n, i, j; @@ -51,17 +51,9 @@ void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) rank = FLINT_ABS(rank); for (i = rank; i < FLINT_MIN(m, n); i++) - { for (j = i; j < n; j++) - { if (nmod_mat_entry(LU, i, j) != 0) - { - flint_printf("FAIL: wrong shape!\n"); - fflush(stdout); - flint_abort(); - } - } - } + return 1; for (i = 0; i < m; i++) { @@ -77,27 +69,20 @@ void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) perm(B, P); if (!nmod_mat_equal(A, B)) - { - flint_printf("FAIL\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("LU:\n"); - nmod_mat_print_pretty(LU); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + return 2; nmod_mat_clear(B); nmod_mat_clear(L); nmod_mat_clear(U); + + return 0; } #endif TEST_FUNCTION_START(nmod_mat_lu_classical, state) { slong i; + int result; for (i = 0; i < 1000 * flint_test_multiplier(); i++) { @@ -126,20 +111,27 @@ TEST_FUNCTION_START(nmod_mat_lu_classical, state) rank = nmod_mat_lu_classical(P, LU, 0); - if (r != rank) + result = (r == rank); + + if (!result) + TEST_FUNCTION_FAIL( + "Wrong rank\n" + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n", + A, LU); + + result = check(P, LU, A, rank); + if (result != 0) { - flint_printf("FAIL:\n"); - flint_printf("wrong rank!\n"); - flint_printf("A:"); - nmod_mat_print_pretty(A); - flint_printf("LU:"); - nmod_mat_print_pretty(LU); - fflush(stdout); - flint_abort(); + if (result == 1) + TEST_FUNCTION_FAIL("Wrong shape\n"); + else if (result == 2) + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n", + A, LU); } - check(P, LU, A, rank); - nmod_mat_clear(A); nmod_mat_clear(LU); flint_free(P); diff --git a/src/nmod_mat/test/t-lu_classical_delayed.c b/src/nmod_mat/test/t-lu_classical_delayed.c index e12e9a0257..6c16878038 100644 --- a/src/nmod_mat/test/t-lu_classical_delayed.c +++ b/src/nmod_mat/test/t-lu_classical_delayed.c @@ -37,7 +37,7 @@ void perm(nmod_mat_t A, slong * P) /* Defined in t-lu_classical.c, t-lu_classical_delayed.c and t-lu_recursive.c */ #ifndef check #define check check -void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) +int check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) { nmod_mat_t B, L, U; slong m, n, i, j; @@ -52,17 +52,9 @@ void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) rank = FLINT_ABS(rank); for (i = rank; i < FLINT_MIN(m, n); i++) - { for (j = i; j < n; j++) - { if (nmod_mat_entry(LU, i, j) != 0) - { - flint_printf("FAIL: wrong shape!\n"); - fflush(stdout); - flint_abort(); - } - } - } + return 1; for (i = 0; i < m; i++) { @@ -78,27 +70,20 @@ void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) perm(B, P); if (!nmod_mat_equal(A, B)) - { - flint_printf("FAIL\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("LU:\n"); - nmod_mat_print_pretty(LU); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + return 2; nmod_mat_clear(B); nmod_mat_clear(L); nmod_mat_clear(U); + + return 0; } #endif TEST_FUNCTION_START(nmod_mat_lu_classical_delayed, state) { slong i; + int result; for (i = 0; i < 1000 * flint_test_multiplier(); i++) { @@ -128,35 +113,34 @@ TEST_FUNCTION_START(nmod_mat_lu_classical_delayed, state) rank = nmod_mat_lu_classical_delayed(P, LU, 0); if (r != rank) + TEST_FUNCTION_FAIL( + "Wrong rank\n" + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n", + A, LU); + + result = check(P, LU, A, rank); + if (result != 0) { - flint_printf("FAIL:\n"); - flint_printf("wrong rank!\n"); - flint_printf("A:"); - nmod_mat_print_pretty(A); - flint_printf("LU:"); - nmod_mat_print_pretty(LU); - fflush(stdout); - flint_abort(); + if (result == 1) + TEST_FUNCTION_FAIL("Wrong shape\n"); + else if (result == 2) + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n", + A, LU); } - check(P, LU, A, rank); - nmod_mat_init_set(LU2, A); P2 = flint_malloc(sizeof(slong) * m); rank2 = nmod_mat_lu_classical(P2, LU2, 0); if (r != rank || !nmod_mat_equal(LU, LU2) || !_perm_equal(P, P2, m)) - { - flint_printf("FAIL (2):\n"); - flint_printf("A:"); - nmod_mat_print_pretty(A); - flint_printf("LU:"); - nmod_mat_print_pretty(LU); - flint_printf("LU2:"); - nmod_mat_print_pretty(LU2); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n" + "LU2 = %{nmod_mat}\n", + A, LU, LU2); nmod_mat_set(LU, A); rank = nmod_mat_lu_classical_delayed(P, LU, 1); @@ -164,18 +148,12 @@ TEST_FUNCTION_START(nmod_mat_lu_classical_delayed, state) rank2 = nmod_mat_lu_classical(P2, LU2, 1); if (rank != rank2 || (rank == r && (!nmod_mat_equal(LU, LU2) || !_perm_equal(P, P2, m)))) - { - flint_printf("FAIL (3):\n"); - flint_printf("A:"); - nmod_mat_print_pretty(A); - flint_printf("r = %wd, rank = %wd, rank2 = %wd\n", r, rank, rank2); - flint_printf("LU:"); - nmod_mat_print_pretty(LU); - flint_printf("LU2:"); - nmod_mat_print_pretty(LU2); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "r = %wd, rank = %wd, rank2 = %wd\n" + "LU = %{nmod_mat}\n" + "LU2 = %{nmod_mat}\n", + A, r, rank, rank2, LU, LU2); nmod_mat_clear(A); nmod_mat_clear(LU); diff --git a/src/nmod_mat/test/t-lu_recursive.c b/src/nmod_mat/test/t-lu_recursive.c index baddeb00dc..348c740d03 100644 --- a/src/nmod_mat/test/t-lu_recursive.c +++ b/src/nmod_mat/test/t-lu_recursive.c @@ -36,7 +36,7 @@ void perm(nmod_mat_t A, slong * P) /* Defined in t-lu_classical.c, t-lu_classical_delayed.c and t-lu_recursive.c */ #ifndef check #define check check -void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) +int check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) { nmod_mat_t B, L, U; slong m, n, i, j; @@ -51,17 +51,9 @@ void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) rank = FLINT_ABS(rank); for (i = rank; i < FLINT_MIN(m, n); i++) - { for (j = i; j < n; j++) - { if (nmod_mat_entry(LU, i, j) != 0) - { - flint_printf("FAIL: wrong shape!\n"); - fflush(stdout); - flint_abort(); - } - } - } + return 1; for (i = 0; i < m; i++) { @@ -77,27 +69,20 @@ void check(slong * P, nmod_mat_t LU, const nmod_mat_t A, slong rank) perm(B, P); if (!nmod_mat_equal(A, B)) - { - flint_printf("FAIL\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("LU:\n"); - nmod_mat_print_pretty(LU); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + return 2; nmod_mat_clear(B); nmod_mat_clear(L); nmod_mat_clear(U); + + return 0; } #endif TEST_FUNCTION_START(nmod_mat_lu_recursive, state) { slong i; + int result; for (i = 0; i < 2000 * flint_test_multiplier(); i++) { @@ -127,19 +112,24 @@ TEST_FUNCTION_START(nmod_mat_lu_recursive, state) rank = nmod_mat_lu_recursive(P, LU, 0); if (r != rank) + TEST_FUNCTION_FAIL( + "Wrong rank\n" + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n", + A, LU); + + result = check(P, LU, A, rank); + if (result != 0) { - flint_printf("FAIL:\n"); - flint_printf("wrong rank!\n"); - flint_printf("A:"); - nmod_mat_print_pretty(A); - flint_printf("LU:"); - nmod_mat_print_pretty(LU); - fflush(stdout); - flint_abort(); + if (result == 1) + TEST_FUNCTION_FAIL("Wrong shape\n"); + else if (result == 2) + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "LU = %{nmod_mat}\n", + A, LU); } - check(P, LU, A, rank); - nmod_mat_clear(A); nmod_mat_clear(LU); flint_free(P); diff --git a/src/nmod_mat/test/t-minpoly.c b/src/nmod_mat/test/t-minpoly.c index fa0867b546..dd4ec40e7f 100644 --- a/src/nmod_mat/test/t-minpoly.c +++ b/src/nmod_mat/test/t-minpoly.c @@ -45,14 +45,12 @@ TEST_FUNCTION_START(nmod_mat_minpoly, state) nmod_poly_divrem(q, r, g, f); if (!nmod_poly_is_zero(r)) - { - flint_printf("FAIL: minpoly(A) does not divide charpoly(BA).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("mp(A) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("cp(A) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "minpoly(A) does not divide charpoly(BA)\n" + "A = %{nmod_mat}\n" + "mp(A) = %{nmod_poly}\n" + "cp(A) = %{nmod_poly}\n", + A, f, g); nmod_mat_clear(A); nmod_poly_clear(f); @@ -95,14 +93,12 @@ TEST_FUNCTION_START(nmod_mat_minpoly, state) nmod_mat_minpoly(g, A); if (!nmod_poly_equal(f, g)) - { - flint_printf("FAIL: minpoly(P^{-1}AP) != minpoly(A).\n"); - flint_printf("Matrix A:\n"), nmod_mat_print_pretty(A), flint_printf("\n"); - flint_printf("mp(A) = "), nmod_poly_print_pretty(f, "X"), flint_printf("\n"); - flint_printf("mp(P^{-1}AP) = "), nmod_poly_print_pretty(g, "X"), flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "minpoly(P^{-1}AP) != minpoly(A)\n" + "A = %{nmod_mat}\n" + "mp(A) = %{nmod_poly}\n" + "mp(P^{-1}AP) = %{nmod_poly}\n", + A, f, g); nmod_mat_clear(A); nmod_poly_clear(f); diff --git a/src/nmod_mat/test/t-mul.c b/src/nmod_mat/test/t-mul.c index 94058ddc6a..ad309a2b09 100644 --- a/src/nmod_mat/test/t-mul.c +++ b/src/nmod_mat/test/t-mul.c @@ -97,26 +97,20 @@ TEST_FUNCTION_START(nmod_mat_mul, state) nmod_mat_mul_check(D, A, B); if (!nmod_mat_equal(C, D)) - { - flint_printf("FAIL: results not equal\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n", + A, B, C, D); if (n == k) { nmod_mat_mul(A, A, B); if (!nmod_mat_equal(A, C)) - { - flint_printf("FAIL: aliasing failed\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("Aliasing failed\n"); } nmod_mat_clear(A); @@ -142,13 +136,11 @@ TEST_FUNCTION_START(nmod_mat_mul, state) nmod_mat_mul(A_window, B, A_window); if (!nmod_mat_equal(A, B)) - { - flint_printf("FAIL: window aliasing failed\n"); - nmod_mat_print_pretty(A); flint_printf("\n\n"); - nmod_mat_print_pretty(B); flint_printf("\n\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Window aliasing failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_window_clear(A_window); nmod_mat_clear(A); diff --git a/src/nmod_mat/test/t-mul_blas.c b/src/nmod_mat/test/t-mul_blas.c index 8b96779b3f..0e1c183adf 100644 --- a/src/nmod_mat/test/t-mul_blas.c +++ b/src/nmod_mat/test/t-mul_blas.c @@ -82,20 +82,11 @@ TEST_FUNCTION_START(nmod_mat_mul_blas, state) nmod_mat_mul_classical(D, A, B); if (!nmod_mat_equal(C, D)) - { - flint_printf("FAIL: results not equal\n"); - flint_printf("m: %wd, k: %wd, n: %wd, mod: %wu\n", m, k, n, modulus); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("m: %wd, k: %wd, n: %wd, mod: %wu\n", m, k, n, modulus); } #if FLINT_USES_BLAS && FLINT_BITS == 64 else - { - flint_printf("FAIL: blas should have worked\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("BLAS should have worked\n"); #endif nmod_mat_clear(A); diff --git a/src/nmod_mat/test/t-mul_classical_threaded.c b/src/nmod_mat/test/t-mul_classical_threaded.c index 1f843cc159..7fa9248318 100644 --- a/src/nmod_mat/test/t-mul_classical_threaded.c +++ b/src/nmod_mat/test/t-mul_classical_threaded.c @@ -61,7 +61,7 @@ TEST_FUNCTION_START(nmod_mat_mul_classical_threaded, state) slong m, k, n; - flint_set_num_threads(n_randint(state, max_threads) + 1); + flint_set_num_threads(n_randint(state, max_threads) + 1); m = n_randint(state, 50); k = n_randint(state, 50); @@ -104,15 +104,13 @@ TEST_FUNCTION_START(nmod_mat_mul_classical_threaded, state) nmod_mat_mul_check(D, A, B); if (!nmod_mat_equal(C, D)) - { - flint_printf("FAIL: results not equal\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n", + A, B, C, D); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-mul_nmod_vec.c b/src/nmod_mat/test/t-mul_nmod_vec.c index 290475edd3..a3f6344892 100644 --- a/src/nmod_mat/test/t-mul_nmod_vec.c +++ b/src/nmod_mat/test/t-mul_nmod_vec.c @@ -64,15 +64,8 @@ TEST_FUNCTION_START(nmod_mat_mul_nmod_vec, state) nmod_mat_mul(C, A, B); for (j = 0; j < m; j++) - { - if (nmod_mat_entry(C, j, 0) != c[j] || - nmod_mat_entry(C, j, 0) != cc[j][0]) - { - flint_printf("FAIL: wrong answer\n"); - fflush(stdout); - flint_abort(); - } - } + if (nmod_mat_entry(C, j, 0) != c[j] || nmod_mat_entry(C, j, 0) != cc[j][0]) + TEST_FUNCTION_FAIL(""); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-mul_strassen.c b/src/nmod_mat/test/t-mul_strassen.c index daf8b25ce3..fc2db89958 100644 --- a/src/nmod_mat/test/t-mul_strassen.c +++ b/src/nmod_mat/test/t-mul_strassen.c @@ -39,15 +39,13 @@ TEST_FUNCTION_START(nmod_mat_mul_strassen, state) nmod_mat_mul_strassen(D, A, B); if (!nmod_mat_equal(C, D)) - { - flint_printf("FAIL: results not equal\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n", + A, B, C, D); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-neg.c b/src/nmod_mat/test/t-neg.c index c9060c5a42..6b3bff1cee 100644 --- a/src/nmod_mat/test/t-neg.c +++ b/src/nmod_mat/test/t-neg.c @@ -38,21 +38,13 @@ TEST_FUNCTION_START(nmod_mat_neg, state) nmod_mat_add(D, A, B); if (!nmod_mat_equal(C, D)) - { - flint_printf("FAIL\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL(""); nmod_mat_neg(C, B); nmod_mat_neg(B, B); if (!nmod_mat_equal(C, B)) - { - flint_printf("FAIL\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL(""); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-nmod_vec_mul.c b/src/nmod_mat/test/t-nmod_vec_mul.c index b4e135e931..ad1044e71d 100644 --- a/src/nmod_mat/test/t-nmod_vec_mul.c +++ b/src/nmod_mat/test/t-nmod_vec_mul.c @@ -64,15 +64,8 @@ TEST_FUNCTION_START(nmod_mat_nmod_vec_mul, state) nmod_mat_mul(C, A, B); for (j = 0; j < n; j++) - { - if (nmod_mat_entry(C, 0, j) != c[j] || - nmod_mat_entry(C, 0, j) != cc[j][0]) - { - flint_printf("FAIL: wrong answer\n"); - fflush(stdout); - flint_abort(); - } - } + if (nmod_mat_entry(C, 0, j) != c[j] || nmod_mat_entry(C, 0, j) != cc[j][0]) + TEST_FUNCTION_FAIL(""); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-nullspace.c b/src/nmod_mat/test/t-nullspace.c index 7acc20a48f..513b5c51df 100644 --- a/src/nmod_mat/test/t-nullspace.c +++ b/src/nmod_mat/test/t-nullspace.c @@ -44,36 +44,24 @@ TEST_FUNCTION_START(nmod_mat_nullspace, state) nulrank = nmod_mat_rank(ker); if (nullity != nulrank) - { - flint_printf("FAIL:\n"); - flint_printf("rank(ker) != nullity!\n"); - nmod_mat_print_pretty(A); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "rank(ker) != nullity\n" + "A = %{nmod_mat}\n", + A); if (nullity + r != n) - { - flint_printf("FAIL:\n"); - flint_printf("nullity + rank != n\n"); - nmod_mat_print_pretty(A); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "nullity + rank != n\n" + "A = %{nmod_mat}\n", + A); nmod_mat_mul(B, A, ker); if (nmod_mat_rank(B) != 0) - { - flint_printf("FAIL:\n"); - flint_printf("A * ker != 0\n"); - nmod_mat_print_pretty(A); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A * ker != 0\n" + "A = %{nmod_mat}\n", + A); nmod_mat_clear(A); nmod_mat_clear(ker); diff --git a/src/nmod_mat/test/t-permute_rows.c b/src/nmod_mat/test/t-permute_rows.c index 1ae5d6027c..ac001d42f6 100644 --- a/src/nmod_mat/test/t-permute_rows.c +++ b/src/nmod_mat/test/t-permute_rows.c @@ -47,30 +47,22 @@ TEST_FUNCTION_START(nmod_mat_permute_rows, state) for (i = 0; i < m; i++) { if (perm_store && perm_store[i] != perm[perm_act[i]]) - { - flint_throw(FLINT_TEST_FAIL, + TEST_FUNCTION_FAIL( "auxiliary permutation not correctly permuted by perm_act\n" "m = %wd\n" "input permutation: %{slong*}\n" "acting permutation: %{slong*}\n" "resulting permutation: %{slong*}\n", - m, - perm, m, - perm_act, m, - perm_store, m); - } + m, perm, m, perm_act, m, perm_store, m); + for (j = 0; j < n; j++) { if (nmod_mat_entry(matt, i, j) != nmod_mat_entry(mat, perm_act[i], j)) - { - flint_printf("FAIL: matrix not correctly row-permuted by perm_act\n"); - flint_printf("first matrix:\n"); - nmod_mat_print_pretty(mat); - flint_printf("second matrix:\n"); - nmod_mat_print_pretty(matt); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "matrix not correctly row-permuted by perm_act\n" + "first matrix = %{nmod_mat}\n" + "second matrix = %{nmod_mat}\n", + mat, matt); } } diff --git a/src/nmod_mat/test/t-pow.c b/src/nmod_mat/test/t-pow.c index 9f66e1f5d7..c148ee4b36 100644 --- a/src/nmod_mat/test/t-pow.c +++ b/src/nmod_mat/test/t-pow.c @@ -43,14 +43,12 @@ TEST_FUNCTION_START(nmod_mat_pow, state) nmod_mat_pow(A, A, exp); if (!(nmod_mat_equal(C, B) && nmod_mat_equal(C, A))) - { - flint_printf("FAIL: results not equal\n");fflush(stdout); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n", + A, B, C); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-rank.c b/src/nmod_mat/test/t-rank.c index ae5c5f803b..64b1e49076 100644 --- a/src/nmod_mat/test/t-rank.c +++ b/src/nmod_mat/test/t-rank.c @@ -33,12 +33,8 @@ TEST_FUNCTION_START(nmod_mat_rank, state) /* flint_printf("SPARSE %wd\n", r); nmod_mat_print_pretty(A); */ if (r != nmod_mat_rank(A)) - { - flint_printf("FAIL:\n"); - flint_printf("wrong rank!\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("Wrong rank\n"); + nmod_mat_clear(A); } } @@ -60,12 +56,8 @@ TEST_FUNCTION_START(nmod_mat_rank, state) flint_printf("DENSE %wd %wd\n", r, d); nmod_mat_print_pretty(A); */ if (r != nmod_mat_rank(A)) - { - flint_printf("FAIL:\n"); - flint_printf("wrong rank!\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("Wrong rank\n"); + nmod_mat_clear(A); } } diff --git a/src/nmod_mat/test/t-rref.c b/src/nmod_mat/test/t-rref.c index b1354a8edb..68e9caa46e 100644 --- a/src/nmod_mat/test/t-rref.c +++ b/src/nmod_mat/test/t-rref.c @@ -79,13 +79,11 @@ TEST_FUNCTION_START(nmod_mat_rref, state) rank1 = nmod_mat_rref(B); if (!check_rref_form(perm, B, rank1)) - { - flint_printf("FAIL (malformed rref)\n"); - nmod_mat_print_pretty(A); flint_printf("\n\n"); - nmod_mat_print_pretty(B); flint_printf("\n\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Malformed rref\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); /* Concatenate the original matrix with the rref, scramble the rows, and check that the rref is the same */ @@ -122,14 +120,12 @@ TEST_FUNCTION_START(nmod_mat_rref, state) } if (!equal) - { - flint_printf("FAIL (rank1 = %wd, rank2 = %wd)!\n", rank1, rank2); - nmod_mat_print_pretty(A); flint_printf("\n\n"); - nmod_mat_print_pretty(B); flint_printf("\n\n"); - nmod_mat_print_pretty(D); flint_printf("\n\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "rank1 = %wd, rank2 = %wd\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "D = %{nmod_mat}\n", + rank1, rank2, A, B, D); _perm_clear(perm); nmod_mat_clear(A); diff --git a/src/nmod_mat/test/t-scalar_addmul_ui.c b/src/nmod_mat/test/t-scalar_addmul_ui.c index a7e0f49c1e..db6e1e423e 100644 --- a/src/nmod_mat/test/t-scalar_addmul_ui.c +++ b/src/nmod_mat/test/t-scalar_addmul_ui.c @@ -39,15 +39,12 @@ TEST_FUNCTION_START(nmod_mat_scalar_addmul_ui, state) nmod_mat_scalar_addmul_ui(D, B, A, x); if (!nmod_mat_equal(C, D)) - { - flint_printf("FAIL\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n", + A, B, C, D); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-scalar_mul.c b/src/nmod_mat/test/t-scalar_mul.c index 5f8f3072a1..38fb13db9e 100644 --- a/src/nmod_mat/test/t-scalar_mul.c +++ b/src/nmod_mat/test/t-scalar_mul.c @@ -43,22 +43,14 @@ TEST_FUNCTION_START(nmod_mat_scalar_mul, state) nmod_mat_sub(D, C, D); if (!nmod_mat_equal(A, D)) - { - flint_printf("FAIL\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL(""); /* Aliasing */ nmod_mat_scalar_mul(C, A, c); nmod_mat_scalar_mul(A, A, c); if (!nmod_mat_equal(A, C)) - { - flint_printf("FAIL\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL(""); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve.c b/src/nmod_mat/test/t-solve.c index c0c3b7f3fd..8932944394 100644 --- a/src/nmod_mat/test/t-solve.c +++ b/src/nmod_mat/test/t-solve.c @@ -43,21 +43,13 @@ TEST_FUNCTION_START(nmod_mat_solve, state) nmod_mat_mul(AX, A, X); if (!nmod_mat_equal(AX, B) || !solved) - { - flint_printf("FAIL:\n"); - flint_printf("AX != B!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("AX:\n"); - nmod_mat_print_pretty(AX); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "AX != B\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "AX = %{nmod_mat}\n", + A, B, X, AX); nmod_mat_clear(A); nmod_mat_clear(B); @@ -88,15 +80,12 @@ TEST_FUNCTION_START(nmod_mat_solve, state) solved = nmod_mat_solve(X, A, B); if (solved) - { - flint_printf("FAIL:\n"); - flint_printf("singular system was 'solved'\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(X); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "singular system was 'solved'\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "X = %{nmod_mat}\n", + A, B, X); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_tril.c b/src/nmod_mat/test/t-solve_tril.c index 5c761e0248..98ec7545f3 100644 --- a/src/nmod_mat/test/t-solve_tril.c +++ b/src/nmod_mat/test/t-solve_tril.c @@ -41,33 +41,21 @@ TEST_FUNCTION_START(nmod_mat_solve_tril, state) /* Check Y = A^(-1) * (A * X) = X */ nmod_mat_solve_tril(Y, A, B, unit); if (!nmod_mat_equal(Y, X)) - { - flint_printf("FAIL!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("Y:\n"); - nmod_mat_print_pretty(Y); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "Y = %{nmod_mat}\n", + A, X, B, Y); /* Check aliasing */ nmod_mat_solve_tril(B, A, B, unit); if (!nmod_mat_equal(B, X)) - { - flint_printf("FAIL!\n"); - flint_printf("aliasing test failed"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing test failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_tril_classical.c b/src/nmod_mat/test/t-solve_tril_classical.c index bae849b02b..febcf94b1a 100644 --- a/src/nmod_mat/test/t-solve_tril_classical.c +++ b/src/nmod_mat/test/t-solve_tril_classical.c @@ -41,33 +41,21 @@ TEST_FUNCTION_START(nmod_mat_solve_tril_classical, state) /* Check Y = A^(-1) * (A * X) = X */ nmod_mat_solve_tril_classical(Y, A, B, unit); if (!nmod_mat_equal(Y, X)) - { - flint_printf("FAIL!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("Y:\n"); - nmod_mat_print_pretty(Y); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "Y = %{nmod_mat}\n", + A, X, B, Y); /* Check aliasing */ nmod_mat_solve_tril_classical(B, A, B, unit); if (!nmod_mat_equal(B, X)) - { - flint_printf("FAIL!\n"); - flint_printf("aliasing test failed"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing test failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_tril_recursive.c b/src/nmod_mat/test/t-solve_tril_recursive.c index 5e94685a7d..89cf22f313 100644 --- a/src/nmod_mat/test/t-solve_tril_recursive.c +++ b/src/nmod_mat/test/t-solve_tril_recursive.c @@ -41,33 +41,21 @@ TEST_FUNCTION_START(nmod_mat_solve_tril_recursive, state) /* Check Y = A^(-1) * (A * X) = X */ nmod_mat_solve_tril_recursive(Y, A, B, unit); if (!nmod_mat_equal(Y, X)) - { - flint_printf("FAIL!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("Y:\n"); - nmod_mat_print_pretty(Y); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "Y = %{nmod_mat}\n", + A, X, B, Y); /* Check aliasing */ nmod_mat_solve_tril_recursive(B, A, B, unit); if (!nmod_mat_equal(B, X)) - { - flint_printf("FAIL!\n"); - flint_printf("aliasing test failed"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing test failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_triu.c b/src/nmod_mat/test/t-solve_triu.c index 55a87dcd78..8bd39f8b28 100644 --- a/src/nmod_mat/test/t-solve_triu.c +++ b/src/nmod_mat/test/t-solve_triu.c @@ -41,33 +41,21 @@ TEST_FUNCTION_START(nmod_mat_solve_triu, state) /* Check Y = A^(-1) * (A * X) = X */ nmod_mat_solve_triu(Y, A, B, unit); if (!nmod_mat_equal(Y, X)) - { - flint_printf("FAIL!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("Y:\n"); - nmod_mat_print_pretty(Y); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "Y = %{nmod_mat}\n", + A, X, B, Y); /* Check aliasing */ nmod_mat_solve_triu(B, A, B, unit); if (!nmod_mat_equal(B, X)) - { - flint_printf("FAIL!\n"); - flint_printf("aliasing test failed"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing test failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_triu_classical.c b/src/nmod_mat/test/t-solve_triu_classical.c index 596e5ac578..8f280ea4fa 100644 --- a/src/nmod_mat/test/t-solve_triu_classical.c +++ b/src/nmod_mat/test/t-solve_triu_classical.c @@ -41,33 +41,21 @@ TEST_FUNCTION_START(nmod_mat_solve_triu_classical, state) /* Check Y = A^(-1) * (A * X) = X */ nmod_mat_solve_triu_classical(Y, A, B, unit); if (!nmod_mat_equal(Y, X)) - { - flint_printf("FAIL!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("Y:\n"); - nmod_mat_print_pretty(Y); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "Y = %{nmod_mat}\n", + A, X, B, Y); /* Check aliasing */ nmod_mat_solve_triu_classical(B, A, B, unit); if (!nmod_mat_equal(B, X)) - { - flint_printf("FAIL!\n"); - flint_printf("aliasing test failed"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing test failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_triu_recursive.c b/src/nmod_mat/test/t-solve_triu_recursive.c index a3dbcd4d89..068025d935 100644 --- a/src/nmod_mat/test/t-solve_triu_recursive.c +++ b/src/nmod_mat/test/t-solve_triu_recursive.c @@ -41,33 +41,21 @@ TEST_FUNCTION_START(nmod_mat_solve_triu_recursive, state) /* Check Y = A^(-1) * (A * X) = X */ nmod_mat_solve_triu_recursive(Y, A, B, unit); if (!nmod_mat_equal(Y, X)) - { - flint_printf("FAIL!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("X:\n"); - nmod_mat_print_pretty(X); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - flint_printf("Y:\n"); - nmod_mat_print_pretty(Y); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "X = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "Y = %{nmod_mat}\n", + A, X, B, Y); /* Check aliasing */ nmod_mat_solve_triu_recursive(B, A, B, unit); if (!nmod_mat_equal(B, X)) - { - flint_printf("FAIL!\n"); - flint_printf("aliasing test failed"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("B:\n"); - nmod_mat_print_pretty(B); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Aliasing test failed\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n", + A, B); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-solve_vec.c b/src/nmod_mat/test/t-solve_vec.c index ed51bd6a0f..cccba50cc0 100644 --- a/src/nmod_mat/test/t-solve_vec.c +++ b/src/nmod_mat/test/t-solve_vec.c @@ -41,21 +41,13 @@ TEST_FUNCTION_START(nmod_mat_solve_vec, state) nmod_mat_mul(Ax, A, x); if (!nmod_mat_equal(Ax, b) || !solved) - { - flint_printf("FAIL:\n"); - flint_printf("Ax != b!\n"); - flint_printf("A:\n"); - nmod_mat_print_pretty(A); - flint_printf("b:\n"); - nmod_mat_print_pretty(b); - flint_printf("x:\n"); - nmod_mat_print_pretty(x); - flint_printf("Ax:\n"); - nmod_mat_print_pretty(Ax); - flint_printf("\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Ax != b\n" + "A = %{nmod_mat}\n" + "b = %{nmod_mat}\n" + "x = %{nmod_mat}\n" + "Ax = %{nmod_mat}\n", + A, b, x, Ax); nmod_mat_clear(A); nmod_mat_clear(b); @@ -85,12 +77,7 @@ TEST_FUNCTION_START(nmod_mat_solve_vec, state) solved = nmod_mat_solve_vec(x->entries, A, b->entries); if (solved) - { - flint_printf("FAIL:\n"); - flint_printf("singular system was 'solved'\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("singular system was 'solved'\n"); nmod_mat_clear(A); nmod_mat_clear(b); diff --git a/src/nmod_mat/test/t-submul.c b/src/nmod_mat/test/t-submul.c index 70d2514e3e..5417dd4f57 100644 --- a/src/nmod_mat/test/t-submul.c +++ b/src/nmod_mat/test/t-submul.c @@ -52,31 +52,27 @@ TEST_FUNCTION_START(nmod_mat_submul, state) nmod_mat_sub(E, C, T); if (!nmod_mat_equal(D, E)) - { - flint_printf("FAIL: results not equal\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - nmod_mat_print_pretty(E); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n" + "E = %{nmod_mat}\n", + A, B, C, D, E); /* Check aliasing */ nmod_mat_submul(C, C, A, B); if (!nmod_mat_equal(C, E)) - { - flint_printf("FAIL: results not equal (aliasing)\n"); - nmod_mat_print_pretty(A); - nmod_mat_print_pretty(B); - nmod_mat_print_pretty(C); - nmod_mat_print_pretty(D); - nmod_mat_print_pretty(E); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "Results not equal (aliasing)\n" + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "C = %{nmod_mat}\n" + "D = %{nmod_mat}\n" + "E = %{nmod_mat}\n", + A, B, C, D, E); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-trace.c b/src/nmod_mat/test/t-trace.c index 2ffec526f3..db7864d589 100644 --- a/src/nmod_mat/test/t-trace.c +++ b/src/nmod_mat/test/t-trace.c @@ -43,17 +43,14 @@ TEST_FUNCTION_START(nmod_mat_trace, state) trba = nmod_mat_trace(BA); if (trab != trba) - { - flint_printf("FAIL:\n"); - nmod_mat_print_pretty(A), flint_printf("\n"); - nmod_mat_print_pretty(B), flint_printf("\n"); - nmod_mat_print_pretty(AB), flint_printf("\n"); - nmod_mat_print_pretty(BA), flint_printf("\n"); - flint_printf("tr(AB): %wu\n", trab); - flint_printf("tr(BA): %wu\n", trba); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL( + "A = %{nmod_mat}\n" + "B = %{nmod_mat}\n" + "AB = %{nmod_mat}\n" + "BA = %{nmod_mat}\n" + "tr(AB) = %wu\n" + "tr(BA) = %wu\n", + A, B, AB, BA, trab, trba); nmod_mat_clear(A); nmod_mat_clear(B); diff --git a/src/nmod_mat/test/t-transpose.c b/src/nmod_mat/test/t-transpose.c index a424bd13f3..a9c70358f3 100644 --- a/src/nmod_mat/test/t-transpose.c +++ b/src/nmod_mat/test/t-transpose.c @@ -37,11 +37,7 @@ TEST_FUNCTION_START(nmod_mat_transpose, state) nmod_mat_transpose(C, B); if (!nmod_mat_equal(C, A)) - { - flint_printf("FAIL: C != A\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("C != A\n"); nmod_mat_clear(A); nmod_mat_clear(B); @@ -74,11 +70,7 @@ TEST_FUNCTION_START(nmod_mat_transpose, state) nmod_mat_set(AT2, AT); if (!nmod_mat_equal(BT, AT2)) - { - flint_printf("FAIL: AT != BT\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("AT != BT\n"); nmod_mat_clear(A); nmod_mat_clear(AT); @@ -105,11 +97,7 @@ TEST_FUNCTION_START(nmod_mat_transpose, state) nmod_mat_transpose(B, B); if (!nmod_mat_equal(B, A)) - { - flint_printf("FAIL: B != A\n"); - fflush(stdout); - flint_abort(); - } + TEST_FUNCTION_FAIL("B != A\n"); nmod_mat_clear(A); nmod_mat_clear(B); From 914417208a0267909bd12c0d8f5d333f6825c10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 12:42:31 +0100 Subject: [PATCH 02/13] Remove duplicate acb_vec_printd --- src/acb_dirichlet.h | 10 ---------- src/acb_dirichlet/test/t-dft.c | 4 ++-- src/acb_dirichlet/test/t-l_vec_hurwitz.c | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/acb_dirichlet.h b/src/acb_dirichlet.h index 763c7ea21b..c7326a17c4 100644 --- a/src/acb_dirichlet.h +++ b/src/acb_dirichlet.h @@ -310,16 +310,6 @@ slong acb_dirichlet_platt_hardy_z_zeros( void acb_dirichlet_dft_index(acb_ptr w, acb_srcptr v, const dirichlet_group_t G, slong prec); void acb_dirichlet_dft(acb_ptr w, acb_srcptr v, const dirichlet_group_t G, slong prec); -/* utils */ - -FLINT_FORCE_INLINE void -acb_vec_printd(acb_srcptr vec, slong len, slong digits) -{ - slong i; - for (i = 0; i < len; i++) - acb_printd(vec + i, digits), flint_printf("\n"); -} - #ifdef __cplusplus } #endif diff --git a/src/acb_dirichlet/test/t-dft.c b/src/acb_dirichlet/test/t-dft.c index 0c59a3ceba..6ffdb69936 100644 --- a/src/acb_dirichlet/test/t-dft.c +++ b/src/acb_dirichlet/test/t-dft.c @@ -27,9 +27,9 @@ check_vec_eq_prec(acb_srcptr w1, acb_srcptr w2, slong len, slong prec, slong dig flint_printf("q = %wu, size = %wd\n", q, len); flint_printf("\nDFT differ from index %wd / %wd \n", i, len); flint_printf("\n%s =\n", f1); - acb_vec_printd(w1, len, digits); + _acb_vec_printd(w1, len, digits); flint_printf("\n%s =\n", f2); - acb_vec_printd(w2, len, digits); + _acb_vec_printd(w2, len, digits); flint_printf("\n\n"); flint_abort(); } diff --git a/src/acb_dirichlet/test/t-l_vec_hurwitz.c b/src/acb_dirichlet/test/t-l_vec_hurwitz.c index 9438040b30..5fa571fa3b 100644 --- a/src/acb_dirichlet/test/t-l_vec_hurwitz.c +++ b/src/acb_dirichlet/test/t-l_vec_hurwitz.c @@ -74,7 +74,7 @@ TEST_FUNCTION_START(acb_dirichlet_l_vec_hurwitz, state) flint_printf("\nL(1/2, %wu) multi = ", chi->n); acb_printd(v + i, 20); flint_printf("\n\n"); - acb_vec_printd(v, G->phi_q, 10); + _acb_vec_printd(v, G->phi_q, 10); flint_printf("\n\n"); flint_abort(); } From efc45d53755dd4df63c31ec8d73d837a9a51f7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 12:51:03 +0100 Subject: [PATCH 03/13] Remove unnused unity_zp_print --- src/aprcl.h | 3 --- src/aprcl/unity_zp_print.c | 21 --------------------- 2 files changed, 24 deletions(-) delete mode 100644 src/aprcl/unity_zp_print.c diff --git a/src/aprcl.h b/src/aprcl.h index 7f98474321..74cf931309 100644 --- a/src/aprcl.h +++ b/src/aprcl.h @@ -131,9 +131,6 @@ slong unity_zp_is_unity(unity_zp f); int unity_zp_equal(unity_zp f, unity_zp g); -/* I/O */ -void unity_zp_print(const unity_zp f); - /* Coefficient management */ void unity_zp_coeff_set_fmpz(unity_zp f, ulong ind, const fmpz_t x); void unity_zp_coeff_set_ui(unity_zp f, ulong ind, ulong x); diff --git a/src/aprcl/unity_zp_print.c b/src/aprcl/unity_zp_print.c deleted file mode 100644 index d16a672756..0000000000 --- a/src/aprcl/unity_zp_print.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - Copyright (C) 2015 Vladimir Glazachev - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "fmpz_mod_poly.h" -#include "aprcl.h" - -void -unity_zp_print(const unity_zp f) -{ - flint_printf("p = %wu; exp = %wu\n", f->p, f->exp); - fmpz_mod_poly_print(f->poly, f->ctx); - flint_printf("\n"); -} From 543194d1adcbb49152ee36ad88a4699c67bb6d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 12:56:00 +0100 Subject: [PATCH 04/13] Remove unnused unity_zp_mul_scalar_fmpz --- src/aprcl.h | 1 - src/aprcl/unity_zp_mul.c | 9 --------- 2 files changed, 10 deletions(-) diff --git a/src/aprcl.h b/src/aprcl.h index 74cf931309..b6a8b39c3e 100644 --- a/src/aprcl.h +++ b/src/aprcl.h @@ -142,7 +142,6 @@ void unity_zp_coeff_inc(unity_zp f, ulong ind); void unity_zp_coeff_dec(unity_zp f, ulong ind); /* Scalar multiplication */ -void unity_zp_mul_scalar_fmpz(unity_zp f, const unity_zp g, const fmpz_t s); void unity_zp_mul_scalar_ui(unity_zp f, const unity_zp g, ulong s); /* Addition */ diff --git a/src/aprcl/unity_zp_mul.c b/src/aprcl/unity_zp_mul.c index e275ad7ec3..62916f882d 100644 --- a/src/aprcl/unity_zp_mul.c +++ b/src/aprcl/unity_zp_mul.c @@ -872,15 +872,6 @@ unity_zp_mul7(unity_zp f, const unity_zp g, const unity_zp h, fmpz_t * t) unity_zp_coeff_set_fmpz(f, 5, t[0]); /* z5 = a0 mod n */ } -void -unity_zp_mul_scalar_fmpz(unity_zp f, const unity_zp g, const fmpz_t s) -{ - FLINT_ASSERT(fmpz_equal(fmpz_mod_ctx_modulus(f->ctx), - fmpz_mod_ctx_modulus(g->ctx))); - - fmpz_mod_poly_scalar_mul_fmpz(f->poly, g->poly, s, f->ctx); -} - void unity_zp_mul_scalar_ui(unity_zp f, const unity_zp g, ulong s) { From 325f1c37df250908ecf6bfb9e0be101824c98f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 12:57:44 +0100 Subject: [PATCH 05/13] Remove unused unity_zpq_scalar_mul_[ui/fmpz] --- src/aprcl.h | 3 --- src/aprcl/unity_zpq_scalar.c | 42 ------------------------------------ 2 files changed, 45 deletions(-) delete mode 100644 src/aprcl/unity_zpq_scalar.c diff --git a/src/aprcl.h b/src/aprcl.h index b6a8b39c3e..29e31c2bb7 100644 --- a/src/aprcl.h +++ b/src/aprcl.h @@ -237,9 +237,6 @@ void unity_zpq_coeff_set_ui(unity_zpq f, slong i, slong j, ulong x); void unity_zpq_coeff_add(unity_zpq f, slong i, slong j, const fmpz_t x); void unity_zpq_coeff_add_ui(unity_zpq f, slong i, slong j, ulong x); -/* Scalar multiplication */ -void unity_zpq_scalar_mul_ui(unity_zpq f, const unity_zpq g, ulong s); - /* Addition and multiplication */ void unity_zpq_add(unity_zpq f, const unity_zpq g, const unity_zpq h); diff --git a/src/aprcl/unity_zpq_scalar.c b/src/aprcl/unity_zpq_scalar.c deleted file mode 100644 index 1b4cfce1ef..0000000000 --- a/src/aprcl/unity_zpq_scalar.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2015 Vladimir Glazachev - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "fmpz_mod_poly.h" -#include "aprcl.h" - -#if FLINT_WANT_ASSERT -# include "fmpz.h" -# include "fmpz_mod.h" -#endif - -void -unity_zpq_scalar_mul_fmpz(unity_zpq f, const unity_zpq g, const fmpz_t s) -{ - slong i; - - FLINT_ASSERT(fmpz_equal(fmpz_mod_ctx_modulus(f->ctx), - fmpz_mod_ctx_modulus(g->ctx))); - - for (i = 0; i < f->p; i++) - fmpz_mod_poly_scalar_mul_fmpz(f->polys[i], g->polys[i], s, f->ctx); -} - -void -unity_zpq_scalar_mul_ui(unity_zpq f, const unity_zpq g, ulong s) -{ - slong i; - - FLINT_ASSERT(fmpz_equal(fmpz_mod_ctx_modulus(f->ctx), - fmpz_mod_ctx_modulus(g->ctx))); - - for (i = 0; i < f->p; i++) - fmpz_mod_poly_scalar_mul_ui(f->polys[i], g->polys[i], s, f->ctx); -} From fa7451d03bc24e8aa4c2da76a1df29cc28ce6eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:00:25 +0100 Subject: [PATCH 06/13] Remove unused unity_zpq_p_unity functions --- src/aprcl.h | 6 ---- src/aprcl/unity_zpq_is_p_unity.c | 55 -------------------------------- 2 files changed, 61 deletions(-) delete mode 100644 src/aprcl/unity_zpq_is_p_unity.c diff --git a/src/aprcl.h b/src/aprcl.h index 29e31c2bb7..41bf26cfd6 100644 --- a/src/aprcl.h +++ b/src/aprcl.h @@ -224,12 +224,6 @@ void unity_zpq_swap(unity_zpq f, unity_zpq g); /* Comparison */ int unity_zpq_equal(const unity_zpq f, const unity_zpq g); -slong unity_zpq_p_unity(const unity_zpq f); - -int unity_zpq_is_p_unity(const unity_zpq f); - -int unity_zpq_is_p_unity_generator(const unity_zpq f); - /* Coefficient management */ void unity_zpq_coeff_set_fmpz(unity_zpq f, slong i, slong j, const fmpz_t x); void unity_zpq_coeff_set_ui(unity_zpq f, slong i, slong j, ulong x); diff --git a/src/aprcl/unity_zpq_is_p_unity.c b/src/aprcl/unity_zpq_is_p_unity.c deleted file mode 100644 index cda504ab01..0000000000 --- a/src/aprcl/unity_zpq_is_p_unity.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (C) 2015 Vladimir Glazachev - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "fmpz.h" -#include "aprcl.h" - -slong -unity_zpq_p_unity(const unity_zpq f) -{ - slong i; - ulong is_punity; - - is_punity = f->p; - - for (i = 0; i < f->p; i++) - { - if (fmpz_equal_ui(f->polys[i]->coeffs + i, 1)) - { - if (is_punity != f->p) - return 0; - - is_punity = i; - } - } - - return is_punity; -} - -int -unity_zpq_is_p_unity(const unity_zpq f) -{ - if (unity_zpq_p_unity(f) != f->p) - return 1; - - return 0; -} - -int -unity_zpq_is_p_unity_generator(const unity_zpq f) -{ - slong upow = unity_zpq_p_unity(f); - - if (upow != f->p && upow != 0) - return 1; - - return 0; -} From dcddfaf9602912f42ef7cf690fc0bcaef2941826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:02:03 +0100 Subject: [PATCH 07/13] Remove unnused aprcl_is_prime_divisors_in_residue --- src/aprcl.h | 4 +-- src/aprcl/is_prime_divisors_in_residue.c | 46 ------------------------ 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 src/aprcl/is_prime_divisors_in_residue.c diff --git a/src/aprcl.h b/src/aprcl.h index 41bf26cfd6..c17a723551 100644 --- a/src/aprcl.h +++ b/src/aprcl.h @@ -110,9 +110,7 @@ slong _aprcl_is_prime_jacobi_check_2k(const unity_zp j, const unity_zp j2_1, con int _aprcl_is_prime_jacobi_additional_test(const fmpz_t n, ulong p); -/* Final division functions */ -int aprcl_is_prime_divisors_in_residue(const fmpz_t n, const fmpz_t s, ulong r); - +/* Final division function */ int aprcl_is_prime_final_division(const fmpz_t n, const fmpz_t s, ulong r); /* Z[unity_root]/(n) operations **********************************************/ diff --git a/src/aprcl/is_prime_divisors_in_residue.c b/src/aprcl/is_prime_divisors_in_residue.c deleted file mode 100644 index fe760b0bd3..0000000000 --- a/src/aprcl/is_prime_divisors_in_residue.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2015 Vladimir Glazachev - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "fmpz.h" -#include "aprcl.h" - -int -aprcl_is_prime_divisors_in_residue(const fmpz_t n, const fmpz_t s, ulong r) -{ - int result; - ulong i; - fmpz_t npow, nmul, fac; - - fmpz_init(fac); - fmpz_init_set(npow, n); - fmpz_mod(npow, npow, s); /* npow = n mod s */ - fmpz_init_set(nmul, npow); - - result = 1; - for (i = 1; i < r; i++) - { - /* if find divisor then n is composite */ - if (fmpz_divisor_in_residue_class_lenstra(fac, n, npow, s) == 1) - { - result = 0; - break; - } - /* npow = n^i mod s */ - fmpz_mul(npow, npow, nmul); - fmpz_mod(npow, npow, s); - } - - fmpz_clear(fac); - fmpz_clear(npow); - fmpz_clear(nmul); - - return result; -} From cad9771a29111e910d7eeebbdbd8fe978b2c4bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:04:49 +0100 Subject: [PATCH 08/13] Remove removed functions from APRCL documentation --- doc/source/aprcl.rst | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/doc/source/aprcl.rst b/doc/source/aprcl.rst index aba53e3a45..1d593f0ba7 100644 --- a/doc/source/aprcl.rst +++ b/doc/source/aprcl.rst @@ -173,13 +173,6 @@ Comparison Returns nonzero if `f = g` reduced by the `p^{exp}`-th cyclotomic polynomial. -Output -................................................................................ - -.. function:: void unity_zp_print(const unity_zp f) - - Prints the contents of the `f`. - Coefficient management ................................................................................ @@ -209,11 +202,6 @@ Coefficient management Scalar multiplication ................................................................................ -.. function:: void unity_zp_mul_scalar_fmpz(unity_zp f, const unity_zp g, const fmpz_t s) - - Sets `f` to `s \cdot g`. `f` and `g` must be initialized with - same `p`, `exp` and `n`. - .. function:: void unity_zp_mul_scalar_ui(unity_zp f, const unity_zp g, ulong s) Sets `f` to `s \cdot g`. `f` and `g` must be initialized with @@ -362,18 +350,6 @@ Extended rings Returns nonzero if `f = g`. -.. function:: slong unity_zpq_p_unity(const unity_zpq f) - - If `f = \zeta_p^x` returns `x \in [0, p - 1]`; otherwise returns `p`. - -.. function:: int unity_zpq_is_p_unity(const unity_zpq f) - - Returns nonzero if `f = \zeta_p^x`. - -.. function:: int unity_zpq_is_p_unity_generator(const unity_zpq f) - - Returns nonzero if `f` is a generator of the cyclic group `\langle\zeta_p\rangle`. - .. function:: void unity_zpq_coeff_set_fmpz(unity_zpq f, slong i, slong j, const fmpz_t x) Sets the coefficient of `\zeta_q^i \zeta_p^j` to `x`. From 9748b02a1f34af630f18da99cd3a32e8520b5053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:16:18 +0100 Subject: [PATCH 09/13] Inline some fmpz_mod_poly attributes --- src/fmpz_mod_poly.h | 42 +++++++++++++++++++++++++++++----- src/fmpz_mod_poly/attributes.c | 34 --------------------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/fmpz_mod_poly.h b/src/fmpz_mod_poly.h index ea22a99771..4f11b49b0d 100644 --- a/src/fmpz_mod_poly.h +++ b/src/fmpz_mod_poly.h @@ -171,14 +171,44 @@ void fmpz_mod_poly_randtest_sparse_irreducible(fmpz_mod_poly_t poly, /* Attributes ***************************************************************/ -slong fmpz_mod_poly_degree(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx); -slong fmpz_mod_poly_length(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx); +FMPZ_MOD_POLY_INLINE +slong fmpz_mod_poly_length(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) +{ + return poly->length; +} +FMPZ_MOD_POLY_INLINE +slong fmpz_mod_poly_degree(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) +{ + return poly->length - 1; +} + +FMPZ_MOD_POLY_INLINE +fmpz * fmpz_mod_poly_lead(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) +{ + if (poly->length) + return poly->coeffs + (poly->length - 1); + else + return NULL; +} -fmpz * fmpz_mod_poly_lead(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx); +FMPZ_MOD_POLY_INLINE +int fmpz_mod_poly_is_monic(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) +{ + return f->length > 0 && f->coeffs[f->length - 1] == WORD(1); +} + +FMPZ_MOD_POLY_INLINE +int fmpz_mod_poly_is_one(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) +{ + return poly->length == 1 && poly->coeffs[0] == WORD(1); +} + +FMPZ_MOD_POLY_INLINE +int fmpz_mod_poly_is_gen(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx) +{ + return op->length == 2 && op->coeffs[1] == WORD(1) && op->coeffs[0] == WORD(0); +} -int fmpz_mod_poly_is_monic(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx); -int fmpz_mod_poly_is_one(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx); -int fmpz_mod_poly_is_gen(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx); int fmpz_mod_poly_is_unit(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx); /* Assignment and basic manipulation ****************************************/ diff --git a/src/fmpz_mod_poly/attributes.c b/src/fmpz_mod_poly/attributes.c index 87cd938446..39fe2b84e6 100644 --- a/src/fmpz_mod_poly/attributes.c +++ b/src/fmpz_mod_poly/attributes.c @@ -9,43 +9,9 @@ (at your option) any later version. See . */ -#include "fmpz.h" #include "fmpz_mod.h" #include "fmpz_mod_poly.h" -slong fmpz_mod_poly_degree(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) -{ - return poly->length - 1; -} - -slong fmpz_mod_poly_length(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) -{ - return poly->length; -} - -fmpz * fmpz_mod_poly_lead(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) -{ - if (poly->length) - return poly->coeffs + (poly->length - 1); - else - return NULL; -} - -int fmpz_mod_poly_is_monic(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) -{ - return f->length > 0 && fmpz_is_one(f->coeffs + f->length - 1); -} - -int fmpz_mod_poly_is_one(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) -{ - return poly->length == 1 && fmpz_is_one(poly->coeffs + 0); -} - -int fmpz_mod_poly_is_gen(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx) -{ - return (op->length) == 2 && (*(op->coeffs + 1) == WORD(1)) && (*(op->coeffs + 0) == WORD(0)); -} - /* bogus for non-prime modulus */ int fmpz_mod_poly_is_unit(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx) { From 5dc481c74201fe0f1fa36040e349a005b67e054e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:22:21 +0100 Subject: [PATCH 10/13] Remove unused d_mat inline functions --- src/d_mat.h | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/d_mat.h b/src/d_mat.h index a5ba93030a..3d62711eec 100644 --- a/src/d_mat.h +++ b/src/d_mat.h @@ -20,11 +20,10 @@ #define D_MAT_INLINE static inline #endif - #include "flint.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif typedef struct @@ -39,18 +38,6 @@ typedef d_mat_struct d_mat_t[1]; #define d_mat_entry(mat,i,j) (*((mat)->rows[i] + (j))) -D_MAT_INLINE -double * d_mat_entry_ptr(const d_mat_t mat, slong i, slong j) -{ - return mat->rows[i] + j; -} - -D_MAT_INLINE -double d_mat_get_entry(const d_mat_t mat, slong i, slong j) -{ - return mat->rows[i][j]; -} - D_MAT_INLINE slong d_mat_nrows(const d_mat_t mat) { @@ -104,15 +91,13 @@ void d_mat_zero(d_mat_t mat); void d_mat_one(d_mat_t mat); - /* Input and output *********************************************************/ void d_mat_print(const d_mat_t mat); /* Random matrix generation *************************************************/ -void d_mat_randtest(d_mat_t mat, flint_rand_t state, slong minexp, - slong maxexp); +void d_mat_randtest(d_mat_t mat, flint_rand_t state, slong minexp, slong maxexp); /* Transpose */ @@ -122,17 +107,6 @@ void d_mat_transpose(d_mat_t B, const d_mat_t A); void d_mat_mul_classical(d_mat_t C, const d_mat_t A, const d_mat_t B); -/* Permutations */ - -D_MAT_INLINE -void d_mat_swap_rows(d_mat_t mat, slong r, slong s) -{ - if (r != s) - { - FLINT_SWAP(double *, mat->rows[r], mat->rows[s]); - } -} - /* Gram-Schmidt Orthogonalisation and QR Decomposition ********************************************************/ void d_mat_gso(d_mat_t B, const d_mat_t A); From 7c095f3282c139ae6aa5b000881ff5fc0c241198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:27:55 +0100 Subject: [PATCH 11/13] Remove unnused d_mat_[gso/qr] --- src/d_mat.h | 6 --- src/d_mat/gso.c | 88 -------------------------------------- src/d_mat/qr.c | 97 ------------------------------------------ src/d_mat/test/main.c | 4 -- src/d_mat/test/t-gso.c | 71 ------------------------------- src/d_mat/test/t-qr.c | 88 -------------------------------------- 6 files changed, 354 deletions(-) delete mode 100644 src/d_mat/gso.c delete mode 100644 src/d_mat/qr.c delete mode 100644 src/d_mat/test/t-gso.c delete mode 100644 src/d_mat/test/t-qr.c diff --git a/src/d_mat.h b/src/d_mat.h index 3d62711eec..59baabad59 100644 --- a/src/d_mat.h +++ b/src/d_mat.h @@ -107,12 +107,6 @@ void d_mat_transpose(d_mat_t B, const d_mat_t A); void d_mat_mul_classical(d_mat_t C, const d_mat_t A, const d_mat_t B); -/* Gram-Schmidt Orthogonalisation and QR Decomposition ********************************************************/ - -void d_mat_gso(d_mat_t B, const d_mat_t A); - -void d_mat_qr(d_mat_t Q, d_mat_t R, const d_mat_t A); - #ifdef __cplusplus } #endif diff --git a/src/d_mat/gso.c b/src/d_mat/gso.c deleted file mode 100644 index 32f8056b9f..0000000000 --- a/src/d_mat/gso.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "double_extras.h" -#include "d_mat.h" - -void -d_mat_gso(d_mat_t B, const d_mat_t A) -{ - slong i, j, k; - int flag; - double t, s; - - if (B->r != A->r || B->c != A->c) - { - flint_throw(FLINT_ERROR, "Exception (d_mat_gso). Incompatible dimensions.\n"); - } - - if (B == A) - { - d_mat_t t; - d_mat_init(t, A->r, A->c); - d_mat_gso(t, A); - d_mat_swap_entrywise(B, t); - d_mat_clear(t); - return; - } - - if (A->r == 0) - { - return; - } - - for (k = 0; k < A->c; k++) - { - for (j = 0; j < A->r; j++) - { - d_mat_entry(B, j, k) = d_mat_entry(A, j, k); - } - flag = 1; - while (flag) - { - t = 0; - for (i = 0; i < k; i++) - { - s = 0; - for (j = 0; j < A->r; j++) - { - s += d_mat_entry(B, j, i) * d_mat_entry(B, j, k); - } - t += s * s; - for (j = 0; j < A->r; j++) - { - d_mat_entry(B, j, k) -= s * d_mat_entry(B, j, i); - } - } - s = 0; - for (j = 0; j < A->r; j++) - { - s += d_mat_entry(B, j, k) * d_mat_entry(B, j, k); - } - t += s; - flag = 0; - if (s < t) - { - if (fabs(s * D_EPS) < 1.0e-308) - s = 0; - else - flag = 1; - } - } - s = sqrt(s); - if (s != 0) - s = 1 / s; - for (j = 0; j < A->r; j++) - { - d_mat_entry(B, j, k) *= s; - } - } -} diff --git a/src/d_mat/qr.c b/src/d_mat/qr.c deleted file mode 100644 index 8da2a3749e..0000000000 --- a/src/d_mat/qr.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "double_extras.h" -#include "d_mat.h" - -void -d_mat_qr(d_mat_t Q, d_mat_t R, const d_mat_t A) -{ - slong i, j, k; - int flag, orig; - double t, s; - - if (Q->r != A->r || Q->c != A->c || R->r != A->c || R->c != A->c) - { - flint_throw(FLINT_ERROR, "Exception (d_mat_qr). Incompatible dimensions.\n"); - } - - if (Q == A) - { - d_mat_t t; - d_mat_init(t, A->r, A->c); - d_mat_qr(t, R, A); - d_mat_swap_entrywise(Q, t); - d_mat_clear(t); - return; - } - - if (A->r == 0) - { - return; - } - - for (k = 0; k < A->c; k++) - { - for (j = 0; j < A->r; j++) - { - d_mat_entry(Q, j, k) = d_mat_entry(A, j, k); - } - orig = flag = 1; - while (flag) - { - t = 0; - for (i = 0; i < k; i++) - { - s = 0; - for (j = 0; j < A->r; j++) - { - s += d_mat_entry(Q, j, i) * d_mat_entry(Q, j, k); - } - if (orig) - { - d_mat_entry(R, i, k) = s; - } - else - { - d_mat_entry(R, i, k) += s; - } - t += s * s; - for (j = 0; j < A->r; j++) - { - d_mat_entry(Q, j, k) -= s * d_mat_entry(Q, j, i); - } - } - s = 0; - for (j = 0; j < A->r; j++) - { - s += d_mat_entry(Q, j, k) * d_mat_entry(Q, j, k); - } - t += s; - flag = 0; - if (s < t) - { - orig = 0; - if (fabs(s * D_EPS) < 1.0e-308) - s = 0; - else - flag = 1; - } - } - d_mat_entry(R, k, k) = s = sqrt(s); - if (s != 0) - s = 1 / s; - for (j = 0; j < A->r; j++) - { - d_mat_entry(Q, j, k) *= s; - } - } -} diff --git a/src/d_mat/test/main.c b/src/d_mat/test/main.c index 100a75367a..0b870c668a 100644 --- a/src/d_mat/test/main.c +++ b/src/d_mat/test/main.c @@ -16,13 +16,11 @@ #include "t-entry.c" #include "t-equal.c" -#include "t-gso.c" #include "t-init_clear.c" #include "t-is_empty.c" #include "t-is_square.c" #include "t-mul_classical.c" #include "t-one.c" -#include "t-qr.c" #include "t-transpose.c" #include "t-zero.c" @@ -32,13 +30,11 @@ test_struct tests[] = { TEST_FUNCTION(d_mat_entry), TEST_FUNCTION(d_mat_equal), - TEST_FUNCTION(d_mat_gso), TEST_FUNCTION(d_mat_init_clear), TEST_FUNCTION(d_mat_is_empty), TEST_FUNCTION(d_mat_is_square), TEST_FUNCTION(d_mat_mul_classical), TEST_FUNCTION(d_mat_one), - TEST_FUNCTION(d_mat_qr), TEST_FUNCTION(d_mat_transpose), TEST_FUNCTION(d_mat_zero) }; diff --git a/src/d_mat/test/t-gso.c b/src/d_mat/test/t-gso.c deleted file mode 100644 index ed68cd0afc..0000000000 --- a/src/d_mat/test/t-gso.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "test_helpers.h" -#include "double_extras.h" -#include "d_mat.h" -#include "ulong_extras.h" - -#define D_MAT_GSO_NORM_EPS (4 * D_EPS) -#define D_MAT_GSO_ORTHO_EPS (2 * D_EPS) - -TEST_FUNCTION_START(d_mat_gso, state) -{ - int i, tmul = 100; -#ifdef _WIN32 - tmul = 1; -#endif - - /* check norm(column(gso)) = 1 or 0 - * check dot product of columns of gso is zero */ - for (i = 0; i < tmul * flint_test_multiplier(); i++) - { - double dot; - int j, k, l; - d_mat_t A; - - slong m, n; - - m = n_randint(state, 10); - n = n_randint(state, 10); - - d_mat_init(A, m, n); - - d_mat_randtest(A, state, 0, 0); - - d_mat_gso(A, A); - - for (j = 0; j < n; j++) - { - double norm = 0; - for (l = 0; l < m; l++) - norm += d_mat_entry(A, l, j) * d_mat_entry(A, l, j); - - if (norm != 0 && fabs(norm - 1) > D_MAT_GSO_NORM_EPS) - TEST_FUNCTION_FAIL(""); - - for (k = j + 1; k < n; k++) - { - - dot = 0; - for (l = 0; l < m; l++) - dot += d_mat_entry(A, l, j) * d_mat_entry(A, l, k); - - if (fabs(dot) > D_MAT_GSO_ORTHO_EPS) - TEST_FUNCTION_FAIL(""); - } - } - - d_mat_clear(A); - } - - TEST_FUNCTION_END(state); -} diff --git a/src/d_mat/test/t-qr.c b/src/d_mat/test/t-qr.c deleted file mode 100644 index 689068cde7..0000000000 --- a/src/d_mat/test/t-qr.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "test_helpers.h" -#include "double_extras.h" -#include "d_mat.h" -#include "ulong_extras.h" - -#define D_MAT_QR_EQ_EPS (3 * D_EPS) -#define D_MAT_QR_NORM_EPS (4 * D_EPS) -#define D_MAT_QR_ORTHO_EPS (2 * D_EPS) - -TEST_FUNCTION_START(d_mat_qr, state) -{ - int i; - int tmul = 100; -#ifdef _WIN32 - tmul = 1; -#endif - - /* check QR = A - * check norm(column(Q)) = 1 or 0 - * check dot product of columns of Q is zero */ - for (i = 0; i < tmul * flint_test_multiplier(); i++) - { - double dot; - int j, k, l; - d_mat_t A, Q, R, B; - - slong m, n; - - m = n_randint(state, 10); - n = n_randint(state, 10); - - d_mat_init(A, m, n); - d_mat_init(Q, m, n); - d_mat_init(R, n, n); - d_mat_init(B, m, n); - - d_mat_randtest(A, state, 0, 0); - d_mat_zero(R); - - d_mat_qr(Q, R, A); - - d_mat_mul_classical(B, Q, R); - - if (!d_mat_approx_equal(A, B, D_MAT_QR_EQ_EPS)) - TEST_FUNCTION_FAIL(""); - - for (j = 0; j < n; j++) - { - double norm = 0; - for (l = 0; l < m; l++) - norm += d_mat_entry(Q, l, j) * d_mat_entry(Q, l, j); - - if (norm != 0 && fabs(norm - 1) > D_MAT_QR_NORM_EPS) - TEST_FUNCTION_FAIL(""); - - for (k = j + 1; k < n; k++) - { - - dot = 0; - for (l = 0; l < m; l++) - { - dot += d_mat_entry(Q, l, j) * d_mat_entry(Q, l, k); - } - - if (fabs(dot) > D_MAT_QR_ORTHO_EPS) - TEST_FUNCTION_FAIL(""); - } - } - - d_mat_clear(A); - d_mat_clear(Q); - d_mat_clear(R); - d_mat_clear(B); - } - - TEST_FUNCTION_END(state); -} From 5c5571dc3d422ef357b6f49b5c7b929a28b52330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:30:13 +0100 Subject: [PATCH 12/13] Remove unnused d_mat_one --- doc/source/d_mat.rst | 30 ------------------------- src/d_mat.h | 2 -- src/d_mat/one.c | 25 --------------------- src/d_mat/test/main.c | 2 -- src/d_mat/test/t-one.c | 50 ------------------------------------------ 5 files changed, 109 deletions(-) delete mode 100644 src/d_mat/one.c delete mode 100644 src/d_mat/test/t-one.c diff --git a/doc/source/d_mat.rst b/doc/source/d_mat.rst index c071829a73..9e150d52af 100644 --- a/doc/source/d_mat.rst +++ b/doc/source/d_mat.rst @@ -52,12 +52,6 @@ Basic assignment and manipulation Sets all entries of ``mat`` to 0. -.. function:: void d_mat_one(d_mat_t mat) - - Sets ``mat`` to the unit matrix, having ones on the main diagonal - and zeroes elsewhere. If ``mat`` is nonsquare, it is set to the - truncation of a unit matrix. - Random matrix generation -------------------------------------------------------------------------------- @@ -124,27 +118,3 @@ Matrix multiplication Sets ``C`` to the matrix product `C = A B`. The matrices must have compatible dimensions for matrix multiplication (an exception is raised otherwise). Aliasing is allowed. - - -Gram-Schmidt Orthogonalisation and QR Decomposition --------------------------------------------------------------------------------- - - -.. function:: void d_mat_gso(d_mat_t B, const d_mat_t A) - - Takes a subset of `R^m` `S = {a_1, a_2, \ldots, a_n}` (as the columns of - a `m \times n` matrix ``A``) and generates an orthonormal set - `S' = {b_1, b_2, \ldots, b_n}` (as the columns of the `m \times n` matrix - ``B``) that spans the same subspace of `R^m` as `S`. - - This uses an algorithm of Schwarz-Rutishauser. See pp. 9 of - https://people.inf.ethz.ch/gander/papers/qrneu.pdf - -.. function:: void d_mat_qr(d_mat_t Q, d_mat_t R, const d_mat_t A) - - Computes the `QR` decomposition of a matrix ``A`` using the Gram-Schmidt - process. (Sets ``Q`` and ``R`` such that `A = QR` where ``R`` is - an upper triangular matrix and ``Q`` is an orthogonal matrix.) - - This uses an algorithm of Schwarz-Rutishauser. See pp. 9 of - https://people.inf.ethz.ch/gander/papers/qrneu.pdf diff --git a/src/d_mat.h b/src/d_mat.h index 59baabad59..fa13ef2b38 100644 --- a/src/d_mat.h +++ b/src/d_mat.h @@ -89,8 +89,6 @@ int d_mat_is_square(const d_mat_t mat) void d_mat_zero(d_mat_t mat); -void d_mat_one(d_mat_t mat); - /* Input and output *********************************************************/ void d_mat_print(const d_mat_t mat); diff --git a/src/d_mat/one.c b/src/d_mat/one.c deleted file mode 100644 index 2375c7ae8d..0000000000 --- a/src/d_mat/one.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Johansson - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "d_mat.h" - -void -d_mat_one(d_mat_t mat) -{ - slong i, n; - - d_mat_zero(mat); - n = FLINT_MIN(mat->r, mat->c); - - for (i = 0; i < n; i++) - d_mat_entry(mat, i, i) = 1; -} diff --git a/src/d_mat/test/main.c b/src/d_mat/test/main.c index 0b870c668a..db5b565139 100644 --- a/src/d_mat/test/main.c +++ b/src/d_mat/test/main.c @@ -20,7 +20,6 @@ #include "t-is_empty.c" #include "t-is_square.c" #include "t-mul_classical.c" -#include "t-one.c" #include "t-transpose.c" #include "t-zero.c" @@ -34,7 +33,6 @@ test_struct tests[] = TEST_FUNCTION(d_mat_is_empty), TEST_FUNCTION(d_mat_is_square), TEST_FUNCTION(d_mat_mul_classical), - TEST_FUNCTION(d_mat_one), TEST_FUNCTION(d_mat_transpose), TEST_FUNCTION(d_mat_zero) }; diff --git a/src/d_mat/test/t-one.c b/src/d_mat/test/t-one.c deleted file mode 100644 index 6e517c7c83..0000000000 --- a/src/d_mat/test/t-one.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Johansson - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "test_helpers.h" -#include "d_mat.h" -#include "ulong_extras.h" - -TEST_FUNCTION_START(d_mat_one, state) -{ - slong m, n, i, j, rep; - - /* check if diagonal elements are one and off diagonal elements are - zero */ - for (rep = 0; rep < 100 * flint_test_multiplier(); rep++) - { - d_mat_t A; - - m = n_randint(state, 20); - n = n_randint(state, 20); - - d_mat_init(A, m, n); - - d_mat_randtest(A, state, 0, 0); - d_mat_one(A); - - for (i = 0; i < m; i++) - { - for (j = 0; j < n; j++) - { - if (i == j && d_mat_entry(A, i, j) != 1) - TEST_FUNCTION_FAIL("entry not one\n"); - else if (i != j && d_mat_entry(A, i, j) != 0) - TEST_FUNCTION_FAIL("entry not zero\n"); - } - } - - d_mat_clear(A); - } - - TEST_FUNCTION_END(state); -} From 95953440fabd19ec7fc4f4fd3a84c171398ec26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 24 Jan 2024 13:31:39 +0100 Subject: [PATCH 13/13] Remove unnused d_mat_is_empty --- doc/source/d_mat.rst | 6 ------ src/d_mat.h | 6 ------ src/d_mat/test/main.c | 2 -- src/d_mat/test/t-is_empty.c | 38 ------------------------------------- 4 files changed, 52 deletions(-) delete mode 100644 src/d_mat/test/t-is_empty.c diff --git a/doc/source/d_mat.rst b/doc/source/d_mat.rst index 9e150d52af..1c17342dc4 100644 --- a/doc/source/d_mat.rst +++ b/doc/source/d_mat.rst @@ -87,12 +87,6 @@ Comparison the same dimensions and entries within ``eps`` of each other, and zero otherwise. -.. function:: int d_mat_is_empty(const d_mat_t mat) - - Returns a non-zero value if the number of rows or the number of - columns in ``mat`` is zero, and otherwise returns - zero. - .. function:: int d_mat_is_square(const d_mat_t mat) Returns a non-zero value if the number of rows is equal to the diff --git a/src/d_mat.h b/src/d_mat.h index fa13ef2b38..96bf307b9d 100644 --- a/src/d_mat.h +++ b/src/d_mat.h @@ -75,12 +75,6 @@ int d_mat_equal(const d_mat_t mat1, const d_mat_t mat2); int d_mat_approx_equal(const d_mat_t mat1, const d_mat_t mat2, double eps); -D_MAT_INLINE -int d_mat_is_empty(const d_mat_t mat) -{ - return (mat->r == 0) || (mat->c == 0); -} - D_MAT_INLINE int d_mat_is_square(const d_mat_t mat) { diff --git a/src/d_mat/test/main.c b/src/d_mat/test/main.c index db5b565139..c8a92b0bb0 100644 --- a/src/d_mat/test/main.c +++ b/src/d_mat/test/main.c @@ -17,7 +17,6 @@ #include "t-entry.c" #include "t-equal.c" #include "t-init_clear.c" -#include "t-is_empty.c" #include "t-is_square.c" #include "t-mul_classical.c" #include "t-transpose.c" @@ -30,7 +29,6 @@ test_struct tests[] = TEST_FUNCTION(d_mat_entry), TEST_FUNCTION(d_mat_equal), TEST_FUNCTION(d_mat_init_clear), - TEST_FUNCTION(d_mat_is_empty), TEST_FUNCTION(d_mat_is_square), TEST_FUNCTION(d_mat_mul_classical), TEST_FUNCTION(d_mat_transpose), diff --git a/src/d_mat/test/t-is_empty.c b/src/d_mat/test/t-is_empty.c deleted file mode 100644 index 2691725342..0000000000 --- a/src/d_mat/test/t-is_empty.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Johansson - Copyright (C) 2014 Abhinav Baid - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include "test_helpers.h" -#include "flint.h" -#include "d_mat.h" -#include "ulong_extras.h" - -TEST_FUNCTION_START(d_mat_is_empty, state) -{ - int i; - - /* check if a non-zero value is returned for non-empty matrices */ - for (i = 0; i < 1000 * flint_test_multiplier(); i++) - { - d_mat_t A; - slong rows = n_randint(state, 10); - slong cols = n_randint(state, 10); - - d_mat_init(A, rows, cols); - - if (d_mat_is_empty(A) != (rows == 0 || cols == 0)) - TEST_FUNCTION_FAIL(""); - - d_mat_clear(A); - } - - TEST_FUNCTION_END(state); -}