Eigne Matrix Class Library

Dependents:   Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more

Eigen Matrix Class Library for mbed.

Finally, you can use Eigen on your mbed!!!

Committer:
ykuroda
Date:
Thu Oct 13 04:07:23 2016 +0000
Revision:
0:13a5d365ba16
First commint, Eigne Matrix Class Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ykuroda 0:13a5d365ba16 1 // This file is part of Eigen, a lightweight C++ template library
ykuroda 0:13a5d365ba16 2 // for linear algebra.
ykuroda 0:13a5d365ba16 3 //
ykuroda 0:13a5d365ba16 4 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
ykuroda 0:13a5d365ba16 5 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
ykuroda 0:13a5d365ba16 6 //
ykuroda 0:13a5d365ba16 7 // This Source Code Form is subject to the terms of the Mozilla
ykuroda 0:13a5d365ba16 8 // Public License v. 2.0. If a copy of the MPL was not distributed
ykuroda 0:13a5d365ba16 9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
ykuroda 0:13a5d365ba16 10
ykuroda 0:13a5d365ba16 11 #ifndef EIGEN_MATRIX_H
ykuroda 0:13a5d365ba16 12 #define EIGEN_MATRIX_H
ykuroda 0:13a5d365ba16 13
ykuroda 0:13a5d365ba16 14 namespace Eigen {
ykuroda 0:13a5d365ba16 15
ykuroda 0:13a5d365ba16 16 /** \class Matrix
ykuroda 0:13a5d365ba16 17 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 18 *
ykuroda 0:13a5d365ba16 19 * \brief The matrix class, also used for vectors and row-vectors
ykuroda 0:13a5d365ba16 20 *
ykuroda 0:13a5d365ba16 21 * The %Matrix class is the work-horse for all \em dense (\ref dense "note") matrices and vectors within Eigen.
ykuroda 0:13a5d365ba16 22 * Vectors are matrices with one column, and row-vectors are matrices with one row.
ykuroda 0:13a5d365ba16 23 *
ykuroda 0:13a5d365ba16 24 * The %Matrix class encompasses \em both fixed-size and dynamic-size objects (\ref fixedsize "note").
ykuroda 0:13a5d365ba16 25 *
ykuroda 0:13a5d365ba16 26 * The first three template parameters are required:
ykuroda 0:13a5d365ba16 27 * \tparam _Scalar \anchor matrix_tparam_scalar Numeric type, e.g. float, double, int or std::complex<float>.
ykuroda 0:13a5d365ba16 28 * User defined sclar types are supported as well (see \ref user_defined_scalars "here").
ykuroda 0:13a5d365ba16 29 * \tparam _Rows Number of rows, or \b Dynamic
ykuroda 0:13a5d365ba16 30 * \tparam _Cols Number of columns, or \b Dynamic
ykuroda 0:13a5d365ba16 31 *
ykuroda 0:13a5d365ba16 32 * The remaining template parameters are optional -- in most cases you don't have to worry about them.
ykuroda 0:13a5d365ba16 33 * \tparam _Options \anchor matrix_tparam_options A combination of either \b #RowMajor or \b #ColMajor, and of either
ykuroda 0:13a5d365ba16 34 * \b #AutoAlign or \b #DontAlign.
ykuroda 0:13a5d365ba16 35 * The former controls \ref TopicStorageOrders "storage order", and defaults to column-major. The latter controls alignment, which is required
ykuroda 0:13a5d365ba16 36 * for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size.
ykuroda 0:13a5d365ba16 37 * \tparam _MaxRows Maximum number of rows. Defaults to \a _Rows (\ref maxrows "note").
ykuroda 0:13a5d365ba16 38 * \tparam _MaxCols Maximum number of columns. Defaults to \a _Cols (\ref maxrows "note").
ykuroda 0:13a5d365ba16 39 *
ykuroda 0:13a5d365ba16 40 * Eigen provides a number of typedefs covering the usual cases. Here are some examples:
ykuroda 0:13a5d365ba16 41 *
ykuroda 0:13a5d365ba16 42 * \li \c Matrix2d is a 2x2 square matrix of doubles (\c Matrix<double, 2, 2>)
ykuroda 0:13a5d365ba16 43 * \li \c Vector4f is a vector of 4 floats (\c Matrix<float, 4, 1>)
ykuroda 0:13a5d365ba16 44 * \li \c RowVector3i is a row-vector of 3 ints (\c Matrix<int, 1, 3>)
ykuroda 0:13a5d365ba16 45 *
ykuroda 0:13a5d365ba16 46 * \li \c MatrixXf is a dynamic-size matrix of floats (\c Matrix<float, Dynamic, Dynamic>)
ykuroda 0:13a5d365ba16 47 * \li \c VectorXf is a dynamic-size vector of floats (\c Matrix<float, Dynamic, 1>)
ykuroda 0:13a5d365ba16 48 *
ykuroda 0:13a5d365ba16 49 * \li \c Matrix2Xf is a partially fixed-size (dynamic-size) matrix of floats (\c Matrix<float, 2, Dynamic>)
ykuroda 0:13a5d365ba16 50 * \li \c MatrixX3d is a partially dynamic-size (fixed-size) matrix of double (\c Matrix<double, Dynamic, 3>)
ykuroda 0:13a5d365ba16 51 *
ykuroda 0:13a5d365ba16 52 * See \link matrixtypedefs this page \endlink for a complete list of predefined \em %Matrix and \em Vector typedefs.
ykuroda 0:13a5d365ba16 53 *
ykuroda 0:13a5d365ba16 54 * You can access elements of vectors and matrices using normal subscripting:
ykuroda 0:13a5d365ba16 55 *
ykuroda 0:13a5d365ba16 56 * \code
ykuroda 0:13a5d365ba16 57 * Eigen::VectorXd v(10);
ykuroda 0:13a5d365ba16 58 * v[0] = 0.1;
ykuroda 0:13a5d365ba16 59 * v[1] = 0.2;
ykuroda 0:13a5d365ba16 60 * v(0) = 0.3;
ykuroda 0:13a5d365ba16 61 * v(1) = 0.4;
ykuroda 0:13a5d365ba16 62 *
ykuroda 0:13a5d365ba16 63 * Eigen::MatrixXi m(10, 10);
ykuroda 0:13a5d365ba16 64 * m(0, 1) = 1;
ykuroda 0:13a5d365ba16 65 * m(0, 2) = 2;
ykuroda 0:13a5d365ba16 66 * m(0, 3) = 3;
ykuroda 0:13a5d365ba16 67 * \endcode
ykuroda 0:13a5d365ba16 68 *
ykuroda 0:13a5d365ba16 69 * This class can be extended with the help of the plugin mechanism described on the page
ykuroda 0:13a5d365ba16 70 * \ref TopicCustomizingEigen by defining the preprocessor symbol \c EIGEN_MATRIX_PLUGIN.
ykuroda 0:13a5d365ba16 71 *
ykuroda 0:13a5d365ba16 72 * <i><b>Some notes:</b></i>
ykuroda 0:13a5d365ba16 73 *
ykuroda 0:13a5d365ba16 74 * <dl>
ykuroda 0:13a5d365ba16 75 * <dt><b>\anchor dense Dense versus sparse:</b></dt>
ykuroda 0:13a5d365ba16 76 * <dd>This %Matrix class handles dense, not sparse matrices and vectors. For sparse matrices and vectors, see the Sparse module.
ykuroda 0:13a5d365ba16 77 *
ykuroda 0:13a5d365ba16 78 * Dense matrices and vectors are plain usual arrays of coefficients. All the coefficients are stored, in an ordinary contiguous array.
ykuroda 0:13a5d365ba16 79 * This is unlike Sparse matrices and vectors where the coefficients are stored as a list of nonzero coefficients.</dd>
ykuroda 0:13a5d365ba16 80 *
ykuroda 0:13a5d365ba16 81 * <dt><b>\anchor fixedsize Fixed-size versus dynamic-size:</b></dt>
ykuroda 0:13a5d365ba16 82 * <dd>Fixed-size means that the numbers of rows and columns are known are compile-time. In this case, Eigen allocates the array
ykuroda 0:13a5d365ba16 83 * of coefficients as a fixed-size array, as a class member. This makes sense for very small matrices, typically up to 4x4, sometimes up
ykuroda 0:13a5d365ba16 84 * to 16x16. Larger matrices should be declared as dynamic-size even if one happens to know their size at compile-time.
ykuroda 0:13a5d365ba16 85 *
ykuroda 0:13a5d365ba16 86 * Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime
ykuroda 0:13a5d365ba16 87 * variables, and the array of coefficients is allocated dynamically on the heap.
ykuroda 0:13a5d365ba16 88 *
ykuroda 0:13a5d365ba16 89 * Note that \em dense matrices, be they Fixed-size or Dynamic-size, <em>do not</em> expand dynamically in the sense of a std::map.
ykuroda 0:13a5d365ba16 90 * If you want this behavior, see the Sparse module.</dd>
ykuroda 0:13a5d365ba16 91 *
ykuroda 0:13a5d365ba16 92 * <dt><b>\anchor maxrows _MaxRows and _MaxCols:</b></dt>
ykuroda 0:13a5d365ba16 93 * <dd>In most cases, one just leaves these parameters to the default values.
ykuroda 0:13a5d365ba16 94 * These parameters mean the maximum size of rows and columns that the matrix may have. They are useful in cases
ykuroda 0:13a5d365ba16 95 * when the exact numbers of rows and columns are not known are compile-time, but it is known at compile-time that they cannot
ykuroda 0:13a5d365ba16 96 * exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case _MaxRows and _MaxCols
ykuroda 0:13a5d365ba16 97 * are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.</dd>
ykuroda 0:13a5d365ba16 98 * </dl>
ykuroda 0:13a5d365ba16 99 *
ykuroda 0:13a5d365ba16 100 * \see MatrixBase for the majority of the API methods for matrices, \ref TopicClassHierarchy,
ykuroda 0:13a5d365ba16 101 * \ref TopicStorageOrders
ykuroda 0:13a5d365ba16 102 */
ykuroda 0:13a5d365ba16 103
ykuroda 0:13a5d365ba16 104 namespace internal {
ykuroda 0:13a5d365ba16 105 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
ykuroda 0:13a5d365ba16 106 struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
ykuroda 0:13a5d365ba16 107 {
ykuroda 0:13a5d365ba16 108 typedef _Scalar Scalar;
ykuroda 0:13a5d365ba16 109 typedef Dense StorageKind;
ykuroda 0:13a5d365ba16 110 typedef DenseIndex Index;
ykuroda 0:13a5d365ba16 111 typedef MatrixXpr XprKind;
ykuroda 0:13a5d365ba16 112 enum {
ykuroda 0:13a5d365ba16 113 RowsAtCompileTime = _Rows,
ykuroda 0:13a5d365ba16 114 ColsAtCompileTime = _Cols,
ykuroda 0:13a5d365ba16 115 MaxRowsAtCompileTime = _MaxRows,
ykuroda 0:13a5d365ba16 116 MaxColsAtCompileTime = _MaxCols,
ykuroda 0:13a5d365ba16 117 Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
ykuroda 0:13a5d365ba16 118 CoeffReadCost = NumTraits<Scalar>::ReadCost,
ykuroda 0:13a5d365ba16 119 Options = _Options,
ykuroda 0:13a5d365ba16 120 InnerStrideAtCompileTime = 1,
ykuroda 0:13a5d365ba16 121 OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime
ykuroda 0:13a5d365ba16 122 };
ykuroda 0:13a5d365ba16 123 };
ykuroda 0:13a5d365ba16 124 }
ykuroda 0:13a5d365ba16 125
ykuroda 0:13a5d365ba16 126 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
ykuroda 0:13a5d365ba16 127 class Matrix
ykuroda 0:13a5d365ba16 128 : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
ykuroda 0:13a5d365ba16 129 {
ykuroda 0:13a5d365ba16 130 public:
ykuroda 0:13a5d365ba16 131
ykuroda 0:13a5d365ba16 132 /** \brief Base class typedef.
ykuroda 0:13a5d365ba16 133 * \sa PlainObjectBase
ykuroda 0:13a5d365ba16 134 */
ykuroda 0:13a5d365ba16 135 typedef PlainObjectBase<Matrix> Base;
ykuroda 0:13a5d365ba16 136
ykuroda 0:13a5d365ba16 137 enum { Options = _Options };
ykuroda 0:13a5d365ba16 138
ykuroda 0:13a5d365ba16 139 EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
ykuroda 0:13a5d365ba16 140
ykuroda 0:13a5d365ba16 141 typedef typename Base::PlainObject PlainObject;
ykuroda 0:13a5d365ba16 142
ykuroda 0:13a5d365ba16 143 using Base::base;
ykuroda 0:13a5d365ba16 144 using Base::coeffRef;
ykuroda 0:13a5d365ba16 145
ykuroda 0:13a5d365ba16 146 /**
ykuroda 0:13a5d365ba16 147 * \brief Assigns matrices to each other.
ykuroda 0:13a5d365ba16 148 *
ykuroda 0:13a5d365ba16 149 * \note This is a special case of the templated operator=. Its purpose is
ykuroda 0:13a5d365ba16 150 * to prevent a default operator= from hiding the templated operator=.
ykuroda 0:13a5d365ba16 151 *
ykuroda 0:13a5d365ba16 152 * \callgraph
ykuroda 0:13a5d365ba16 153 */
ykuroda 0:13a5d365ba16 154 EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
ykuroda 0:13a5d365ba16 155 {
ykuroda 0:13a5d365ba16 156 return Base::_set(other);
ykuroda 0:13a5d365ba16 157 }
ykuroda 0:13a5d365ba16 158
ykuroda 0:13a5d365ba16 159 /** \internal
ykuroda 0:13a5d365ba16 160 * \brief Copies the value of the expression \a other into \c *this with automatic resizing.
ykuroda 0:13a5d365ba16 161 *
ykuroda 0:13a5d365ba16 162 * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
ykuroda 0:13a5d365ba16 163 * it will be initialized.
ykuroda 0:13a5d365ba16 164 *
ykuroda 0:13a5d365ba16 165 * Note that copying a row-vector into a vector (and conversely) is allowed.
ykuroda 0:13a5d365ba16 166 * The resizing, if any, is then done in the appropriate way so that row-vectors
ykuroda 0:13a5d365ba16 167 * remain row-vectors and vectors remain vectors.
ykuroda 0:13a5d365ba16 168 */
ykuroda 0:13a5d365ba16 169 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 170 EIGEN_STRONG_INLINE Matrix& operator=(const MatrixBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 171 {
ykuroda 0:13a5d365ba16 172 return Base::_set(other);
ykuroda 0:13a5d365ba16 173 }
ykuroda 0:13a5d365ba16 174
ykuroda 0:13a5d365ba16 175 /* Here, doxygen failed to copy the brief information when using \copydoc */
ykuroda 0:13a5d365ba16 176
ykuroda 0:13a5d365ba16 177 /**
ykuroda 0:13a5d365ba16 178 * \brief Copies the generic expression \a other into *this.
ykuroda 0:13a5d365ba16 179 * \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other)
ykuroda 0:13a5d365ba16 180 */
ykuroda 0:13a5d365ba16 181 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 182 EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
ykuroda 0:13a5d365ba16 183 {
ykuroda 0:13a5d365ba16 184 return Base::operator=(other);
ykuroda 0:13a5d365ba16 185 }
ykuroda 0:13a5d365ba16 186
ykuroda 0:13a5d365ba16 187 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 188 EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
ykuroda 0:13a5d365ba16 189 {
ykuroda 0:13a5d365ba16 190 return Base::operator=(func);
ykuroda 0:13a5d365ba16 191 }
ykuroda 0:13a5d365ba16 192
ykuroda 0:13a5d365ba16 193 /** \brief Default constructor.
ykuroda 0:13a5d365ba16 194 *
ykuroda 0:13a5d365ba16 195 * For fixed-size matrices, does nothing.
ykuroda 0:13a5d365ba16 196 *
ykuroda 0:13a5d365ba16 197 * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
ykuroda 0:13a5d365ba16 198 * is called a null matrix. This constructor is the unique way to create null matrices: resizing
ykuroda 0:13a5d365ba16 199 * a matrix to 0 is not supported.
ykuroda 0:13a5d365ba16 200 *
ykuroda 0:13a5d365ba16 201 * \sa resize(Index,Index)
ykuroda 0:13a5d365ba16 202 */
ykuroda 0:13a5d365ba16 203 EIGEN_STRONG_INLINE Matrix() : Base()
ykuroda 0:13a5d365ba16 204 {
ykuroda 0:13a5d365ba16 205 Base::_check_template_params();
ykuroda 0:13a5d365ba16 206 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
ykuroda 0:13a5d365ba16 207 }
ykuroda 0:13a5d365ba16 208
ykuroda 0:13a5d365ba16 209 // FIXME is it still needed
ykuroda 0:13a5d365ba16 210 Matrix(internal::constructor_without_unaligned_array_assert)
ykuroda 0:13a5d365ba16 211 : Base(internal::constructor_without_unaligned_array_assert())
ykuroda 0:13a5d365ba16 212 { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
ykuroda 0:13a5d365ba16 213
ykuroda 0:13a5d365ba16 214 #ifdef EIGEN_HAVE_RVALUE_REFERENCES
ykuroda 0:13a5d365ba16 215 Matrix(Matrix&& other)
ykuroda 0:13a5d365ba16 216 : Base(std::move(other))
ykuroda 0:13a5d365ba16 217 {
ykuroda 0:13a5d365ba16 218 Base::_check_template_params();
ykuroda 0:13a5d365ba16 219 if (RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic)
ykuroda 0:13a5d365ba16 220 Base::_set_noalias(other);
ykuroda 0:13a5d365ba16 221 }
ykuroda 0:13a5d365ba16 222 Matrix& operator=(Matrix&& other)
ykuroda 0:13a5d365ba16 223 {
ykuroda 0:13a5d365ba16 224 other.swap(*this);
ykuroda 0:13a5d365ba16 225 return *this;
ykuroda 0:13a5d365ba16 226 }
ykuroda 0:13a5d365ba16 227 #endif
ykuroda 0:13a5d365ba16 228
ykuroda 0:13a5d365ba16 229 /** \brief Constructs a vector or row-vector with given dimension. \only_for_vectors
ykuroda 0:13a5d365ba16 230 *
ykuroda 0:13a5d365ba16 231 * Note that this is only useful for dynamic-size vectors. For fixed-size vectors,
ykuroda 0:13a5d365ba16 232 * it is redundant to pass the dimension here, so it makes more sense to use the default
ykuroda 0:13a5d365ba16 233 * constructor Matrix() instead.
ykuroda 0:13a5d365ba16 234 */
ykuroda 0:13a5d365ba16 235 EIGEN_STRONG_INLINE explicit Matrix(Index dim)
ykuroda 0:13a5d365ba16 236 : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
ykuroda 0:13a5d365ba16 237 {
ykuroda 0:13a5d365ba16 238 Base::_check_template_params();
ykuroda 0:13a5d365ba16 239 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix)
ykuroda 0:13a5d365ba16 240 eigen_assert(dim >= 0);
ykuroda 0:13a5d365ba16 241 eigen_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim);
ykuroda 0:13a5d365ba16 242 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
ykuroda 0:13a5d365ba16 243 }
ykuroda 0:13a5d365ba16 244
ykuroda 0:13a5d365ba16 245 #ifndef EIGEN_PARSED_BY_DOXYGEN
ykuroda 0:13a5d365ba16 246 template<typename T0, typename T1>
ykuroda 0:13a5d365ba16 247 EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y)
ykuroda 0:13a5d365ba16 248 {
ykuroda 0:13a5d365ba16 249 Base::_check_template_params();
ykuroda 0:13a5d365ba16 250 Base::template _init2<T0,T1>(x, y);
ykuroda 0:13a5d365ba16 251 }
ykuroda 0:13a5d365ba16 252 #else
ykuroda 0:13a5d365ba16 253 /** \brief Constructs an uninitialized matrix with \a rows rows and \a cols columns.
ykuroda 0:13a5d365ba16 254 *
ykuroda 0:13a5d365ba16 255 * This is useful for dynamic-size matrices. For fixed-size matrices,
ykuroda 0:13a5d365ba16 256 * it is redundant to pass these parameters, so one should use the default constructor
ykuroda 0:13a5d365ba16 257 * Matrix() instead. */
ykuroda 0:13a5d365ba16 258 Matrix(Index rows, Index cols);
ykuroda 0:13a5d365ba16 259 /** \brief Constructs an initialized 2D vector with given coefficients */
ykuroda 0:13a5d365ba16 260 Matrix(const Scalar& x, const Scalar& y);
ykuroda 0:13a5d365ba16 261 #endif
ykuroda 0:13a5d365ba16 262
ykuroda 0:13a5d365ba16 263 /** \brief Constructs an initialized 3D vector with given coefficients */
ykuroda 0:13a5d365ba16 264 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
ykuroda 0:13a5d365ba16 265 {
ykuroda 0:13a5d365ba16 266 Base::_check_template_params();
ykuroda 0:13a5d365ba16 267 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
ykuroda 0:13a5d365ba16 268 m_storage.data()[0] = x;
ykuroda 0:13a5d365ba16 269 m_storage.data()[1] = y;
ykuroda 0:13a5d365ba16 270 m_storage.data()[2] = z;
ykuroda 0:13a5d365ba16 271 }
ykuroda 0:13a5d365ba16 272 /** \brief Constructs an initialized 4D vector with given coefficients */
ykuroda 0:13a5d365ba16 273 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
ykuroda 0:13a5d365ba16 274 {
ykuroda 0:13a5d365ba16 275 Base::_check_template_params();
ykuroda 0:13a5d365ba16 276 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
ykuroda 0:13a5d365ba16 277 m_storage.data()[0] = x;
ykuroda 0:13a5d365ba16 278 m_storage.data()[1] = y;
ykuroda 0:13a5d365ba16 279 m_storage.data()[2] = z;
ykuroda 0:13a5d365ba16 280 m_storage.data()[3] = w;
ykuroda 0:13a5d365ba16 281 }
ykuroda 0:13a5d365ba16 282
ykuroda 0:13a5d365ba16 283 explicit Matrix(const Scalar *data);
ykuroda 0:13a5d365ba16 284
ykuroda 0:13a5d365ba16 285 /** \brief Constructor copying the value of the expression \a other */
ykuroda 0:13a5d365ba16 286 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 287 EIGEN_STRONG_INLINE Matrix(const MatrixBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 288 : Base(other.rows() * other.cols(), other.rows(), other.cols())
ykuroda 0:13a5d365ba16 289 {
ykuroda 0:13a5d365ba16 290 // This test resides here, to bring the error messages closer to the user. Normally, these checks
ykuroda 0:13a5d365ba16 291 // are performed deeply within the library, thus causing long and scary error traces.
ykuroda 0:13a5d365ba16 292 EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
ykuroda 0:13a5d365ba16 293 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
ykuroda 0:13a5d365ba16 294
ykuroda 0:13a5d365ba16 295 Base::_check_template_params();
ykuroda 0:13a5d365ba16 296 Base::_set_noalias(other);
ykuroda 0:13a5d365ba16 297 }
ykuroda 0:13a5d365ba16 298 /** \brief Copy constructor */
ykuroda 0:13a5d365ba16 299 EIGEN_STRONG_INLINE Matrix(const Matrix& other)
ykuroda 0:13a5d365ba16 300 : Base(other.rows() * other.cols(), other.rows(), other.cols())
ykuroda 0:13a5d365ba16 301 {
ykuroda 0:13a5d365ba16 302 Base::_check_template_params();
ykuroda 0:13a5d365ba16 303 Base::_set_noalias(other);
ykuroda 0:13a5d365ba16 304 }
ykuroda 0:13a5d365ba16 305 /** \brief Copy constructor with in-place evaluation */
ykuroda 0:13a5d365ba16 306 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 307 EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived>& other)
ykuroda 0:13a5d365ba16 308 {
ykuroda 0:13a5d365ba16 309 Base::_check_template_params();
ykuroda 0:13a5d365ba16 310 Base::resize(other.rows(), other.cols());
ykuroda 0:13a5d365ba16 311 other.evalTo(*this);
ykuroda 0:13a5d365ba16 312 }
ykuroda 0:13a5d365ba16 313
ykuroda 0:13a5d365ba16 314 /** \brief Copy constructor for generic expressions.
ykuroda 0:13a5d365ba16 315 * \sa MatrixBase::operator=(const EigenBase<OtherDerived>&)
ykuroda 0:13a5d365ba16 316 */
ykuroda 0:13a5d365ba16 317 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 318 EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
ykuroda 0:13a5d365ba16 319 : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
ykuroda 0:13a5d365ba16 320 {
ykuroda 0:13a5d365ba16 321 Base::_check_template_params();
ykuroda 0:13a5d365ba16 322 Base::_resize_to_match(other);
ykuroda 0:13a5d365ba16 323 // FIXME/CHECK: isn't *this = other.derived() more efficient. it allows to
ykuroda 0:13a5d365ba16 324 // go for pure _set() implementations, right?
ykuroda 0:13a5d365ba16 325 *this = other;
ykuroda 0:13a5d365ba16 326 }
ykuroda 0:13a5d365ba16 327
ykuroda 0:13a5d365ba16 328 /** \internal
ykuroda 0:13a5d365ba16 329 * \brief Override MatrixBase::swap() since for dynamic-sized matrices
ykuroda 0:13a5d365ba16 330 * of same type it is enough to swap the data pointers.
ykuroda 0:13a5d365ba16 331 */
ykuroda 0:13a5d365ba16 332 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 333 void swap(MatrixBase<OtherDerived> const & other)
ykuroda 0:13a5d365ba16 334 { this->_swap(other.derived()); }
ykuroda 0:13a5d365ba16 335
ykuroda 0:13a5d365ba16 336 inline Index innerStride() const { return 1; }
ykuroda 0:13a5d365ba16 337 inline Index outerStride() const { return this->innerSize(); }
ykuroda 0:13a5d365ba16 338
ykuroda 0:13a5d365ba16 339 /////////// Geometry module ///////////
ykuroda 0:13a5d365ba16 340
ykuroda 0:13a5d365ba16 341 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 342 explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
ykuroda 0:13a5d365ba16 343 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 344 Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
ykuroda 0:13a5d365ba16 345
ykuroda 0:13a5d365ba16 346 #ifdef EIGEN2_SUPPORT
ykuroda 0:13a5d365ba16 347 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 348 explicit Matrix(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
ykuroda 0:13a5d365ba16 349 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 350 Matrix& operator=(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
ykuroda 0:13a5d365ba16 351 #endif
ykuroda 0:13a5d365ba16 352
ykuroda 0:13a5d365ba16 353 // allow to extend Matrix outside Eigen
ykuroda 0:13a5d365ba16 354 #ifdef EIGEN_MATRIX_PLUGIN
ykuroda 0:13a5d365ba16 355 #include EIGEN_MATRIX_PLUGIN
ykuroda 0:13a5d365ba16 356 #endif
ykuroda 0:13a5d365ba16 357
ykuroda 0:13a5d365ba16 358 protected:
ykuroda 0:13a5d365ba16 359 template <typename Derived, typename OtherDerived, bool IsVector>
ykuroda 0:13a5d365ba16 360 friend struct internal::conservative_resize_like_impl;
ykuroda 0:13a5d365ba16 361
ykuroda 0:13a5d365ba16 362 using Base::m_storage;
ykuroda 0:13a5d365ba16 363 };
ykuroda 0:13a5d365ba16 364
ykuroda 0:13a5d365ba16 365 /** \defgroup matrixtypedefs Global matrix typedefs
ykuroda 0:13a5d365ba16 366 *
ykuroda 0:13a5d365ba16 367 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 368 *
ykuroda 0:13a5d365ba16 369 * Eigen defines several typedef shortcuts for most common matrix and vector types.
ykuroda 0:13a5d365ba16 370 *
ykuroda 0:13a5d365ba16 371 * The general patterns are the following:
ykuroda 0:13a5d365ba16 372 *
ykuroda 0:13a5d365ba16 373 * \c MatrixSizeType where \c Size can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size,
ykuroda 0:13a5d365ba16 374 * and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd
ykuroda 0:13a5d365ba16 375 * for complex double.
ykuroda 0:13a5d365ba16 376 *
ykuroda 0:13a5d365ba16 377 * For example, \c Matrix3d is a fixed-size 3x3 matrix type of doubles, and \c MatrixXf is a dynamic-size matrix of floats.
ykuroda 0:13a5d365ba16 378 *
ykuroda 0:13a5d365ba16 379 * There are also \c VectorSizeType and \c RowVectorSizeType which are self-explanatory. For example, \c Vector4cf is
ykuroda 0:13a5d365ba16 380 * a fixed-size vector of 4 complex floats.
ykuroda 0:13a5d365ba16 381 *
ykuroda 0:13a5d365ba16 382 * \sa class Matrix
ykuroda 0:13a5d365ba16 383 */
ykuroda 0:13a5d365ba16 384
ykuroda 0:13a5d365ba16 385 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
ykuroda 0:13a5d365ba16 386 /** \ingroup matrixtypedefs */ \
ykuroda 0:13a5d365ba16 387 typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
ykuroda 0:13a5d365ba16 388 /** \ingroup matrixtypedefs */ \
ykuroda 0:13a5d365ba16 389 typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
ykuroda 0:13a5d365ba16 390 /** \ingroup matrixtypedefs */ \
ykuroda 0:13a5d365ba16 391 typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
ykuroda 0:13a5d365ba16 392
ykuroda 0:13a5d365ba16 393 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
ykuroda 0:13a5d365ba16 394 /** \ingroup matrixtypedefs */ \
ykuroda 0:13a5d365ba16 395 typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
ykuroda 0:13a5d365ba16 396 /** \ingroup matrixtypedefs */ \
ykuroda 0:13a5d365ba16 397 typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
ykuroda 0:13a5d365ba16 398
ykuroda 0:13a5d365ba16 399 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
ykuroda 0:13a5d365ba16 400 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
ykuroda 0:13a5d365ba16 401 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
ykuroda 0:13a5d365ba16 402 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
ykuroda 0:13a5d365ba16 403 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
ykuroda 0:13a5d365ba16 404 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
ykuroda 0:13a5d365ba16 405 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
ykuroda 0:13a5d365ba16 406 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
ykuroda 0:13a5d365ba16 407
ykuroda 0:13a5d365ba16 408 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
ykuroda 0:13a5d365ba16 409 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
ykuroda 0:13a5d365ba16 410 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
ykuroda 0:13a5d365ba16 411 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
ykuroda 0:13a5d365ba16 412 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
ykuroda 0:13a5d365ba16 413
ykuroda 0:13a5d365ba16 414 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
ykuroda 0:13a5d365ba16 415 #undef EIGEN_MAKE_TYPEDEFS
ykuroda 0:13a5d365ba16 416 #undef EIGEN_MAKE_FIXED_TYPEDEFS
ykuroda 0:13a5d365ba16 417
ykuroda 0:13a5d365ba16 418 } // end namespace Eigen
ykuroda 0:13a5d365ba16 419
ykuroda 0:13a5d365ba16 420 #endif // EIGEN_MATRIX_H