Macaulay2 Engine
Loading...
Searching...
No Matches
mutablemat-defs.hpp
Go to the documentation of this file.
1// Copyright 2005-2012 Michael E. Stillman
2
3#ifndef _mutable_mat_defs_hpp_
4#define _mutable_mat_defs_hpp_
5
43
44#include <iostream>
45#include "mat.hpp"
46
47namespace M2 {
48class ARingZZp;
49class ARingRR;
50class ARingCC;
51class ARingRRR;
52class ARingCCC;
53};
54
55template <typename RT>
56class DMat;
57template <typename RT>
58class SMat;
59template <typename MT>
60bool isDense(const MT& mat);
61template <typename RT>
62bool isDense(const DMat<RT>& mat)
63{
64 (void) mat;
65 return true;
66}
67template <typename RT>
68bool isDense(const SMat<RT>& mat)
69{
70 (void) mat;
71 return false;
72}
73
74template <typename RT>
76{
77 typedef RT EigenvalueType;
78 typedef RT EigenvectorType;
81};
82
93template <>
101
111template <>
119
130template <>
138
149template <>
157
158// The following include file is for creating a Matrix, in "toMatrix"
159#include "matrix-con.hpp"
160
161#include "dmat.hpp"
162#include "smat.hpp"
163#include "mat-elem-ops.hpp"
164#include "mat-arith.hpp"
165#include "mat-linalg.hpp"
166
167template <typename CoeffRing>
169{
170 int nrows = static_cast<int>(A.numRows());
171 int ncols = static_cast<int>(A.numColumns());
172 FreeModule* F = R->make_FreeModule(nrows);
173 MatrixConstructor result(F, ncols);
174 if (nrows == 0 || ncols == 0) return result.to_matrix();
175
176 for (int r = 0; r < nrows; ++r)
177 for (int c = 0; c < ncols; ++c)
178 {
179 const typename CoeffRing::ElementType & a = A.entry(r,c);
180 if (not A.ring().is_zero(a))
181 {
182 ring_elem ra;
183 A.ring().to_ring_elem(ra, a);
184 result.set_entry(r, c, ra);
185 }
186 }
187
188 result.compute_column_degrees();
189 return result.to_matrix();
190}
191template <typename CoeffRing>
193{
194 int nrows = static_cast<int>(A.numRows());
195 int ncols = static_cast<int>(A.numColumns());
196 FreeModule* F = R->make_FreeModule(nrows);
197 MatrixConstructor result(F, ncols);
198 if (nrows == 0 || ncols == 0) return result.to_matrix();
199 ring_elem f;
200 auto i = A.begin();
201 for (int c = 0; c < ncols; c++)
202 {
203 ring_elem a;
204 for (i.set(c); i.valid(); i.next())
205 {
206 i.copy_elem(a);
207 int r = static_cast<int>(i.row());
208 result.set_entry(r, c, a);
209 }
210 }
211 result.compute_column_degrees();
212 return result.to_matrix();
213}
214
215inline bool error_column_bound(size_t c, size_t ncols)
216{
217 if (c >= ncols)
218 {
219 ERROR("column out of range");
220 return true;
221 }
222 return false;
223}
224
225inline bool error_row_bound(size_t r, size_t nrows)
226{
227 if (r >= nrows)
228 {
229 ERROR("row out of range");
230 return true;
231 }
232 return false;
233}
234
238
239template <typename Mat>
241{
242 public:
243 typedef Mat MatType;
244 typedef typename Mat::CoeffRing CoeffRing;
245 typedef typename CoeffRing::elem elem;
246 typedef typename CoeffRing::Element Element;
247 typedef typename CoeffRing::ElementType ElementType;
248
250
257
258 private:
259 const Ring* mRing;
260 Mat mat;
261 // This class wraps the operations for Mat to make a MutableMatrix
262
263 // Same operations as in MutableMatrix. Almost nothing is
264 // done except to call the Mat routines.
265
267 MutableMat(const Ring* R, const Mat& m) : mRing(R), mat(m) {}
268 public:
269 // This constructor makes a zero matrix
270 MutableMat(const Ring* R, const CoeffRing* coeffR, size_t nrows, size_t ncols)
271 : mRing(R), mat(*coeffR, nrows, ncols)
272 {
273 }
274
275 // Make a zero matrix, using the same ring and density taken from 'mat'.
276 MutableMat* makeZeroMatrix(size_t nrows, size_t ncols) const
277 {
278 return new MutableMat(get_ring(), &mat.ring(), nrows, ncols);
279 }
280
281 Mat* get_Mat() { return &mat; }
282 const Mat* get_Mat() const { return &mat; }
283 Mat& getMat() { return mat; }
284 const Mat& getMat() const { return mat; }
285#if 0
286 // MESXXX
287 class iterator : public MutableMatrix::iterator
288 {
289 typename Mat::iterator i;
290 public:
291 iterator(const Mat *M0) : i(M0) {}
292 void set(size_t col0) { i.set(col0); }
293 void next() { i.next(); }
294 bool valid() { return i.valid(); }
295 size_t row() { return i.row(); }
296 const elem& value() { return i.value(); }
297 void copy_ring_elem(ring_elem &result) { i.copy_elem(result); }
298 };
299#endif
300#if 0
301 // MESXXX
302 virtual iterator * begin() const { return new iterator(&mat); }
303#endif
304 virtual const Ring* get_ring() const { return mRing; }
305 virtual size_t n_rows() const { return mat.numRows(); }
306 virtual size_t n_cols() const { return mat.numColumns(); }
307 virtual bool is_dense() const { return isDense(mat); }
308 virtual Matrix* to_matrix() const { return toMatrix(get_ring(), mat); }
309 virtual MutableMat* copy(bool prefer_dense) const
310 {
311#if 0
313 Mat *m = mat.copy();
314 result->mat.grab(m);
315 return result;
316#endif
317 (void) prefer_dense;
318 return clone();
319 }
320
321 virtual MutableMat* clone() const
322 {
324 return result;
325 // result->mat.copy(mat);
326 // Mat *m = new Mat(mat); // copies mat
327 // return new MutableMat(*m); // places copy into result
328 }
329
330 virtual size_t lead_row(size_t col) const
331 {
332 return MatOps::lead_row(mat, col);
333 }
334 /* returns the largest index row which has a non-zero value in column 'col'.
335 returns -1 if the column is 0 */
336
337 virtual size_t lead_row(size_t col, ring_elem& result) const
338 /* returns the largest index row which has a non-zero value in column 'col'.
339 Also sets result to be the entry at this index.
340 returns -1 if the column is 0 */
341 {
342 Element b(mat.ring());
343 mat.ring().set_zero(b);
344
345 size_t ret = MatOps::lead_row(mat, col, b);
346 if (ret != static_cast<size_t>(-1)) mat.ring().to_ring_elem(result, b);
347
348 return ret;
349 }
350
351 virtual bool get_entry(size_t r, size_t c, ring_elem& result) const
352 // Returns false if (r,c) is out of range or if result is 0. No error
353 // is returned. result <-- this(r,c), and is set to zero if false is returned.
354 {
355 if (r < n_rows() && c < n_cols())
356 {
357 Element a(mat.ring());
358
359 MatOps::getEntry(mat, r, c, a);
360 bool is_nonzero = not mat.ring().is_zero(a);
361 mat.ring().to_ring_elem(result, a);
362 return is_nonzero;
363 }
364
365 result = get_ring()->zero();
366 return false;
367 }
368
369 virtual bool set_entry(size_t r, size_t c, const ring_elem a)
370 // Returns false if (r,c) is out of range, or the ring of a is wrong.
371 {
372 if (error_row_bound(r, n_rows())) return false;
373 if (error_column_bound(c, n_cols())) return false;
374 const ElementType& b = mat.ring().from_ring_elem_const(a);
375 MatOps::setEntry(mat, r, c, b);
376 return true;
377 }
378
380 // Row and column operations //
382 // The following routines return false if one of the row or columns given
383 // is out of range.
384
385 virtual bool interchange_rows(size_t i, size_t j)
386 /* swap rows: row(i) <--> row(j) */
387 {
388 size_t nrows = n_rows();
389 if (error_row_bound(i, nrows) || error_row_bound(j, nrows)) return false;
390 MatOps::interchange_rows(mat, i, j);
391 return true;
392 }
393
394 virtual bool interchange_columns(size_t i, size_t j)
395 /* swap columns: column(i) <--> column(j) */
396 {
397 size_t ncols = n_cols();
398 if (error_column_bound(i, ncols) || error_column_bound(j, ncols))
399 return false;
400 MatOps::interchange_columns(mat, i, j);
401 return true;
402 }
403
404 virtual bool scale_row(size_t i, ring_elem r)
405 /* row(i) <- r * row(i) */
406 {
407 size_t nrows = n_rows();
408 if (error_row_bound(i, nrows)) return false;
409 const ElementType& b = mat.ring().from_ring_elem_const(r);
410 MatOps::scale_row(mat, i, b);
411 return true;
412 }
413
414 virtual bool scale_column(size_t i, ring_elem r)
415 /* column(i) <- r * column(i) */
416 {
417 size_t ncols = n_cols();
418 if (error_column_bound(i, ncols)) return false;
419 const ElementType& b = mat.ring().from_ring_elem_const(r);
420 MatOps::scale_column(mat, i, b);
421 return true;
422 }
423
424 virtual bool divide_row(size_t i, ring_elem r)
425 /* row(i) <- row(i) / r */
426 {
427 size_t nrows = n_rows();
428 if (error_row_bound(i, nrows)) return false;
429 const ElementType& b = mat.ring().from_ring_elem_const(r);
430 MatOps::divide_row(mat, i, b);
431 return true;
432 }
433
434 virtual bool divide_column(size_t i, ring_elem r)
435 /* column(i) <- column(i) / r */
436 {
437 size_t ncols = n_cols();
438 if (error_column_bound(i, ncols)) return false;
439 const ElementType& b = mat.ring().from_ring_elem_const(r);
440 MatOps::divide_column(mat, i, b);
441 return true;
442 }
443
444 virtual bool row_op(size_t i, ring_elem r, size_t j)
445 /* row(i) <- row(i) + r * row(j) */
446 {
447 size_t nrows = n_rows();
448 if (error_row_bound(i, nrows) || error_row_bound(j, nrows)) return false;
449 if (i == j) return true;
450 const ElementType& b = mat.ring().from_ring_elem_const(r);
451 MatOps::row_op(mat, i, b, j);
452 return true;
453 }
454
455 virtual bool column_op(size_t i, ring_elem r, size_t j)
456 /* column(i) <- column(i) + r * column(j) */
457 {
458 size_t ncols = n_cols();
459 if (error_column_bound(i, ncols) || error_column_bound(j, ncols))
460 return false;
461 if (i == j) return true;
462 const ElementType& b = mat.ring().from_ring_elem_const(r);
463 MatOps::column_op(mat, i, b, j);
464 return true;
465 }
466
467 virtual bool column2by2(size_t c1,
468 size_t c2,
469 ring_elem a1,
470 ring_elem a2,
471 ring_elem b1,
472 ring_elem b2)
473 /* column(c1) <- a1 * column(c1) + a2 * column(c2),
474 column(c2) <- b1 * column(c1) + b2 * column(c2)
475 */
476 {
477 size_t ncols = n_cols();
478 if (error_column_bound(c1, ncols) || error_column_bound(c2, ncols))
479 return false;
480 if (c1 == c2) return true;
481 const ElementType& aa1 = mat.ring().from_ring_elem_const(a1);
482 const ElementType& aa2 = mat.ring().from_ring_elem_const(a2);
483 const ElementType& bb1 = mat.ring().from_ring_elem_const(b1);
484 const ElementType& bb2 = mat.ring().from_ring_elem_const(b2);
485 MatOps::column2by2(mat, c1, c2, aa1, aa2, bb1, bb2);
486 return true;
487 }
488
489 virtual bool row2by2(size_t r1,
490 size_t r2,
491 ring_elem a1,
492 ring_elem a2,
493 ring_elem b1,
494 ring_elem b2)
495 /* row(r1) <- a1 * row(r1) + a2 * row(r2),
496 row(r2) <- b1 * row(r1) + b2 * row(r2)
497 */
498 {
499 size_t nrows = n_rows();
500 if (error_row_bound(r1, nrows) || error_row_bound(r2, nrows)) return false;
501 if (r1 == r2) return true;
502 const ElementType& aa1 = mat.ring().from_ring_elem_const(a1);
503 const ElementType& aa2 = mat.ring().from_ring_elem_const(a2);
504 const ElementType& bb1 = mat.ring().from_ring_elem_const(b1);
505 const ElementType& bb2 = mat.ring().from_ring_elem_const(b2);
506 MatOps::row2by2(mat, r1, r2, aa1, aa2, bb1, bb2);
507 return true;
508 }
509
510 virtual bool dot_product(size_t c1, size_t c2, ring_elem& result) const
511 {
512 size_t ncols = n_cols();
513 if (error_column_bound(c1, ncols) || error_column_bound(c2, ncols))
514 return false;
515 Element a(mat.ring());
516 mat.ring().set_zero(a);
517 MatOps::dot_product(mat, c1, c2, a);
518 mat.ring().to_ring_elem(result, a);
519 return true;
520 }
521
522 virtual bool row_permute(size_t start_row, M2_arrayint perm)
523 {
524 return MatOps::row_permute(mat, start_row, perm);
525 }
526
527 virtual bool column_permute(size_t start_col, M2_arrayint perm)
528 {
529 return MatOps::column_permute(mat, start_col, perm);
530 }
531
532 virtual bool insert_columns(size_t i, size_t n_to_add)
533 /* Insert n_to_add columns directly BEFORE column i. */
534 {
535 if (i > n_cols())
536 {
537 ERROR("cannot insert %l columns before column %ln", n_to_add, i);
538 return false;
539 }
540 MatOps::insert_columns(mat, i, n_to_add);
541 return true;
542 }
543
544 virtual bool insert_rows(size_t i, size_t n_to_add)
545 /* Insert n_to_add rows directly BEFORE row i. */
546 {
547 if (i > n_rows())
548 {
549 ERROR("cannot insert %l rows before row %ln", n_to_add, i);
550 return false;
551 }
552 MatOps::insert_rows(mat, i, n_to_add);
553 return true;
554 }
555
556 virtual bool delete_columns(size_t i, size_t j)
557 /* Delete columns i .. j from M */
558 {
559 size_t ncols = n_cols();
560 if (error_column_bound(i, ncols) || error_column_bound(j, ncols))
561 {
562 ERROR("column index out of range");
563 return false;
564 }
565
566 MatOps::delete_columns(mat, i, j);
567 return true;
568 }
569
570 virtual bool delete_rows(size_t i, size_t j)
571 /* Delete rows i .. j from M */
572 {
573 size_t nrows = n_rows();
574 if (error_row_bound(i, nrows) || error_row_bound(j, nrows))
575 {
576 ERROR("row index out of range");
577 return false;
578 }
579 MatOps::delete_rows(mat, i, j);
580 return true;
581 }
582
583 virtual void reduce_by_pivots() { MatOps::reduce_by_pivots(mat); }
585 {
586 for (size_t r = 0; r < rows->len; r++)
587 if (rows->array[r] < 0 || rows->array[r] >= n_rows())
588 {
589 ERROR(
590 "row index %d out of bounds 0..%d", rows->array[r], n_rows() - 1);
591 return 0;
592 }
593 for (size_t c = 0; c < cols->len; c++)
594 if (cols->array[c] < 0 || cols->array[c] >= n_cols())
595 {
596 ERROR("column index %d out of bounds 0..%d",
597 cols->array[c],
598 n_cols() - 1);
599 return 0;
600 }
601 MutableMat* result = makeZeroMatrix(rows->len, cols->len);
602 MatOps::setFromSubmatrix(getMat(), rows, cols, result->getMat());
603 return result;
604 }
605
607 {
608 for (size_t c = 0; c < cols->len; c++)
609 if (cols->array[c] < 0 || cols->array[c] >= n_cols())
610 {
611 ERROR("column index %d out of bounds 0..%d",
612 cols->array[c],
613 n_cols() - 1);
614 return 0;
615 }
616 MutableMat* result = makeZeroMatrix(n_rows(), cols->len);
617 MatOps::setFromSubmatrix(getMat(), cols, result->getMat());
618 return result;
619 }
620
622 // promote, lift, eval ////////
624
625 virtual MutableMatrix* promote(const Ring* S) const
626 {
627 (void) S;
628 return 0;
629 }
630
631 virtual MutableMatrix* lift(const Ring* R) const
632 {
633 (void) R;
634 return 0;
635 }
636
637 virtual MutableMatrix* eval(const RingMap* F) const
638 {
639 (void) F;
640 return 0;
641 }
642
644 // Matrix operations //////////
646
647 virtual bool is_zero() const { return MatrixOps::isZero(getMat()); }
648 virtual bool is_equal(const MutableMatrix* B) const
649 {
650 const MutableMat* B1 = dynamic_cast<const MutableMat*>(B);
651 if (B1 == NULL || &B1->getMat().ring() != &getMat().ring()) return false;
652 return MatrixOps::isEqual(getMat(), B1->getMat());
653 }
654
655 virtual MutableMat* add(const MutableMatrix* B) const
656 // return this + B. return NULL if sizes or types do not match.
657 {
658 const Mat* B1 = B->coerce_const<Mat>();
659 if (B1 == NULL)
660 {
661 ERROR("expected matrices with the same ring and sparsity");
662 return NULL;
663 }
664 if (B->get_ring() != get_ring())
665 {
666 ERROR("expected matrices with the same ring");
667 return NULL;
668 }
669 if (B1->numRows() != n_rows() || B1->numColumns() != n_cols())
670 {
671 ERROR("expected matrices of the same shape");
672 return NULL;
673 }
674
676 MatrixOps::addInPlace(result->getMat(), *B1);
677 return result;
678 }
679
680 virtual MutableMatrix* negate() const
681 {
684 return result;
685 }
686
687 virtual MutableMat* subtract(const MutableMatrix* B) const
688 // return this - B. return NULL of sizes or types do not match.
689 {
690 const Mat* B1 = B->coerce_const<Mat>();
691 if (B1 == NULL)
692 {
693 ERROR("expected matrices with the same ring and sparsity");
694 return NULL;
695 }
696 if (B->get_ring() != get_ring())
697 {
698 ERROR("expected matrices with the same ring");
699 return NULL;
700 }
701 if (B1->numRows() != n_rows() || B1->numColumns() != n_cols())
702 {
703 ERROR("expected matrices of the same shape");
704 return NULL;
705 }
706
708 MatrixOps::subtractInPlace(result->getMat(), *B1);
709 return result;
710 }
711
712 virtual MutableMat* mult(const RingElement* f) const
713 // return f*this. return NULL of sizes or types do not match.
714 {
715 if (f->get_ring() != get_ring())
716 {
717 ERROR("expected same ring");
718 return 0;
719 }
720 const ElementType& a = mat.ring().from_ring_elem_const(f->get_value());
721
724
725 return result;
726 }
727
728 virtual MutableMat /* or null */* transpose() const
729 {
731 MatrixOps::transpose(getMat(), result->getMat());
732 return result;
733 }
734
736 // Linear algebra /////////////
738
739 virtual M2_arrayintOrNull LU(MutableMatrix* L, MutableMatrix* U) const;
740
741 virtual M2_arrayintOrNull LUincremental(std::vector<size_t>& P, const MutableMatrix* v, int i);
742
743 virtual void triangularSolve(MutableMatrix* x, int m, int strategy);
744
745 virtual bool eigenvalues(MutableMatrix* eigenvals,
746 bool is_symm_or_hermitian) const;
747
748 virtual bool eigenvectors(MutableMatrix* eigenvals,
749 MutableMatrix* eigenvecs,
750 bool is_symm_or_hermitian) const;
751
752 virtual bool SVD(MutableMatrix* Sigma,
753 MutableMatrix* U,
754 MutableMatrix* Vt,
755 bool use_divide_and_conquer) const;
756
757 virtual bool least_squares(const MutableMatrix* b,
759 bool assume_full_rank) const;
760
761 virtual bool QR(MutableMatrix* Q, MutableMatrix* R, bool return_QR) const;
762
764
766
767 virtual size_t rank() const;
768
769 virtual const RingElement* determinant() const;
770
771 // Find the inverse matrix. If the matrix is not square, or
772 // the ring is one in which th matrix cannot be inverted,
773 // then NULL is returned, and an error message is set.
774 virtual MutableMatrix* invert() const;
775
776 virtual MutableMatrix* rowReducedEchelonForm() const;
777
778 // Returns an array of increasing integers {n_1, n_2, ...}
779 // such that if M is the matrix with rows (resp columns, if row_profile is
780 // false)
781 // then rank(M_{0..n_i-1}) + 1 = rank(M_{0..n_i}).
782 // NULL is returned, and an error is set, if this function is not available
783 // for the given choice of ring and dense/sparseness.
784 virtual M2_arrayintOrNull rankProfile(bool row_profile) const;
785
786 // Find a spanning set for the null space. If M = this,
787 // return a matrix whose columns span {x | Mx = 0}
788 virtual MutableMatrix* nullSpace() const;
789
790 // Returns X, if (this=A) AX=B has a solution.
791 // Returns NULL, if not.
792 // Throws an exception if any other usage issues arise (bad rings, sizes, not
793 // implemented...)
794 virtual MutableMatrix* solveLinear(const MutableMatrix* B) const;
795
796 // Returns X, if this=A is invertible, and AX=B. (so X is uniquely determined)
797 // Returns NULL, if A is not invertible.
798 // Throws an exception if any other usage issues arise.
799 virtual MutableMatrix* solveInvertible(const MutableMatrix* B) const;
800
801 virtual void addMultipleTo(const MutableMatrix* A, const MutableMatrix* B);
802
803 virtual void subtractMultipleTo(const MutableMatrix* A,
804 const MutableMatrix* B);
805
806 virtual MutableMatrix /* or null */* mult(const MutableMatrix* B) const;
807
808 // Special routines for approximate fields
809 virtual void clean(gmp_RR epsilon); // modifies 'this'
810 virtual gmp_RRorNull norm() const;
811
813 M2SLProgram* P,
814 M2_arrayint constsPos,
815 M2_arrayint varsPos) const; // this = const matrix
816
818 M2_string libName,
819 int nInputs,
820 int nOutputs) const; // this = const matrix
821};
822
823#endif
824
825// Local Variables:
826// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
827// indent-tabs-mode: nil
828// End:
size_t numRows() const
Definition dmat.hpp:144
ElementType & entry(size_t row, size_t column)
Definition dmat.hpp:148
const ACoeffRing & ring() const
Definition dmat.hpp:143
size_t numColumns() const
Definition dmat.hpp:145
Definition dmat.hpp:62
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
aring-style adapter for arbitrary-precision complex numbers, stored as (MPFR, MPFR) pairs.
Definition aring-CCC.hpp:71
aring-style adapter for double-precision complex numbers, stored as (double, double) pairs.
Definition aring-CC.hpp:72
aring-style adapter for double-precision real numbers.
Definition aring-RR.hpp:62
aring-style adapter for arbitrary-precision real numbers, backed by MPFR.
Definition aring-RRR.hpp:70
aring-style adapter for Z/p using a discrete-log (Zech) representation: every non-zero residue is its...
Definition aring-zzp.hpp:67
MutableEngineObject wrapper holding a raw SLEvaluator*.
Definition SLP-defs.hpp:248
MutableEngineObject wrapper that owns an SLProgram via unique_ptr.
Definition SLP-defs.hpp:64
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
virtual M2SLEvaluator * createCompiledSLEvaluator(M2_string libName, int nInputs, int nOutputs) const
MutableMat(const Ring *R, const CoeffRing *coeffR, size_t nrows, size_t ncols)
virtual bool row2by2(size_t r1, size_t r2, ring_elem a1, ring_elem a2, ring_elem b1, ring_elem b2)
virtual bool eigenvalues(MutableMatrix *eigenvals, bool is_symm_or_hermitian) const
virtual size_t rank() const
Fast linear algebra routines (well, fast for some rings).
EigenTypes< CoeffRing >::HermitianEigenvectorType HermitianEigenvectorType
CoeffRing::ElementType ElementType
virtual bool delete_columns(size_t i, size_t j)
EigenTypes< CoeffRing >::HermitianEigenvalueType HermitianEigenvalueType
Mat::CoeffRing CoeffRing
virtual bool delete_rows(size_t i, size_t j)
virtual MutableMatrix * promote(const Ring *S) const
virtual const RingElement * determinant() const
EigenTypes< CoeffRing >::EigenvalueType EigenvalueType
virtual engine_RawArrayIntPairOrNull LQUPFactorizationInPlace(bool transpose)
LU decomposition routines /////.
virtual MutableMatrix * eval(const RingMap *F) const
virtual bool scale_column(size_t i, ring_elem r)
virtual bool QR(MutableMatrix *Q, MutableMatrix *R, bool return_QR) const
virtual M2_arrayintOrNull rankProfile(bool row_profile) const
virtual MutableMatrix * solveLinear(const MutableMatrix *B) const
virtual size_t n_rows() const
virtual MutableMat * copy(bool prefer_dense) const
virtual MutableMatrix * negate() const
MatElementaryOps< Mat > MatOps
virtual bool dot_product(size_t c1, size_t c2, ring_elem &result) const
virtual bool divide_row(size_t i, ring_elem r)
virtual bool scale_row(size_t i, ring_elem r)
virtual M2_arrayintOrNull LUincremental(std::vector< size_t > &P, const MutableMatrix *v, int i)
virtual MutableMat * add(const MutableMatrix *B) const
virtual bool insert_rows(size_t i, size_t n_to_add)
virtual bool get_entry(size_t r, size_t c, ring_elem &result) const
virtual M2SLEvaluator * createSLEvaluator(M2SLProgram *P, M2_arrayint constsPos, M2_arrayint varsPos) const
virtual size_t lead_row(size_t col) const
virtual gmp_RRorNull norm() const
const Ring * mRing
virtual void subtractMultipleTo(const MutableMatrix *A, const MutableMatrix *B)
virtual bool column_op(size_t i, ring_elem r, size_t j)
virtual MutableMatrix * nullSpace() const
virtual bool column_permute(size_t start_col, M2_arrayint perm)
virtual MutableMatrix * lift(const Ring *R) const
virtual void reduce_by_pivots()
virtual bool divide_column(size_t i, ring_elem r)
virtual size_t n_cols() const
virtual MutableMatrix * solveInvertible(const MutableMatrix *B) const
virtual bool column2by2(size_t c1, size_t c2, ring_elem a1, ring_elem a2, ring_elem b1, ring_elem b2)
virtual bool is_equal(const MutableMatrix *B) const
virtual bool least_squares(const MutableMatrix *b, MutableMatrix *x, bool assume_full_rank) const
virtual Matrix * to_matrix() const
virtual void addMultipleTo(const MutableMatrix *A, const MutableMatrix *B)
EigenTypes< CoeffRing >::EigenvectorType EigenvectorType
virtual bool is_zero() const
virtual bool set_entry(size_t r, size_t c, const ring_elem a)
virtual bool row_permute(size_t start_row, M2_arrayint perm)
virtual void clean(gmp_RR epsilon)
virtual MutableMat * clone() const
virtual bool row_op(size_t i, ring_elem r, size_t j)
virtual MutableMatrix * submatrix(M2_arrayint rows, M2_arrayint cols) const
virtual MutableMat * transpose() const
virtual MutableMat * mult(const RingElement *f) const
virtual size_t lead_row(size_t col, ring_elem &result) const
virtual bool SVD(MutableMatrix *Sigma, MutableMatrix *U, MutableMatrix *Vt, bool use_divide_and_conquer) const
virtual void triangularSolve(MutableMatrix *x, int m, int strategy)
const Mat & getMat() const
CoeffRing::elem elem
virtual const Ring * get_ring() const
virtual bool insert_columns(size_t i, size_t n_to_add)
MutableMat * makeZeroMatrix(size_t nrows, size_t ncols) const
virtual MutableMatrix * invert() const
virtual bool eigenvectors(MutableMatrix *eigenvals, MutableMatrix *eigenvecs, bool is_symm_or_hermitian) const
const Mat * get_Mat() const
virtual M2_arrayintOrNull LU(MutableMatrix *L, MutableMatrix *U) const
virtual bool interchange_rows(size_t i, size_t j)
CoeffRing::Element Element
virtual MutableMatrix * submatrix(M2_arrayint cols) const
virtual MutableMat * subtract(const MutableMatrix *B) const
virtual bool interchange_columns(size_t i, size_t j)
virtual bool is_dense() const
MutableMat(const Ring *R, const Mat &m)
virtual MutableMatrix * rowReducedEchelonForm() const
MutableMatrix()
Definition mat.hpp:81
Abstract base class for mutable matrices over an arbitrary engine Ring, the in-place counterpart of t...
Definition mat.hpp:79
virtual FreeModule * make_FreeModule() const
Definition ring.cpp:53
ring_elem zero() const
Definition ring.hpp:359
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
xxx xxx xxx
Definition ring.hpp:102
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
iterator begin() const
Definition smat.hpp:131
size_t numRows() const
Definition smat.hpp:99
size_t numColumns() const
Definition smat.hpp:100
Definition smat.hpp:43
DMat<ACoeffRing> — dense-matrix template plus the umbrella that wires in every per-ring specialisatio...
#define Matrix
Definition factory.cpp:14
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
mpfr_srcptr gmp_RR
Definition m2-types.h:148
M2_arrayint M2_arrayintOrNull
Definition m2-types.h:99
engine_RawArrayIntPair engine_RawArrayIntPairOrNull
Definition m2-types.h:188
mpfr_srcptr gmp_RRorNull
Definition m2-types.h:149
Templated matrix arithmetic for DMat<R> / SMat<R> plus the MatrixWindow / SubMatrix view types.
MatElementaryOps<MT> — row / column primitives templated over dense or sparse matrix storage.
Templated DMat<R> linear algebra: LU, rank, determinant, solve, inverse, nullSpace.
MutableMatrix — abstract base of every mutable matrix the engine hands across the boundary.
MatrixConstructor — the mutable builder that produces an immutable Matrix.
bool error_column_bound(size_t c, size_t ncols)
bool isDense(const MT &mat)
bool error_row_bound(size_t r, size_t nrows)
Matrix * toMatrix(const Ring *R, const DMat< CoeffRing > &A)
Definition aring-CC.cpp:3
void scalarMultInPlace(DMat< RT > &A, const typename RT::ElementType &f)
void negateInPlace(DMat< RT > &A)
void set(DMat< RT > &A, MatrixWindow wA, const DMat< RT > &B, MatrixWindow wB)
bool isEqual(const DMat< RT > &A, const DMat< RT > &B)
bool isZero(const DMat< RT > &A)
void subtractInPlace(DMat< RT > &A, const DMat< RT > &B)
void addInPlace(DMat< RT > &A, const DMat< RT > &B)
void transpose(const DMat< RT > &A, DMat< RT > &result)
volatile int x
TermIterator< Nterm > begin(Nterm *ptr)
Definition ringelem.cpp:4
SMat<ACoeffRing> — column-oriented sparse matrix template, dual of DMat<R>.