Eigen  3.2.10
 
Loading...
Searching...
No Matches
Matrix.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_MATRIX_H
12#define EIGEN_MATRIX_H
13
14namespace Eigen {
15
103
104namespace internal {
105template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
106struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
107{
108 typedef _Scalar Scalar;
109 typedef Dense StorageKind;
110 typedef DenseIndex Index;
111 typedef MatrixXpr XprKind;
112 enum {
113 RowsAtCompileTime = _Rows,
114 ColsAtCompileTime = _Cols,
115 MaxRowsAtCompileTime = _MaxRows,
116 MaxColsAtCompileTime = _MaxCols,
117 Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
118 CoeffReadCost = NumTraits<Scalar>::ReadCost,
119 Options = _Options,
120 InnerStrideAtCompileTime = 1,
121 OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime
122 };
123};
124}
125
126template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
128 : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
129{
130 public:
131
135 typedef PlainObjectBase<Matrix> Base;
136
137 enum { Options = _Options };
138
139 EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
140
141 typedef typename Base::PlainObject PlainObject;
142
143 using Base::base;
144 using Base::coeffRef;
145
154 EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
155 {
156 return Base::_set(other);
157 }
158
169 template<typename OtherDerived>
170 EIGEN_STRONG_INLINE Matrix& operator=(const MatrixBase<OtherDerived>& other)
171 {
172 return Base::_set(other);
173 }
174
175 /* Here, doxygen failed to copy the brief information when using \copydoc */
176
181 template<typename OtherDerived>
182 EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
183 {
184 return Base::operator=(other);
185 }
186
187 template<typename OtherDerived>
188 EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
189 {
190 return Base::operator=(func);
191 }
192
203 EIGEN_STRONG_INLINE Matrix() : Base()
204 {
205 Base::_check_template_params();
206 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
207 }
208
209 // FIXME is it still needed
210 Matrix(internal::constructor_without_unaligned_array_assert)
211 : Base(internal::constructor_without_unaligned_array_assert())
212 { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
213
214#ifdef EIGEN_HAVE_RVALUE_REFERENCES
215 Matrix(Matrix&& other)
216 : Base(std::move(other))
217 {
218 Base::_check_template_params();
219 if (RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic)
220 Base::_set_noalias(other);
221 }
222 Matrix& operator=(Matrix&& other)
223 {
224 other.swap(*this);
225 return *this;
226 }
227#endif
228
235 EIGEN_STRONG_INLINE explicit Matrix(Index dim)
236 : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
237 {
238 Base::_check_template_params();
239 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix)
240 eigen_assert(dim >= 0);
241 eigen_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim);
242 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
243 }
244
245 #ifndef EIGEN_PARSED_BY_DOXYGEN
246 template<typename T0, typename T1>
247 EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y)
248 {
249 Base::_check_template_params();
250 Base::template _init2<T0,T1>(x, y);
251 }
252 #else
258 Matrix(Index rows, Index cols);
260 Matrix(const Scalar& x, const Scalar& y);
261 #endif
262
264 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
265 {
266 Base::_check_template_params();
267 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
268 m_storage.data()[0] = x;
269 m_storage.data()[1] = y;
270 m_storage.data()[2] = z;
271 }
272
273 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
274 {
275 Base::_check_template_params();
276 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
277 m_storage.data()[0] = x;
278 m_storage.data()[1] = y;
279 m_storage.data()[2] = z;
280 m_storage.data()[3] = w;
281 }
282
283 explicit Matrix(const Scalar *data);
284
286 template<typename OtherDerived>
287 EIGEN_STRONG_INLINE Matrix(const MatrixBase<OtherDerived>& other)
288 : Base(other.rows() * other.cols(), other.rows(), other.cols())
289 {
290 // This test resides here, to bring the error messages closer to the user. Normally, these checks
291 // are performed deeply within the library, thus causing long and scary error traces.
292 EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
293 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
294
295 Base::_check_template_params();
296 Base::_set_noalias(other);
297 }
298
299 EIGEN_STRONG_INLINE Matrix(const Matrix& other)
300 : Base(other.rows() * other.cols(), other.rows(), other.cols())
301 {
302 Base::_check_template_params();
303 Base::_set_noalias(other);
304 }
305
306 template<typename OtherDerived>
307 EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived>& other)
308 {
309 Base::_check_template_params();
310 Base::resize(other.rows(), other.cols());
311 other.evalTo(*this);
312 }
313
317 template<typename OtherDerived>
318 EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
319 : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
320 {
321 Base::_check_template_params();
323 // FIXME/CHECK: isn't *this = other.derived() more efficient. it allows to
324 // go for pure _set() implementations, right?
325 *this = other;
326 }
327
332 template<typename OtherDerived>
333 void swap(MatrixBase<OtherDerived> const & other)
334 { this->_swap(other.derived()); }
335
336 inline Index innerStride() const { return 1; }
337 inline Index outerStride() const { return this->innerSize(); }
338
340
341 template<typename OtherDerived>
343 template<typename OtherDerived>
345
346 #ifdef EIGEN2_SUPPORT
347 template<typename OtherDerived>
348 explicit Matrix(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
349 template<typename OtherDerived>
350 Matrix& operator=(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
351 #endif
352
353 // allow to extend Matrix outside Eigen
354 #ifdef EIGEN_MATRIX_PLUGIN
355 #include EIGEN_MATRIX_PLUGIN
356 #endif
357
358 protected:
359 template <typename Derived, typename OtherDerived, bool IsVector>
360 friend struct internal::conservative_resize_like_impl;
361
362 using Base::m_storage;
363};
364
384
385#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
386 \
387typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
388 \
389typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
390 \
391typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
392
393#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
394 \
395typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
396 \
397typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
398
399#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
400EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
401EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
402EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
403EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
404EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
405EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
406EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
407
408EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
409EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
410EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
411EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
412EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
413
414#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
415#undef EIGEN_MAKE_TYPEDEFS
416#undef EIGEN_MAKE_FIXED_TYPEDEFS
417
418} // end namespace Eigen
419
420#endif // EIGEN_MATRIX_H
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:129
Matrix(const MatrixBase< OtherDerived > &other)
Constructor copying the value of the expression other.
Definition Matrix.h:287
Matrix(Index dim)
Constructs a vector or row-vector with given dimension. This is only for vectors (either row-vectors ...
Definition Matrix.h:235
Matrix()
Default constructor.
Definition Matrix.h:203
Matrix(Index rows, Index cols)
Constructs an uninitialized matrix with rows rows and cols columns.
Matrix(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w)
Constructs an initialized 4D vector with given coefficients.
Definition Matrix.h:273
Matrix(const Matrix &other)
Copy constructor.
Definition Matrix.h:299
Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition Matrix.h:154
Matrix(const RotationBase< OtherDerived, ColsAtCompileTime > &r)
Constructs a Dim x Dim rotation matrix from the rotation r.
Definition RotationBase.h:141
Matrix(const ReturnByValue< OtherDerived > &other)
Copy constructor with in-place evaluation.
Definition Matrix.h:307
Matrix(const Scalar &x, const Scalar &y)
Constructs an initialized 2D vector with given coefficients.
Matrix(const EigenBase< OtherDerived > &other)
Copy constructor for generic expressions.
Definition Matrix.h:318
Matrix(const Scalar &x, const Scalar &y, const Scalar &z)
Constructs an initialized 3D vector with given coefficients.
Definition Matrix.h:264
Matrix & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition Matrix.h:182
Matrix & operator=(const PlainObjectBase &other)
Definition PlainObjectBase.h:404
void _resize_to_match(const EigenBase< OtherDerived > &other)
Definition PlainObjectBase.h:599
Matrix & _set_noalias(const DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:646
Matrix & _set(const DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:628
void resize(Index nbRows, Index nbCols)
Definition PlainObjectBase.h:235
Common base class for compact rotation representations.
Definition RotationBase.h:30
@ RowMajor
Definition Constants.h:266
Definition LDLT.h:18
Definition EigenBase.h:27