12#ifndef EIGEN_DENSEBASE_H
13#define EIGEN_DENSEBASE_H
16#include "./InternalHeaderCheck.h"
21EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned, THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE)
38template <typename Derived>
40#ifndef EIGEN_PARSED_BY_DOXYGEN
41 :
public DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>
43 :
public DenseCoeffsBase<Derived, DirectWriteAccessors>
52 using StorageKind =
typename internal::traits<Derived>::StorageKind;
60 using StorageIndex =
typename internal::traits<Derived>::StorageIndex;
63 using Scalar =
typename internal::traits<Derived>::Scalar;
70 using RealScalar =
typename NumTraits<Scalar>::Real;
71 using Base = DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>;
74 using Base::coeffByOuterInner;
75 using Base::colIndexByOuterInner;
77 using Base::const_cast_derived;
79 using Base::rowIndexByOuterInner;
82 using Base::operator();
83 using Base::operator[];
84 using Base::colStride;
85 using Base::innerStride;
86 using Base::outerStride;
87 using Base::rowStride;
93 using CoeffReturnType =
typename Base::CoeffReturnType;
137 internal::traits<Derived>::MaxColsAtCompileTime),
149 internal::traits<Derived>::RowsAtCompileTime == 1 || internal::traits<Derived>::ColsAtCompileTime == 1,
162 Flags = internal::traits<Derived>::Flags,
173 InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::
value,
174 OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::
value
177 using PacketScalar =
typename internal::find_best_packet<Scalar, SizeAtCompileTime>::type;
179 enum { IsPlainObjectBase = 0 };
185 internal::traits<Derived>::ColsAtCompileTime,
187 internal::traits<Derived>::MaxRowsAtCompileTime, internal::traits<Derived>::MaxColsAtCompileTime>;
193 internal::traits<Derived>::ColsAtCompileTime,
195 internal::traits<Derived>::MaxRowsAtCompileTime, internal::traits<Derived>::MaxColsAtCompileTime>;
228 EIGEN_DEVICE_FUNC
void resize(Index newSize) {
229 EIGEN_ONLY_USED_FOR_DEBUG(newSize);
230 eigen_assert(newSize == this->size() &&
"DenseBase::resize() does not actually allow to resize.");
236 EIGEN_DEVICE_FUNC
void resize(Index rows, Index cols) {
237 EIGEN_ONLY_USED_FOR_DEBUG(rows);
238 EIGEN_ONLY_USED_FOR_DEBUG(cols);
239 eigen_assert(rows == this->rows() && cols == this->cols() &&
240 "DenseBase::resize() does not actually allow to resize.");
243#ifndef EIGEN_PARSED_BY_DOXYGEN
256 internal::traits<Derived>::ColsAtCompileTime, 1>;
261 template <
typename OtherDerived>
267 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE Derived&
operator=(
const DenseBase& other);
269 template <
typename OtherDerived>
272 template <
typename OtherDerived>
275 template <
typename OtherDerived>
278 template <
typename OtherDerived>
279 EIGEN_DEVICE_FUNC Derived&
operator=(
const ReturnByValue<OtherDerived>& func);
283 template <
typename OtherDerived>
289 template <
unsigned int Added,
unsigned int Removed>
291 EIGEN_DEPRECATED
const Derived&
flagged()
const {
295 template <
typename OtherDerived>
299 EIGEN_DEVICE_FUNC TransposeReturnType transpose();
301 EIGEN_DEVICE_FUNC
const ConstTransposeReturnType transpose()
const;
302 EIGEN_DEVICE_FUNC
void transposeInPlace();
304 EIGEN_DEVICE_FUNC
static const ConstantReturnType
Constant(Index rows, Index cols,
const Scalar&
value);
305 EIGEN_DEVICE_FUNC
static const ConstantReturnType
Constant(Index size,
const Scalar&
value);
308 EIGEN_DEPRECATED_WITH_REASON(
"The method may result in accuracy loss. Use .EqualSpaced() instead.")
309 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
LinSpaced(Sequential_t, Index size, const
Scalar& low,
311 EIGEN_DEPRECATED_WITH_REASON(
"The method may result in accuracy loss. Use .EqualSpaced() instead.")
312 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
LinSpaced(Sequential_t, const
Scalar& low,
315 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
LinSpaced(Index size, const
Scalar& low,
317 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
LinSpaced(const
Scalar& low, const
Scalar& high);
319 EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(Index size, const
Scalar& low,
321 EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(const
Scalar& low, const
Scalar& step);
323 template <typename CustomNullaryOp>
325 const CustomNullaryOp& func);
326 template <typename CustomNullaryOp>
328 const CustomNullaryOp& func);
329 template <typename CustomNullaryOp>
332 EIGEN_DEVICE_FUNC static const ZeroReturnType
Zero(Index rows, Index cols);
333 EIGEN_DEVICE_FUNC static const ZeroReturnType
Zero(Index size);
334 EIGEN_DEVICE_FUNC static const ZeroReturnType
Zero();
335 EIGEN_DEVICE_FUNC static const ConstantReturnType
Ones(Index rows, Index cols);
336 EIGEN_DEVICE_FUNC static const ConstantReturnType
Ones(Index size);
337 EIGEN_DEVICE_FUNC static const ConstantReturnType
Ones();
343 EIGEN_DEVICE_FUNC Derived& setEqualSpaced(Index size, const
Scalar& low, const
Scalar& step);
344 EIGEN_DEVICE_FUNC Derived& setEqualSpaced(const
Scalar& low, const
Scalar& step);
345 EIGEN_DEVICE_FUNC Derived&
setZero();
346 EIGEN_DEVICE_FUNC Derived&
setOnes();
349 template <typename OtherDerived>
352 EIGEN_DEVICE_FUNC constexpr
bool isMuchSmallerThan(
353 const RealScalar& other, const RealScalar& prec =
NumTraits<
Scalar>::dummy_precision()) const;
354 template <typename OtherDerived>
355 EIGEN_DEVICE_FUNC constexpr
bool isMuchSmallerThan(
365 EIGEN_DEVICE_FUNC inline
bool hasNaN() const;
366 EIGEN_DEVICE_FUNC inline
bool allFinite() const;
368 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator*=(const
Scalar& other);
369 template <
bool Enable = internal::complex_array_access<
Scalar>::
value, typename = std::enable_if_t<Enable>>
370 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator*=(const RealScalar& other);
372 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator/=(const
Scalar& other);
373 template <
bool Enable = internal::complex_array_access<
Scalar>::
value, typename = std::enable_if_t<Enable>>
374 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator/=(const RealScalar& other);
376 using EvalReturnType = internal::add_const_on_value_type_t<typename internal::
eval<Derived>::type>;
385 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvalReturnType
eval()
const {
389 return typename internal::eval<Derived>::type(derived());
395 template <
typename OtherDerived>
397 EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase, THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
398 eigen_assert(rows() == other.rows() && cols() == other.cols());
399 call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
405 template <
typename OtherDerived>
407 eigen_assert(rows() == other.rows() && cols() == other.cols());
408 call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
413 EIGEN_DEVICE_FUNC Scalar sum()
const;
414 EIGEN_DEVICE_FUNC Scalar mean()
const;
415 EIGEN_DEVICE_FUNC Scalar trace()
const;
417 EIGEN_DEVICE_FUNC Scalar prod()
const;
420 template <
int NaNPropagation = PropagateFast>
421 EIGEN_DEVICE_FUNC
typename internal::traits<Derived>::Scalar minCoeff()
const;
422 template <
int NaNPropagation = PropagateFast>
423 EIGEN_DEVICE_FUNC
typename internal::traits<Derived>::Scalar maxCoeff()
const;
425 template <
int NaNPropagation = PropagateFast,
typename IndexType>
426 EIGEN_DEVICE_FUNC
typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col)
const;
427 template <
int NaNPropagation = PropagateFast,
typename IndexType>
428 EIGEN_DEVICE_FUNC
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col)
const;
429 template <
int NaNPropagation = PropagateFast,
typename IndexType>
430 EIGEN_DEVICE_FUNC
typename internal::traits<Derived>::Scalar
minCoeff(IndexType* index)
const;
431 template <
int NaNPropagation = PropagateFast,
typename IndexType>
432 EIGEN_DEVICE_FUNC
typename internal::traits<Derived>::Scalar
maxCoeff(IndexType* index)
const;
434 template <
typename BinaryOp>
435 EIGEN_DEVICE_FUNC
Scalar redux(
const BinaryOp& func)
const;
437 template <
typename Visitor>
438 EIGEN_DEVICE_FUNC
void visit(Visitor& func)
const;
450 EIGEN_DEVICE_FUNC CoeffReturnType
value()
const {
451 EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) eigen_assert(this->rows() == 1 && this->cols() == 1);
452 return derived().coeff(0, 0);
455 EIGEN_DEVICE_FUNC
bool all()
const;
456 EIGEN_DEVICE_FUNC
bool any()
const;
457 EIGEN_DEVICE_FUNC Index count()
const;
472 EIGEN_DEVICE_FUNC
inline ConstRowwiseReturnType
rowwise()
const {
return ConstRowwiseReturnType(derived()); }
473 EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();
482 EIGEN_DEVICE_FUNC
inline ConstColwiseReturnType
colwise()
const {
return ConstColwiseReturnType(derived()); }
483 EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
486 static const RandomReturnType Random(Index rows, Index cols);
487 static const RandomReturnType Random(Index size);
488 static const RandomReturnType Random();
490 template <
typename ThenDerived,
typename ElseDerived>
492 internal::scalar_boolean_select_op<typename DenseBase<ThenDerived>::Scalar,
494 ThenDerived, ElseDerived, Derived>
497 template <
typename ThenDerived>
499 internal::scalar_boolean_select_op<typename DenseBase<ThenDerived>::Scalar,
504 template <
typename ElseDerived>
506 internal::scalar_boolean_select_op<typename DenseBase<ElseDerived>::Scalar,
512 RealScalar lpNorm()
const;
514 template <
int RowFactor,
int ColFactor>
527 template <
typename NRowsType,
typename NColsType>
528 EIGEN_DEVICE_FUNC
const
532 derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols));
551 EIGEN_DEVICE_FUNC ReverseReturnType reverse();
554 EIGEN_DEVICE_FUNC ConstReverseReturnType
reverse()
const {
return ConstReverseReturnType(derived()); }
555 EIGEN_DEVICE_FUNC
void reverseInPlace();
557#ifdef EIGEN_PARSED_BY_DOXYGEN
565 using iterator_type =
567 internal::generic_randaccess_stl_iterator<Derived>>;
570 internal::pointer_based_stl_iterator<const Derived>,
571 internal::generic_randaccess_stl_iterator<const Derived>>;
575 using iterator = std::conditional_t<IsVectorAtCompileTime, iterator_type, void>;
577 using const_iterator = std::conditional_t<IsVectorAtCompileTime, const_iterator_type, void>;
587 using RealViewReturnType = std::conditional_t<NumTraits<Scalar>::IsComplex, RealView<Derived>, Derived&>;
588 using ConstRealViewReturnType =
589 std::conditional_t<NumTraits<Scalar>::IsComplex, RealView<const Derived>,
const Derived&>;
608 EIGEN_DEVICE_FUNC RealViewReturnType
realView();
610 EIGEN_DEVICE_FUNC ConstRealViewReturnType
realView()
const;
612#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
613#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
614#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
615#define EIGEN_DOC_UNARY_ADDONS(X, Y)
616#include "../plugins/CommonCwiseUnaryOps.inc"
617#include "../plugins/BlockMethods.inc"
619#include "../plugins/IndexedViewMethods.inc"
620#include "../plugins/ReshapedMethods.inc"
621#ifdef EIGEN_DENSEBASE_PLUGIN
622#include EIGEN_DENSEBASE_PLUGIN
624#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
625#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
626#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
627#undef EIGEN_DOC_UNARY_ADDONS
630 template <
typename Dest>
631 EIGEN_DEVICE_FUNC
inline void evalTo(Dest&)
const {
632 EIGEN_STATIC_ASSERT((std::is_same<Dest, void>::value),
633 THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
639#ifdef EIGEN_INTERNAL_DEBUGGING
640 EIGEN_DEVICE_FUNC
constexpr DenseBase() {
647 INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
654 EIGEN_DEVICE_FUNC
explicit DenseBase(
int);
656 template <
typename OtherDerived>
662template <
typename DerivedA,
typename DerivedB>
663EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
665 std::enable_if_t<std::is_base_of<DenseBase<std::decay_t<DerivedA>>, std::decay_t<DerivedA>>::value &&
666 std::is_base_of<DenseBase<std::decay_t<DerivedB>>, std::decay_t<DerivedB>>::value,
668 swap(DerivedA&& a, DerivedB&& b) {
General-purpose arrays with easy API for coefficient-wise operations.
Definition Array.h:55
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:65
Generic expression where a coefficient-wise ternary operator is applied to three expressions.
Definition CwiseTernaryOp.h:87
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:45
internal::traits< Derived >::Scalar minCoeff() const
Definition Redux.h:786
Eigen::InnerIterator< Derived > InnerIterator
Definition DenseBase.h:50
CommaInitializer< Derived > operator<<(const Scalar &s)
Definition CommaInitializer.h:135
const WithFormat< Derived > format(const IOFormat &fmt) const
Definition DenseBase.h:447
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:314
Derived & setOnes()
Definition CwiseNullaryOp.h:661
void resize(Index rows, Index cols)
Definition DenseBase.h:236
constexpr Index outerSize() const
Definition DenseBase.h:211
void resize(Index newSize)
Definition DenseBase.h:228
random_access_iterator_type const_iterator
Definition DenseBase.h:563
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:113
constexpr Derived & operator=(const DenseBase< OtherDerived > &other)
Definition Assign.h:41
std::conditional_t< std::is_same< typename internal::traits< Derived >::XprKind, MatrixXpr >::value, PlainMatrix, PlainArray > PlainObject
The plain matrix or array type corresponding to this expression.
Definition DenseBase.h:203
void visit(Visitor &func) const
Definition Visitor.h:423
void swap(PlainObjectBase< OtherDerived > &other)
Definition DenseBase.h:406
const Replicate< Derived, internal::get_fixed_value< NRowsType >::value, internal::get_fixed_value< NColsType >::value > replicate(NRowsType nRows, NColsType nCols) const
Definition DenseBase.h:530
Array< typename internal::traits< Derived >::Scalar, internal::traits< Derived >::RowsAtCompileTime, internal::traits< Derived >::ColsAtCompileTime, AutoAlign|(internal::traits< Derived >::Flags &RowMajorBit ? RowMajor :ColMajor), internal::traits< Derived >::MaxRowsAtCompileTime, internal::traits< Derived >::MaxColsAtCompileTime > PlainArray
Definition DenseBase.h:191
iterator begin()
Definition StlIterators.h:576
ConstColwiseReturnType colwise() const
Definition DenseBase.h:482
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition CwiseNullaryOp.h:416
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition Replicate.h:111
static const ZeroReturnType Zero(Index rows, Index cols)
Definition CwiseNullaryOp.h:471
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition CwiseNullaryOp.h:186
RealViewReturnType realView()
Definition RealView.h:289
const Replicate< Derived, Dynamic, Dynamic > replicate(Index rowFactor, Index colFactor) const
Definition DenseBase.h:545
internal::traits< Derived >::Scalar maxCoeff() const
Definition Redux.h:799
EIGEN_DEPRECATED constexpr Derived & lazyAssign(const DenseBase< OtherDerived > &other)
Matrix< typename internal::traits< Derived >::Scalar, internal::traits< Derived >::RowsAtCompileTime, internal::traits< Derived >::ColsAtCompileTime, AutoAlign|(internal::traits< Derived >::Flags &RowMajorBit ? RowMajor :ColMajor), internal::traits< Derived >::MaxRowsAtCompileTime, internal::traits< Derived >::MaxColsAtCompileTime > PlainMatrix
Definition DenseBase.h:183
CoeffReturnType value() const
Definition DenseBase.h:450
constexpr bool isApprox(const DenseBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition ApproxComparisons.h:421
static const ConstantReturnType Ones(Index rows, Index cols)
Definition CwiseNullaryOp.h:598
typename internal::traits< Derived >::StorageIndex StorageIndex
The type used to store indices.
Definition DenseBase.h:60
@ IsVectorAtCompileTime
Definition DenseBase.h:148
@ SizeAtCompileTime
Definition DenseBase.h:109
@ MaxSizeAtCompileTime
Definition DenseBase.h:136
@ IsRowMajor
Definition DenseBase.h:167
@ NumDimensions
Definition DenseBase.h:155
@ Flags
Definition DenseBase.h:162
@ ColsAtCompileTime
Definition DenseBase.h:103
@ MaxColsAtCompileTime
Definition DenseBase.h:125
@ MaxRowsAtCompileTime
Definition DenseBase.h:114
@ RowsAtCompileTime
Definition DenseBase.h:97
void fill(const Scalar &value)
Definition CwiseNullaryOp.h:323
ConstReverseReturnType reverse() const
Definition DenseBase.h:554
constexpr DenseBase()=default
ConstRowwiseReturnType rowwise() const
Definition DenseBase.h:472
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:649
EvalReturnType eval() const
Definition DenseBase.h:385
typename internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:63
constexpr Index innerSize() const
Definition DenseBase.h:220
Derived & setConstant(const Scalar &value)
Definition CwiseNullaryOp.h:333
Derived & setRandom()
Definition Random.h:130
Scalar value_type
Definition DenseBase.h:68
EIGEN_DEPRECATED const Derived & flagged() const
Definition DenseBase.h:291
iterator end()
Definition StlIterators.h:602
const_iterator cbegin() const
Definition StlIterators.h:592
const_iterator cend() const
Definition StlIterators.h:618
static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition CwiseNullaryOp.h:235
bool allFinite() const
Definition Visitor.h:690
Derived & setZero()
Definition CwiseNullaryOp.h:521
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Visitor.h:711
random_access_iterator_type iterator
Definition DenseBase.h:561
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Visitor.h:696
void swap(const DenseBase< OtherDerived > &other)
Definition DenseBase.h:396
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:38
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Expression which must be nested by value.
Definition NestByValue.h:40
Dense storage base class for matrices and arrays.
Definition PlainObjectBase.h:110
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:65
Expression of the reverse of a vector or matrix.
Definition Reverse.h:66
Expression of the transpose of a matrix.
Definition Transpose.h:57
Pseudo expression providing broadcasting and partial reduction operations.
Definition VectorwiseOp.h:249
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
@ AutoAlign
Definition Constants.h:323
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int RowMajorBit
Definition Constants.h:71
Helper class used by the comma initializer operator.
Definition CommaInitializer.h:32
Definition EigenBase.h:34
Definition Constants.h:557
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233