@@ -93,6 +93,11 @@ class DenseMatrix : public DenseMatrixBase<T>
93
93
DenseMatrix & operator = (DenseMatrix &&) = default ;
94
94
virtual ~DenseMatrix () = default ;
95
95
96
+ /* *
97
+ * Sets all elements of the matrix to 0 and resets any decomposition
98
+ * flag which may have been previously set. This allows e.g. a new
99
+ * LU decomposition to be computed while reusing the same storage.
100
+ */
96
101
virtual void zero () override ;
97
102
98
103
/* *
@@ -234,8 +239,11 @@ class DenseMatrix : public DenseMatrixBase<T>
234
239
void swap (DenseMatrix<T> & other_matrix);
235
240
236
241
/* *
237
- * Resize the matrix. Will never free memory, but may
238
- * allocate more. Sets all elements to 0.
242
+ * Resizes the matrix to the specified size and calls zero(). Will
243
+ * never free memory, but may allocate more. Note: when the matrix
244
+ * is zero()'d, any decomposition (LU, Cholesky, etc.) is also
245
+ * cleared, forcing a new decomposition to be computed the next time
246
+ * e.g. lu_solve() is called.
239
247
*/
240
248
void resize (const unsigned int new_m,
241
249
const unsigned int new_n);
@@ -389,6 +397,15 @@ class DenseMatrix : public DenseMatrixBase<T>
389
397
* Solve the system Ax=b given the input vector b. Partial pivoting
390
398
* is performed by default in order to keep the algorithm stable to
391
399
* the effects of round-off error.
400
+ *
401
+ * Important note: once you call lu_solve(), you must _not_ modify
402
+ * the entries of the matrix via calls to operator(i,j) and call
403
+ * lu_solve() again without first calling either zero() or resize(),
404
+ * otherwise the code will skip computing the decomposition of the
405
+ * matrix and go directly to the back substitution step. This is
406
+ * done on purpose for efficiency, so that the same LU decomposition
407
+ * can be used with multiple right-hand sides, but it does also make
408
+ * it possible to "shoot yourself in the foot", so be careful!
392
409
*/
393
410
void lu_solve (const DenseVector<T> & b,
394
411
DenseVector<T> & x);
@@ -401,6 +418,16 @@ class DenseMatrix : public DenseMatrixBase<T>
401
418
* One nice property of Cholesky decompositions is that they do not require
402
419
* pivoting for stability.
403
420
*
421
+ * Important note: once you call cholesky_solve(), you must _not_
422
+ * modify the entries of the matrix via calls to operator(i,j) and
423
+ * call cholesky_solve() again without first calling either zero()
424
+ * or resize(), otherwise the code will skip computing the
425
+ * decomposition of the matrix and go directly to the back
426
+ * substitution step. This is done on purpose for efficiency, so
427
+ * that the same decomposition can be used with multiple right-hand
428
+ * sides, but it does also make it possible to "shoot yourself in
429
+ * the foot", so be careful!
430
+ *
404
431
* \note This method may also be used when A is real-valued and x
405
432
* and b are complex-valued.
406
433
*/
0 commit comments