diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-06-24 22:07:03 +0200 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-06-24 22:07:03 +0200 |
commit | 03ad303d1417e53b8bcec8dd8d8e404cd4e13af4 (patch) | |
tree | 92cc1f23881836e6beda8d000fa98c822deb7af1 /Eigen | |
parent | 96dca681b04c9bd10081ef46453049cda1ee74df (diff) |
* add resize(int, NoChange) and resize(NoChange, int)
* add missing assert in resize(int)
* add examples for all resize variants
* expand docs (part of which is from Tim Hutt's e-mail)
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/Matrix.h | 45 | ||||
-rw-r--r-- | Eigen/src/Core/util/Constants.h | 2 |
2 files changed, 44 insertions, 3 deletions
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index b5a90dfdf..e099ba1e7 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -215,14 +215,19 @@ class Matrix /** Resizes \c *this to a \a rows x \a cols matrix. * - * Makes sense for dynamic-size matrices only. + * This method is intended for dynamic-size matrices, although it is legal to call it on any + * matrix as long as fixed dimensions are left unchanged. If you only want to change the number + * of rows and/or of columns, you can use resize(NoChange_t, int), resize(int, NoChange_t). * * If the current number of coefficients of \c *this exactly matches the * product \a rows * \a cols, then no memory allocation is performed and * the current values are left unchanged. In all other cases, including * shrinking, the data is reallocated and all previous values are lost. * - * \sa resize(int) for vectors. + * Example: \include Matrix_resize_int_int.cpp + * Output: \verbinclude Matrix_resize_int_int.out + * + * \sa resize(int) for vectors, resize(NoChange_t, int), resize(int, NoChange_t) */ inline void resize(int rows, int cols) { @@ -235,17 +240,51 @@ class Matrix /** Resizes \c *this to a vector of length \a size * - * \sa resize(int,int) for the details. + * \only_for_vectors. This method does not work for + * partially dynamic matrices when the static dimension is anything other + * than 1. For example it will not work with Matrix<double, 2, Dynamic>. + * + * Example: \include Matrix_resize_int.cpp + * Output: \verbinclude Matrix_resize_int.out + * + * \sa resize(int,int), resize(NoChange_t, int), resize(int, NoChange_t) */ inline void resize(int size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix) + ei_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == size); if(RowsAtCompileTime == 1) m_storage.resize(size, 1, size); else m_storage.resize(size, size, 1); } + /** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange + * as in the example below. + * + * Example: \include Matrix_resize_NoChange_int.cpp + * Output: \verbinclude Matrix_resize_NoChange_int.out + * + * \sa resize(int,int) + */ + inline void resize(NoChange_t, int cols) + { + resize(rows(), cols); + } + + /** Resizes the matrix, changing only the number of rows. For the parameter of type NoChange_t, just pass the special value \c NoChange + * as in the example below. + * + * Example: \include Matrix_resize_int_NoChange.cpp + * Output: \verbinclude Matrix_resize_int_NoChange.out + * + * \sa resize(int,int) + */ + inline void resize(int rows, NoChange_t) + { + resize(rows, cols()); + } + /** Resizes *this to have the same dimensions as \a other. * Takes care of doing all the checking that's needed. * diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index 0c06a39bc..79efa700b 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -241,6 +241,8 @@ enum { DontAlign = 0x2 }; +enum NoChange_t { NoChange }; + enum { IsDense = 0, IsSparse = SparseBit, |