-
-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #22970: use flint fmpq_mat for rational dense matrices
The flint library has a builtin type for rational matrices: `fmpq_mat_t`. This ticket proposes to replace the current array of `mpq_t` wrapped by `Matrix_rational_dense` in favor of `fmpq_mat_t`. (See also the related #22924 and #22872) URL: https://trac.sagemath.org/22970 Reported by: vdelecroix Ticket author(s): Vincent Delecroix Reviewer(s): Marc Masdeu
- Loading branch information
Showing
23 changed files
with
1,667 additions
and
1,160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,74 @@ | ||
# distutils: libraries = flint | ||
|
||
from libc.stdio cimport FILE | ||
from sage.libs.gmp.types cimport mpq_t | ||
from sage.libs.flint.types cimport fmpq_t | ||
from sage.libs.flint.types cimport fmpz_t, fmpq_t, flint_rand_t, mp_bitcnt_t, fmpz | ||
from sage.libs.mpfr cimport mpfr_t, mpfr_rnd_t | ||
|
||
cdef extern from "flint/fmpq.h": | ||
# Memory management | ||
fmpz * fmpq_numref(fmpq_t) | ||
fmpz * fmpq_denref(fmpq_t) | ||
void fmpq_init(fmpq_t) | ||
void fmpq_clear(fmpq_t) | ||
|
||
# Conversion | ||
void fmpq_set_mpq(fmpq_t, const mpq_t) | ||
void fmpq_get_mpq(mpq_t, const fmpq_t) | ||
|
||
# Comparison | ||
int fmpq_is_zero(const fmpq_t res) | ||
int fmpq_is_one(const fmpq_t res) | ||
int fmpq_equal(const fmpq_t x, const fmpq_t y) | ||
int fmpq_sgn(const fmpq_t) | ||
void fmpq_one(fmpq_t) | ||
void fmpq_zero(fmpq_t) | ||
bint fmpq_is_zero(fmpq_t) | ||
bint fmpq_is_one(fmpq_t) | ||
int fmpq_sgn(const fmpq_t x) | ||
void fmpq_set(fmpq_t dest, const fmpq_t src) | ||
void fmpq_swap(fmpq_t op1, fmpq_t op2) | ||
void fmpq_neg(fmpq_t dest, const fmpq_t src) | ||
void fmpq_abs(fmpq_t dest, const fmpq_t src) | ||
int fmpq_cmp(const fmpq_t x, const fmpq_t y) | ||
|
||
void fmpq_canonicalise(fmpq_t res) | ||
int fmpq_is_canonical(const fmpq_t x) | ||
void fmpq_set_si(fmpq_t res, long p, unsigned long q) | ||
void fmpq_set_fmpz_frac(fmpq_t res, const fmpz_t p, const fmpz_t q) | ||
void fmpq_set_mpq(fmpq_t dest, const mpq_t src) | ||
void fmpq_get_mpq(mpq_t dest, const fmpq_t src) | ||
int fmpq_get_mpfr(mpfr_t r, const fmpq_t x, mpfr_rnd_t rnd) | ||
void flint_mpq_init_set_readonly(mpq_t z, const fmpq_t f) | ||
void flint_mpq_clear_readonly(mpq_t z) | ||
void fmpq_init_set_readonly(fmpq_t f, const mpq_t z) | ||
void fmpq_clear_readonly(fmpq_t f) | ||
char * fmpq_get_str(char * str, int b, const fmpq_t x) | ||
void fmpq_fprint(FILE * file, const fmpq_t x) | ||
void fmpq_print(const fmpq_t x) | ||
void fmpq_randtest(fmpq_t res, flint_rand_t state, mp_bitcnt_t bits) | ||
void fmpq_randtest_not_zero(fmpq_t res, flint_rand_t state, mp_bitcnt_t bits) | ||
void fmpq_randbits(fmpq_t res, flint_rand_t state, mp_bitcnt_t bits) | ||
void fmpq_add(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
void fmpq_add_si(fmpq_t res, const fmpq_t op1, long c) | ||
void fmpq_add_fmpz(fmpq_t res, const fmpq_t op1, const fmpz_t c) | ||
void fmpq_sub(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
void fmpq_sub_si(fmpq_t res, const fmpq_t op1, long c) | ||
void fmpq_sub_fmpz(fmpq_t res, const fmpq_t op1, const fmpz_t c) | ||
void fmpq_mul(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
void fmpq_mul_fmpz(fmpq_t res, const fmpq_t op, const fmpz_t x) | ||
void fmpq_pow_si(fmpq_t rop, const fmpq_t op, long e) | ||
void fmpq_addmul(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
void fmpq_submul(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
void fmpq_inv(fmpq_t dest, const fmpq_t src) | ||
void fmpq_div(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
void fmpq_div_fmpz(fmpq_t res, const fmpq_t op, const fmpz_t x) | ||
void fmpq_mul_2exp(fmpq_t res, const fmpq_t x, mp_bitcnt_t exp) | ||
void fmpq_div_2exp(fmpq_t res, const fmpq_t x, mp_bitcnt_t exp) | ||
int fmpq_mod_fmpz(fmpz_t res, const fmpq_t x, const fmpz_t mod) | ||
void fmpq_gcd(fmpq_t res, const fmpq_t op1, const fmpq_t op2) | ||
int fmpq_reconstruct_fmpz(fmpq_t res, const fmpz_t a, const fmpz_t m) | ||
int fmpq_reconstruct_fmpz_2(fmpq_t res, const fmpz_t a, const fmpz_t m, const fmpz_t N, const fmpz_t D) | ||
mp_bitcnt_t fmpq_height_bits(const fmpq_t x) | ||
void fmpq_height(fmpz_t height, const fmpq_t x) | ||
void fmpq_next_calkin_wilf(fmpq_t res, const fmpq_t x) | ||
void fmpq_next_signed_calkin_wilf(fmpq_t res, const fmpq_t x) | ||
void fmpq_next_minimal(fmpq_t res, const fmpq_t x) | ||
void fmpq_next_signed_minimal(fmpq_t res, const fmpq_t x) | ||
long fmpq_get_cfrac(fmpz * c, fmpq_t rem, const fmpq_t x, long n) | ||
void fmpq_set_cfrac(fmpq_t x, const fmpz * c, long n) | ||
long fmpq_cfrac_bound(const fmpq_t x) | ||
void fmpq_dedekind_sum_naive(fmpq_t s, const fmpz_t h, const fmpz_t k) | ||
void fmpq_dedekind_sum_coprime_large(fmpq_t s, const fmpz_t h, const fmpz_t k) | ||
double fmpq_dedekind_sum_coprime_d(double h, double k) | ||
void fmpq_dedekind_sum_coprime(fmpq_t s, const fmpz_t h, const fmpz_t k) | ||
void fmpq_dedekind_sum(fmpq_t s, const fmpz_t h, const fmpz_t k) | ||
void fmpq_harmonic_ui(fmpq_t x, unsigned long n) |
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,62 @@ | ||
# distutils: libraries = flint | ||
|
||
from sage.libs.flint.types cimport fmpz_t, fmpz, fmpq_t, fmpq, fmpz_mat_t, fmpq_mat_t, flint_rand_t, mp_bitcnt_t | ||
|
||
cdef extern from "flint/fmpq_mat.h": | ||
fmpq * fmpq_mat_entry(const fmpq_mat_t mat, long i, long j) | ||
fmpz * fmpq_mat_entry_num(const fmpq_mat_t mat, long i, long j) | ||
fmpz * fmpq_mat_entry_den(const fmpq_mat_t mat, long i, long j) | ||
long fmpq_mat_nrows(const fmpq_mat_t mat) | ||
long fmpq_mat_ncols(const fmpq_mat_t mat) | ||
void fmpq_mat_init(fmpq_mat_t mat, long rows, long cols) | ||
void fmpq_mat_clear(fmpq_mat_t mat) | ||
void fmpq_mat_swap(fmpq_mat_t mat1, fmpq_mat_t mat2) | ||
void fmpq_mat_window_init(fmpq_mat_t window, const fmpq_mat_t mat, long r1, long c1, long r2, long c2) | ||
void fmpq_mat_window_clear(fmpq_mat_t window) | ||
void fmpq_mat_concat_horizontal(fmpq_mat_t res, const fmpq_mat_t mat1, const fmpq_mat_t mat2) | ||
void fmpq_mat_concat_vertical(fmpq_mat_t res, const fmpq_mat_t mat1, const fmpq_mat_t mat2) | ||
void fmpq_mat_print(const fmpq_mat_t mat) | ||
void fmpq_mat_randbits(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits) | ||
void fmpq_mat_randtest(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits) | ||
void fmpq_mat_hilbert_matrix(fmpq_mat_t mat) | ||
void fmpq_mat_set(fmpq_mat_t dest, const fmpq_mat_t src) | ||
void fmpq_mat_zero(fmpq_mat_t mat) | ||
void fmpq_mat_one(fmpq_mat_t mat) | ||
void fmpq_mat_transpose(fmpq_mat_t rop, const fmpq_mat_t op) | ||
void fmpq_mat_add(fmpq_mat_t mat, const fmpq_mat_t mat1, const fmpq_mat_t mat2) | ||
void fmpq_mat_sub(fmpq_mat_t mat, const fmpq_mat_t mat1, const fmpq_mat_t mat2) | ||
void fmpq_mat_neg(fmpq_mat_t rop, const fmpq_mat_t op) | ||
void fmpq_mat_scalar_mul_fmpz(fmpq_mat_t rop, const fmpq_mat_t op, const fmpz_t x) | ||
void fmpq_mat_scalar_div_fmpz(fmpq_mat_t rop, const fmpq_mat_t op, const fmpz_t x) | ||
bint fmpq_mat_equal(const fmpq_mat_t mat1, const fmpq_mat_t mat2) | ||
bint fmpq_mat_is_integral(const fmpq_mat_t mat) | ||
bint fmpq_mat_is_zero(const fmpq_mat_t mat) | ||
bint fmpq_mat_is_empty(const fmpq_mat_t mat) | ||
bint fmpq_mat_is_square(const fmpq_mat_t mat) | ||
int fmpq_mat_get_fmpz_mat(fmpz_mat_t dest, const fmpq_mat_t mat) | ||
void fmpq_mat_get_fmpz_mat_entrywise(fmpz_mat_t num, fmpz_mat_t den, const fmpq_mat_t mat) | ||
void fmpq_mat_get_fmpz_mat_matwise(fmpz_mat_t num, fmpz_t den, const fmpq_mat_t mat) | ||
void fmpq_mat_get_fmpz_mat_rowwise(fmpz_mat_t num, fmpz * den, const fmpq_mat_t mat) | ||
void fmpq_mat_get_fmpz_mat_colwise(fmpz_mat_t num, fmpz * den, const fmpq_mat_t mat) | ||
void fmpq_mat_get_fmpz_mat_rowwise_2(fmpz_mat_t num, fmpz_mat_t num2, fmpz * den, const fmpq_mat_t mat, const fmpq_mat_t mat2) | ||
void fmpq_mat_get_fmpz_mat_mod_fmpz(fmpz_mat_t dest, const fmpq_mat_t mat, const fmpz_t mod) | ||
void fmpq_mat_set_fmpz_mat(fmpq_mat_t dest, const fmpz_mat_t src) | ||
void fmpq_mat_set_fmpz_mat_div_fmpz(fmpq_mat_t X, const fmpz_mat_t Xmod, const fmpz_t div) | ||
int fmpq_mat_set_fmpz_mat_mod_fmpz(fmpq_mat_t X, const fmpz_mat_t Xmod, const fmpz_t mod) | ||
void fmpq_mat_mul_direct(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B) | ||
void fmpq_mat_mul_cleared(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B) | ||
void fmpq_mat_mul(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B) | ||
void fmpq_mat_mul_fmpz_mat(fmpq_mat_t C, const fmpq_mat_t A, const fmpz_mat_t B) | ||
void fmpq_mat_mul_r_fmpz_mat(fmpq_mat_t C, const fmpz_mat_t A, const fmpq_mat_t B) | ||
void fmpq_mat_trace(fmpq_t trace, const fmpq_mat_t mat) | ||
void fmpq_mat_det(fmpq_t det, const fmpq_mat_t mat) | ||
int fmpq_mat_solve_fraction_free(fmpq_mat_t X, const fmpq_mat_t A, const fmpq_mat_t B) | ||
int fmpq_mat_solve_dixon(fmpq_mat_t X, const fmpq_mat_t A, const fmpq_mat_t B) | ||
int fmpq_mat_solve_fmpz_mat(fmpq_mat_t X, const fmpz_mat_t A, const fmpz_mat_t B) | ||
int fmpq_mat_inv(fmpq_mat_t B, const fmpq_mat_t A) | ||
int fmpq_mat_pivot(long * perm, fmpq_mat_t mat, long r, long c) | ||
long fmpq_mat_rref_classical(fmpq_mat_t B, const fmpq_mat_t A) | ||
long fmpq_mat_rref_fraction_free(fmpq_mat_t B, const fmpq_mat_t A) | ||
long fmpq_mat_rref(fmpq_mat_t B, const fmpq_mat_t A) | ||
void fmpq_mat_gso(fmpq_mat_t B, const fmpq_mat_t A) | ||
|
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
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
from cypari2.types cimport GEN | ||
from cypari2.gen cimport Gen | ||
from sage.libs.flint.types cimport fmpz_t, fmpz_mat_t | ||
from sage.libs.flint.types cimport fmpz_t, fmpz_mat_t, fmpq_t, fmpq_mat_t | ||
|
||
cdef GEN _new_GEN_from_fmpz_t(fmpz_t value) | ||
cdef GEN _new_GEN_from_fmpz_mat_t(fmpz_mat_t B, Py_ssize_t nr, Py_ssize_t nc) | ||
cdef GEN _new_GEN_from_fmpz_mat_t_rotate90(fmpz_mat_t B, Py_ssize_t nr, Py_ssize_t nc) | ||
cdef Gen integer_matrix(fmpz_mat_t B, Py_ssize_t nr, Py_ssize_t nc, bint permute_for_hnf) | ||
cdef GEN _new_GEN_from_fmpz_mat_t(fmpz_mat_t B) | ||
cdef GEN _new_GEN_from_fmpz_mat_t_rotate90(fmpz_mat_t B) | ||
cdef Gen integer_matrix(fmpz_mat_t B, bint rotate) | ||
|
||
cdef GEN _new_GEN_from_fmpq_t(fmpq_t value) | ||
cdef GEN _new_GEN_from_fmpq_mat_t(fmpq_mat_t B) | ||
cdef GEN _new_GEN_from_fmpq_mat_t_rotate90(fmpq_mat_t B) | ||
cdef Gen rational_matrix(fmpq_mat_t B, bint rotate) |
Oops, something went wrong.