-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e3a735
commit fe7a9c5
Showing
7 changed files
with
137 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright (C) 2024 Fredrik Johansson | ||
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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "fmpz_mod.h" | ||
#include "fmpz_mod_mat.h" | ||
#include "gr.h" | ||
#include "gr_mat.h" | ||
|
||
void fmpz_mod_mat_det(fmpz_t res, const fmpz_mod_mat_t mat, const fmpz_mod_ctx_t ctx) | ||
{ | ||
gr_ctx_t gr_ctx; | ||
slong n = mat->r; | ||
|
||
if (!fmpz_mod_mat_is_square(mat, ctx)) | ||
{ | ||
flint_throw(FLINT_ERROR, "Exception (fmpz_mod_mat_charpoly_berkowitz). Non-square matrix.\n"); | ||
} | ||
|
||
_gr_ctx_init_fmpz_mod_from_ref(gr_ctx, ctx); | ||
|
||
if (n <= 4) | ||
{ | ||
GR_MUST_SUCCEED(gr_mat_det_cofactor(res, (const gr_mat_struct *) mat, gr_ctx)); | ||
} | ||
else | ||
{ | ||
if (gr_mat_det_lu(res, (const gr_mat_struct *) mat, gr_ctx) != GR_SUCCESS) | ||
{ | ||
/* Fall back on division-free algorithm if we encountered an impossible inverse */ | ||
/* Could try something else here: faddeev_bsgs (O(n^3.5)) or Howell form. */ | ||
GR_MUST_SUCCEED(gr_mat_det_berkowitz(res, (const gr_mat_struct *) mat, gr_ctx)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright (C) 2024 Fredrik Johansson | ||
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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "test_helpers.h" | ||
#include "fmpz.h" | ||
#include "fmpz_mod.h" | ||
#include "fmpz_mod_mat.h" | ||
#include "fmpz_mod_poly.h" | ||
#include "fmpz_mat.h" | ||
|
||
TEST_FUNCTION_START(fmpz_mod_mat_det, state) | ||
{ | ||
fmpz_mod_ctx_t ctx; | ||
fmpz_mod_mat_t A; | ||
fmpz_mat_t B; | ||
fmpz_t d1, d2; | ||
slong i, n; | ||
|
||
for (i = 0; i < 1000 * flint_test_multiplier(); i++) | ||
{ | ||
n = n_randint(state, 7); | ||
fmpz_mod_ctx_init_rand_bits(ctx, state, 200); | ||
|
||
fmpz_init(d1); | ||
fmpz_init(d2); | ||
|
||
fmpz_mod_mat_init(A, n, n, ctx); | ||
fmpz_mat_init(B, n, n); | ||
|
||
fmpz_mod_mat_randtest(A, state, ctx); | ||
fmpz_mod_mat_get_fmpz_mat(B, A, ctx); | ||
|
||
fmpz_mod_mat_det(d1, A, ctx); | ||
fmpz_mat_det(d2, B); | ||
fmpz_mod_set_fmpz(d2, d2, ctx); | ||
|
||
FLINT_TEST(fmpz_equal(d1, d2)); | ||
|
||
fmpz_mod_mat_clear(A, ctx); | ||
fmpz_mat_clear(B); | ||
fmpz_clear(d1); | ||
fmpz_clear(d2); | ||
|
||
fmpz_mod_ctx_clear(ctx); | ||
} | ||
|
||
TEST_FUNCTION_END(state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters