Medial Code Documentation
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
138namespace internal {
139template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
140struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
141{
142private:
144 typedef typename find_best_packet<_Scalar,size>::type PacketScalar;
145 enum {
146 row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
147 is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
148 max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
150 actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
151 required_alignment = unpacket_traits<PacketScalar>::alignment,
152 packet_access_bit = packet_traits<_Scalar>::Vectorizable && (actual_alignment>=required_alignment) ? PacketAccessBit : 0
153 };
154
155public:
156 typedef _Scalar Scalar;
157 typedef Dense StorageKind;
158 typedef Eigen::Index StorageIndex;
159 typedef MatrixXpr XprKind;
160 enum {
161 RowsAtCompileTime = _Rows,
162 ColsAtCompileTime = _Cols,
163 MaxRowsAtCompileTime = _MaxRows,
164 MaxColsAtCompileTime = _MaxCols,
166 Options = _Options,
167 InnerStrideAtCompileTime = 1,
168 OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
169
170 // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
171 EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
172 Alignment = actual_alignment
173 };
174};
175}
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
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
206 EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
207 {
208 return Base::_set(other);
209 }
210
221 template<typename OtherDerived>
223 EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other)
224 {
225 return Base::_set(other);
226 }
227
228 /* Here, doxygen failed to copy the brief information when using \copydoc */
229
234 template<typename OtherDerived>
235 EIGEN_DEVICE_FUNC
236 EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
237 {
238 return Base::operator=(other);
239 }
240
241 template<typename OtherDerived>
243 EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
244 {
245 return Base::operator=(func);
246 }
247
258 EIGEN_DEVICE_FUNC
259 EIGEN_STRONG_INLINE Matrix() : Base()
260 {
261 Base::_check_template_params();
262 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
263 }
264
265 // FIXME is it still needed
268 : Base(internal::constructor_without_unaligned_array_assert())
269 { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
270
271#ifdef EIGEN_HAVE_RVALUE_REFERENCES
272 EIGEN_DEVICE_FUNC
273 Matrix(Matrix&& other)
274 : Base(std::move(other))
275 {
276 Base::_check_template_params();
277 if (RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic)
278 Base::_set_noalias(other);
279 }
280 EIGEN_DEVICE_FUNC
281 Matrix& operator=(Matrix&& other)
282 {
283 other.swap(*this);
284 return *this;
285 }
286#endif
287
288 #ifndef EIGEN_PARSED_BY_DOXYGEN
289
290 // This constructor is for both 1x1 matrices and dynamic vectors
291 template<typename T>
292 EIGEN_DEVICE_FUNC
293 EIGEN_STRONG_INLINE explicit Matrix(const T& x)
294 {
295 Base::_check_template_params();
296 Base::template _init1<T>(x);
297 }
298
299 template<typename T0, typename T1>
300 EIGEN_DEVICE_FUNC
301 EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y)
302 {
303 Base::_check_template_params();
304 Base::template _init2<T0,T1>(x, y);
305 }
306 #else
308 EIGEN_DEVICE_FUNC
309 explicit Matrix(const Scalar *data);
310
323 EIGEN_STRONG_INLINE explicit Matrix(Index dim);
325 Matrix(const Scalar& x);
338 EIGEN_DEVICE_FUNC
339 Matrix(Index rows, Index cols);
340
342 Matrix(const Scalar& x, const Scalar& y);
343 #endif
344
346 EIGEN_DEVICE_FUNC
347 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
348 {
349 Base::_check_template_params();
350 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
351 m_storage.data()[0] = x;
352 m_storage.data()[1] = y;
353 m_storage.data()[2] = z;
354 }
357 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
358 {
359 Base::_check_template_params();
360 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
361 m_storage.data()[0] = x;
362 m_storage.data()[1] = y;
363 m_storage.data()[2] = z;
364 m_storage.data()[3] = w;
365 }
366
367
370 EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
371 { }
372
376 template<typename OtherDerived>
378 EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
379 : Base(other.derived())
380 { }
381
382 EIGEN_DEVICE_FUNC inline Index innerStride() const { return 1; }
383 EIGEN_DEVICE_FUNC inline Index outerStride() const { return this->innerSize(); }
384
386
387 template<typename OtherDerived>
388 EIGEN_DEVICE_FUNC
389 explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
390 template<typename OtherDerived>
391 EIGEN_DEVICE_FUNC
392 Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
393
394 // allow to extend Matrix outside Eigen
395 #ifdef EIGEN_MATRIX_PLUGIN
396 #include EIGEN_MATRIX_PLUGIN
397 #endif
398
399 protected:
400 template <typename Derived, typename OtherDerived, bool IsVector>
401 friend struct internal::conservative_resize_like_impl;
402
403 using Base::m_storage;
404};
405
426#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
427 \
428typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
429 \
430typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
431 \
432typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
433
434#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
435 \
436typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
437 \
438typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
439
440#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
441EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
442EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
443EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
444EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
445EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
446EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
447EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
448
449EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
450EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
451EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
452EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
453EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
454
455#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
456#undef EIGEN_MAKE_TYPEDEFS
457#undef EIGEN_MAKE_FIXED_TYPEDEFS
458
459} // end namespace Eigen
460
461#endif // EIGEN_MATRIX_H
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar &x, const Scalar &y, const Scalar &z)
Constructs an initialized 3D vector with given coefficients.
Definition Matrix.h:347
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix()
Default constructor.
Definition Matrix.h:259
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition Matrix.h:206
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition Matrix.h:236
PlainObjectBase< Matrix > Base
Base class typedef.
Definition Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const EigenBase< OtherDerived > &other)
Copy constructor for generic expressions.
Definition Matrix.h:378
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Matrix &other)
Copy constructor.
Definition Matrix.h:370
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w)
Constructs an initialized 4D vector with given coefficients.
Definition Matrix.h:357
Dense storage base class for matrices and arrays.
Definition PlainObjectBase.h:93
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition PlainObjectBase.h:228
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const PlainObjectBase &other)
This is a special case of the templated operator=.
Definition PlainObjectBase.h:430
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition PlainObjectBase.h:680
Pseudo expression representing a solving operation.
Definition Solve.h:63
Definition XprHelper.h:212
@ DontAlign
Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated,...
Definition Constants.h:326
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:322
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:88
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition Constants.h:124
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition Constants.h:149
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
Definition StdDeque.h:58
The type used to identify a dense storage.
Definition Constants.h:490
The type used to identify a matrix expression.
Definition Constants.h:505
Definition GenericPacketMath.h:90
Definition XprHelper.h:222
Definition ForwardDeclarations.h:17
Definition XprHelper.h:119
Definition inference.c:32