14 const DMatZZpFFPACK::ElementType& a,
23 FFLAS::FFLAS_TRANSPOSE tA = FFLAS::FflasNoTrans;
24 FFLAS::FFLAS_TRANSPOSE tB = FFLAS::FflasNoTrans;
26 size_t m = A.numRows();
27 size_t k = A.numColumns();
28 assert(A.numColumns() == B.numRows());
29 size_t n = B.numColumns();
31 assert(C.numRows() == m);
32 assert(C.numColumns() == n);
34 DMatZZpFFPACK::ElementType b;
36 C.ring().set_from_long(b, 1);
37 FFLAS::fgemm(C.ring().field(),
57 DMatZZpFFPACK::ElementType one;
58 A.ring().set_from_long(one, 1);
84 size_t result = FFPACK::Rank(mat.ring().field(),
95 if (mat.numRows() == 0)
99 mat.ring().set_from_long(result_det, 1);
105 result_det = FFPACK::Det(mat.ring().field(),
115 assert(mat.numRows() == mat.numColumns());
116 result_inv.resize(mat.numRows(), mat.numRows());
118 assert(result_inv.numRows() == mat.numRows());
119 assert(result_inv.numColumns() == mat.numRows());
121 if (mat.numRows() == 0)
129 size_t n = mat.numRows();
132 mat.ring().field(), n, N.rowMajorArray(), n, result_inv.rowMajorArray(), n, nullspacedim);
133 return (nullspacedim == 0);
138 bool right_side =
true;
143 size_t nr = mat.numRows();
144 size_t nc = mat.numColumns();
146 DMatZZpFFPACK::ElementType* nullspaceFFPACK =
nullptr;
148 size_t nullspace_dim;
149 size_t nullspace_leading_dim;
151 FFPACK::NullSpaceBasis(mat.ring().field(),
152 (right_side ? FFLAS::FflasRight : FFLAS::FflasLeft),
158 nullspace_leading_dim,
163 if (right_side && nullspace_dim != nullspace_leading_dim)
165 std::cerr <<
"error: this should not happen!" << std::endl;
167 else if (!right_side && nullspace_leading_dim != nc)
169 std::cerr <<
"error: this should not happen either!" << std::endl;
173 nullspace.resize(nc, nullspace_dim);
175 nullspace.resize(nullspace_dim, nr);
177 std::swap(nullspace.rowMajorArray(), nullspaceFFPACK);
179 delete[] nullspaceFFPACK;
180 return nullspace_dim;
187 bool declare_A_is_invertible)
190 (void) declare_A_is_invertible;
191 size_t a_rows = A.numRows();
192 size_t a_cols = A.numColumns();
194 size_t b_rows = B.numRows();
195 size_t b_cols = B.numColumns();
201 size_t x_rows = (right_side ? a_cols : b_rows);
202 size_t x_cols = (right_side ? b_cols : a_rows);
204 X.resize(x_rows, x_cols);
208 FFPACK::fgesv(A.ring().field(),
209 (right_side ? FFLAS::FflasLeft : FFLAS::FflasRight),
212 (right_side ? b_cols : b_rows),
213 copyA.rowMajorArray(),
217 copyB.rowMajorArray(),
245 rk = FFPACK::RowRankProfile(mat.ring().field(),
252 rk = FFPACK::ColumnRankProfile(mat.ring().field(),
260 for (
size_t i = 0; i < rk; i++) profile->array[i] =
static_cast<int>(prof[i]);
268 std::vector<size_t>& result_profile)
276 rk = FFPACK::RowRankProfile(mat.ring().field(),
283 rk = FFPACK::ColumnRankProfile(mat.ring().field(),
290 result_profile.resize(0);
291 for (
size_t i = 0; i < rk; i++) result_profile.push_back(prof[i]);
FieldType::Element ElementType
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_makearrayint(int n)
M2_arrayint M2_arrayintOrNull
Templated DMat<R> linear algebra: LU, rank, determinant, solve, inverse, nullSpace.
void subtractMultipleTo(DMatZZpFFPACK &C, const DMatZZpFFPACK &A, const DMatZZpFFPACK &B)
void addMultipleTo(DMatZZpFFPACK &C, const DMatZZpFFPACK::ElementType &a, const DMatZZpFFPACK &A, const DMatZZpFFPACK &B)
void mult(const DMatZZpFFPACK &A, const DMatZZpFFPACK &B, DMatZZpFFPACK &C)
void determinant(const DMatZZpFFPACK &A, ZZpFFPACK::ElementType &result_det)
bool inverse(const DMatZZpFFPACK &A, DMatZZpFFPACK &result_inv)
size_t rank(const DMatZZpFFPACK &A)
size_t nullSpace(const DMatZZpFFPACK &A, DMatZZpFFPACK &result_nullspace)
M2_arrayintOrNull rankProfile(const DMatZZpFFPACK &A, bool row_profile)
bool solveLinear(const DMatZZpFFPACK &A, const DMatZZpFFPACK &B, DMatZZpFFPACK &X)
void swap(mpfr::mpreal &x, mpfr::mpreal &y)