Eigen  3.4.1 (git rev 28ded8800c26864e537852658428ab44c8399e87)
 
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
16namespace internal {
17template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
18struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
19{
20private:
21 enum { size = internal::size_at_compile_time<_Rows,_Cols>::ret };
22 typedef typename find_best_packet<_Scalar,size>::type PacketScalar;
23 enum {
24 row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
25 is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
26 max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
27 default_alignment = compute_default_alignment<_Scalar,max_size>::value,
28 actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
29 required_alignment = unpacket_traits<PacketScalar>::alignment,
30 packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
31 };
32
33public:
34 typedef _Scalar Scalar;
35 typedef Dense StorageKind;
36 typedef Eigen::Index StorageIndex;
37 typedef MatrixXpr XprKind;
38 enum {
39 RowsAtCompileTime = _Rows,
40 ColsAtCompileTime = _Cols,
41 MaxRowsAtCompileTime = _MaxRows,
42 MaxColsAtCompileTime = _MaxCols,
43 Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
44 Options = _Options,
45 InnerStrideAtCompileTime = 1,
46 OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
47
48 // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
49 EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
50 Alignment = actual_alignment
51 };
52};
53}
54
176
177template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
179 : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
180{
181 public:
182
186 typedef PlainObjectBase<Matrix> Base;
187
188 enum { Options = _Options };
189
190 EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
191
192 typedef typename Base::PlainObject PlainObject;
193
194 using Base::base;
195 using Base::coeffRef;
196
205 EIGEN_DEVICE_FUNC
206 EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
207 {
208 return Base::_set(other);
209 }
210
221 template<typename OtherDerived>
222 EIGEN_DEVICE_FUNC
223 EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other)
224 {
225 return Base::_set(other);
226 }
227
232 template<typename OtherDerived>
233 EIGEN_DEVICE_FUNC
234 EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
235 {
236 return Base::operator=(other);
237 }
238
239 template<typename OtherDerived>
240 EIGEN_DEVICE_FUNC
241 EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
242 {
243 return Base::operator=(func);
244 }
245
256 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
258 {
259 Base::_check_template_params();
260 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
261 }
262
263 // FIXME is it still needed
264 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
265 explicit Matrix(internal::constructor_without_unaligned_array_assert)
266 : Base(internal::constructor_without_unaligned_array_assert())
267 { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
268
269#if EIGEN_HAS_RVALUE_REFERENCES
270 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
271 Matrix(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
272 : Base(std::move(other))
273 {
274 Base::_check_template_params();
275 }
276 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
277 Matrix& operator=(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
278 {
279 Base::operator=(std::move(other));
280 return *this;
281 }
282#endif
283
284#if EIGEN_HAS_CXX11
300 template <typename... ArgTypes>
301 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
302 Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
303 : Base(a0, a1, a2, a3, args...) {}
304
328 EIGEN_DEVICE_FUNC
329 explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
330#endif // end EIGEN_HAS_CXX11
331
332#ifndef EIGEN_PARSED_BY_DOXYGEN
333
334 // This constructor is for both 1x1 matrices and dynamic vectors
335 template<typename T>
336 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
337 explicit Matrix(const T& x)
338 {
339 Base::_check_template_params();
340 Base::template _init1<T>(x);
341 }
342
343 template<typename T0, typename T1>
344 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
345 Matrix(const T0& x, const T1& y)
346 {
347 Base::_check_template_params();
348 Base::template _init2<T0,T1>(x, y);
349 }
350
351
352#else
354 EIGEN_DEVICE_FUNC
355 explicit Matrix(const Scalar *data);
356
369 EIGEN_STRONG_INLINE explicit Matrix(Index dim);
372 Matrix(const Scalar& x);
385 EIGEN_DEVICE_FUNC
386 Matrix(Index rows, Index cols);
387
390 Matrix(const Scalar& x, const Scalar& y);
391 #endif // end EIGEN_PARSED_BY_DOXYGEN
392
396 EIGEN_DEVICE_FUNC
397 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
398 {
399 Base::_check_template_params();
400 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
401 m_storage.data()[0] = x;
402 m_storage.data()[1] = y;
403 m_storage.data()[2] = z;
404 }
405
408 EIGEN_DEVICE_FUNC
409 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
410 {
411 Base::_check_template_params();
412 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
413 m_storage.data()[0] = x;
414 m_storage.data()[1] = y;
415 m_storage.data()[2] = z;
416 m_storage.data()[3] = w;
417 }
418
419
421 EIGEN_DEVICE_FUNC
422 EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
423 { }
424
428 template<typename OtherDerived>
429 EIGEN_DEVICE_FUNC
430 EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
431 : Base(other.derived())
432 { }
433
434 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
435 inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
436 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
437 inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
438
440
441 template<typename OtherDerived>
442 EIGEN_DEVICE_FUNC
444 template<typename OtherDerived>
445 EIGEN_DEVICE_FUNC
447
448 // allow to extend Matrix outside Eigen
449 #ifdef EIGEN_MATRIX_PLUGIN
450 #include EIGEN_MATRIX_PLUGIN
451 #endif
452
453 protected:
454 template <typename Derived, typename OtherDerived, bool IsVector>
455 friend struct internal::conservative_resize_like_impl;
456
457 using Base::m_storage;
458};
459
488
489#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
490 \
491 \
492typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
493 \
494 \
495typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
496 \
497 \
498typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
499
500#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
501 \
502 \
503typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
504 \
505 \
506typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
507
508#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
509EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
510EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
511EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
512EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
513EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
514EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
515EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
516
517EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
518EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
519EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
520EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
521EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
522
523#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
524#undef EIGEN_MAKE_TYPEDEFS
525#undef EIGEN_MAKE_FIXED_TYPEDEFS
526
527#if EIGEN_HAS_CXX11
528
529#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
530 \
531 \
532template <typename Type> \
533using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
534 \
535 \
536template <typename Type> \
537using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
538 \
539 \
540template <typename Type> \
541using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
542
543#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
544 \
545 \
546template <typename Type> \
547using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
548 \
549 \
550template <typename Type> \
551using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
552
553EIGEN_MAKE_TYPEDEFS(2, 2)
554EIGEN_MAKE_TYPEDEFS(3, 3)
555EIGEN_MAKE_TYPEDEFS(4, 4)
556EIGEN_MAKE_TYPEDEFS(Dynamic, X)
557EIGEN_MAKE_FIXED_TYPEDEFS(2)
558EIGEN_MAKE_FIXED_TYPEDEFS(3)
559EIGEN_MAKE_FIXED_TYPEDEFS(4)
560
563template <typename Type, int Size>
564using Vector = Matrix<Type, Size, 1>;
565
568template <typename Type, int Size>
569using RowVector = Matrix<Type, 1, Size>;
570
571#undef EIGEN_MAKE_TYPEDEFS
572#undef EIGEN_MAKE_FIXED_TYPEDEFS
573
574#endif // EIGEN_HAS_CXX11
575
576} // end namespace Eigen
577
578#endif // EIGEN_MATRIX_H
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:47
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
Matrix(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w)
Constructs an initialized 4D vector with given coefficients.
Definition Matrix.h:409
Matrix(Index dim)
Constructs a vector or row-vector with given dimension. This is only for vectors (either row-vectors ...
Matrix(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Construct a row of column vector with fixed size from an arbitrary number of coefficients....
Definition Matrix.h:302
Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition Matrix.h:206
Matrix(const Scalar &x, const Scalar &y)
Constructs an initialized 2D vector with given coefficients.
Matrix(const RotationBase< OtherDerived, ColsAtCompileTime > &r)
Constructs a Dim x Dim rotation matrix from the rotation r.
Definition RotationBase.h:141
Matrix(const Scalar &x, const Scalar &y, const Scalar &z)
Constructs an initialized 3D vector with given coefficients.
Definition Matrix.h:397
Matrix(const Matrix &other)
Copy constructor.
Definition Matrix.h:422
Matrix(const std::initializer_list< std::initializer_list< Scalar > > &list)
Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by ro...
Definition Matrix.h:329
Matrix()
Default constructor.
Definition Matrix.h:257
Matrix(const Scalar &x)
Constructs an initialized 1x1 matrix with the given coefficient.
PlainObjectBase< Matrix > Base
Definition Matrix.h:186
Matrix(const EigenBase< OtherDerived > &other)
Copy constructor for generic expressions.
Definition Matrix.h:430
Matrix(const Scalar *data)
Constructs a fixed-sized matrix initialized with coefficients starting at data.
Matrix & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition Matrix.h:234
Matrix(Index rows, Index cols)
Constructs an uninitialized matrix with rows rows and cols columns.
Matrix & _set(const DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:777
Matrix & operator=(const PlainObjectBase &other)
Definition PlainObjectBase.h:449
const Scalar * data() const
Definition PlainObjectBase.h:247
Common base class for compact rotation representations.
Definition RotationBase.h:30
@ DontAlign
Definition Constants.h:325
@ RowMajor
Definition Constants.h:321
const unsigned int PacketAccessBit
Definition Constants.h:94
const unsigned int LinearAccessBit
Definition Constants.h:130
const unsigned int DirectAccessBit
Definition Constants.h:155
const unsigned int RowMajorBit
Definition Constants.h:66
Matrix< Type, 1, Size > RowVector
[c++11]
Definition Matrix.h:569
Matrix< Type, Size, 1 > Vector
[c++11]
Definition Matrix.h:564
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
Definition Constants.h:22
Definition EigenBase.h:30