Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/libs/linbox/matrix_rational_dense_linbox.cpp
4048 views
1
#include<iostream>
2
3
#include "gmp.h"
4
#include "matrix_rational_dense_linbox.h"
5
#include "linbox/integer.h"
6
#include "linbox/matrix/blas-matrix.h"
7
#include "linbox/matrix/matrix-domain.h"
8
#include "linbox/field/gmp-rational.h"
9
#include "linbox/blackbox/dense.h"
10
#include "linbox/algorithms/echelon-form.h"
11
//#include "linbox/field/givaro-rational.h"
12
#include "linbox/field/modular.h"
13
14
15
using namespace LinBox;
16
using namespace std;
17
18
GMPRationalField QQ;
19
SpyInteger spy;
20
21
void new_gmp_matrix(DenseMatrix<GMPRationalField>& A, mpq_t** matrix, size_t nrows, size_t ncols) {
22
size_t i, j;
23
for (i=0; i < nrows; i++) {
24
for (j=0; j < ncols; j++) {
25
GMPRationalField::Element t;
26
t = A.getEntry(i, j);
27
integer x;
28
mpz_set(spy.get_mpz(QQ.get_num(x, t)), mpq_numref(matrix[i][j]));
29
mpz_set(spy.get_mpz(QQ.get_den(x, t)), mpq_denref(matrix[i][j]));
30
A.setEntry(i, j, t);
31
}
32
}
33
}
34
35
void linbox_rational_dense_echelon_form_2(mpq_t** matrix, size_t nr, size_t nc)
36
{
37
/* EchelonFormDomain<GMPRationalField> EF(QQ);
38
DenseMatrix<GMPRationalField> A(QQ,nr, nc);
39
DenseMatrix<GMPRationalField> E(QQ,nr, nc);
40
new_gmp_matrix(A, matrix, nr, nc);
41
cout << "made matrix\n";
42
EF.rowEchelon(E, A); */
43
}
44
45
typedef Modular<int> ModInt;
46
ModInt F(32771);
47
48
void linbox_rational_dense_echelon_form(mpq_t** matrix, size_t nr, size_t nc)
49
{
50
EchelonFormDomain< ModInt > EF(F);
51
DenseMatrix<ModInt> A(F,nr, nc);
52
DenseMatrix<ModInt> E(F,nr, nc);
53
size_t k;
54
k = 19;
55
for (size_t i=0; i < nr; i++)
56
for (size_t j=0; j < nc; j++) {
57
A.setEntry(i,j,5+i*i+j-j*j+i*i*i+k*k);
58
k += i*i + j*j + 17;
59
}
60
// new_gmp_matrix(A, matrix, nr, nc);
61
cout << "made matrix\n";
62
EF.rowEchelon(E, A);
63
cout << "did echelon\n";
64
}
65
66