Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
DenseBase.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5// Copyright (C) 2008-2010 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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_DENSEBASE_H
13#define EIGEN_DENSEBASE_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
20// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
21EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned, THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE)
22
23
38template <typename Derived>
40#ifndef EIGEN_PARSED_BY_DOXYGEN
41 : public DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>
42#else
43 : public DenseCoeffsBase<Derived, DirectWriteAccessors>
44#endif // not EIGEN_PARSED_BY_DOXYGEN
45{
46 public:
51
52 using StorageKind = typename internal::traits<Derived>::StorageKind;
53
60 using StorageIndex = typename internal::traits<Derived>::StorageIndex;
61
63 using Scalar = typename internal::traits<Derived>::Scalar;
64
66 *
67 * It is an alias for the Scalar type */
69
70 using RealScalar = typename NumTraits<Scalar>::Real;
71 using Base = DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>;
72
73 using Base::coeff;
74 using Base::coeffByOuterInner;
75 using Base::colIndexByOuterInner;
76 using Base::cols;
77 using Base::const_cast_derived;
78 using Base::derived;
79 using Base::rowIndexByOuterInner;
80 using Base::rows;
81 using Base::size;
82 using Base::operator();
83 using Base::operator[];
84 using Base::colStride;
85 using Base::innerStride;
86 using Base::outerStride;
87 using Base::rowStride;
88 using Base::stride;
89 using Base::w;
90 using Base::x;
91 using Base::y;
92 using Base::z;
93 using CoeffReturnType = typename Base::CoeffReturnType;
94
95 enum {
96
97 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
102
103 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
108
109 SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::value),
113
114 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
123 */
125 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
128
130
135
136 MaxSizeAtCompileTime = internal::size_at_compile_time(internal::traits<Derived>::MaxRowsAtCompileTime,
137 internal::traits<Derived>::MaxColsAtCompileTime),
140 * this value is set to \a Dynamic.
141 *
142 * This value is useful to know when evaluating an expression, in order to determine
143 * whether it is possible to avoid doing a dynamic memory allocation.
144 *
145 * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
146 */
147
149 internal::traits<Derived>::RowsAtCompileTime == 1 || internal::traits<Derived>::ColsAtCompileTime == 1,
154
156 : bool(IsVectorAtCompileTime) ? 1
157 : 2,
158 /**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors,
159 * and 2 for matrices.
160 */
161
162 Flags = internal::traits<Derived>::Flags,
166
169 InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
170 : int(IsRowMajor) ? int(ColsAtCompileTime)
171 : int(RowsAtCompileTime),
172
173 InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::value,
174 OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::value
175 };
176
177 using PacketScalar = typename internal::find_best_packet<Scalar, SizeAtCompileTime>::type;
178
179 enum { IsPlainObjectBase = 0 };
180
184 Matrix<typename internal::traits<Derived>::Scalar, internal::traits<Derived>::RowsAtCompileTime,
185 internal::traits<Derived>::ColsAtCompileTime,
186 AutoAlign | (internal::traits<Derived>::Flags & RowMajorBit ? RowMajor : ColMajor),
187 internal::traits<Derived>::MaxRowsAtCompileTime, internal::traits<Derived>::MaxColsAtCompileTime>;
188
192 Array<typename internal::traits<Derived>::Scalar, internal::traits<Derived>::RowsAtCompileTime,
193 internal::traits<Derived>::ColsAtCompileTime,
194 AutoAlign | (internal::traits<Derived>::Flags & RowMajorBit ? RowMajor : ColMajor),
195 internal::traits<Derived>::MaxRowsAtCompileTime, internal::traits<Derived>::MaxColsAtCompileTime>;
196
203 using PlainObject = std::conditional_t<std::is_same<typename internal::traits<Derived>::XprKind, MatrixXpr>::value,
205
211 EIGEN_DEVICE_FUNC constexpr Index outerSize() const {
212 return IsVectorAtCompileTime ? 1 : int(IsRowMajor) ? this->rows() : this->cols();
213 }
214
218 * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a
219 * column-major matrix, and the number of columns for a row-major matrix. */
220 EIGEN_DEVICE_FUNC constexpr Index innerSize() const {
221 return IsVectorAtCompileTime ? this->size() : int(IsRowMajor) ? this->cols() : this->rows();
222 }
223
224 /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
225 * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and
226 * does nothing else.
227 */
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.");
231 }
232
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.");
241 }
242
243#ifndef EIGEN_PARSED_BY_DOXYGEN
245 using ConstantReturnType = CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>;
247 using ZeroReturnType = CwiseNullaryOp<internal::scalar_zero_op<Scalar>, PlainObject>;
248 // Keep typedef: EIGEN_DEPRECATED uses __declspec on MSVC, which cannot annotate a using declaration.
249 /** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */
250 EIGEN_DEPRECATED typedef CwiseNullaryOp<internal::linspaced_op<Scalar>, PlainObject> SequentialLinSpacedReturnType;
252 using RandomAccessLinSpacedReturnType = CwiseNullaryOp<internal::linspaced_op<Scalar>, PlainObject>;
253
254 using RandomAccessEqualSpacedReturnType = CwiseNullaryOp<internal::equalspaced_op<Scalar>, PlainObject>;
257 internal::traits<Derived>::ColsAtCompileTime, 1>;
258
259#endif // not EIGEN_PARSED_BY_DOXYGEN
260
262 template <typename OtherDerived>
263 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other);
264
268 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator=(const DenseBase& other);
269
270 template <typename OtherDerived>
271 EIGEN_DEVICE_FUNC constexpr Derived& operator=(const EigenBase<OtherDerived>& other);
272
273 template <typename OtherDerived>
274 EIGEN_DEVICE_FUNC constexpr Derived& operator+=(const EigenBase<OtherDerived>& other);
275
276 template <typename OtherDerived>
277 EIGEN_DEVICE_FUNC constexpr Derived& operator-=(const EigenBase<OtherDerived>& other);
278
279 template <typename OtherDerived>
280 EIGEN_DEVICE_FUNC Derived& operator=(const ReturnByValue<OtherDerived>& func);
281
284 template <typename OtherDerived>
286 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC constexpr Derived& lazyAssign(const DenseBase<OtherDerived>& other);
288 EIGEN_DEVICE_FUNC CommaInitializer<Derived> operator<<(const Scalar& s);
289
290 template <unsigned int Added, unsigned int Removed>
292 EIGEN_DEPRECATED const Derived& flagged() const {
293 return derived();
294 }
295
296 template <typename OtherDerived>
297 EIGEN_DEVICE_FUNC CommaInitializer<Derived> operator<<(const DenseBase<OtherDerived>& other);
298
299 using TransposeReturnType = Transpose<Derived>;
300 EIGEN_DEVICE_FUNC TransposeReturnType transpose();
301 using ConstTransposeReturnType = Transpose<const Derived>;
302 EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const;
303 EIGEN_DEVICE_FUNC void transposeInPlace();
304
305 EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(Index rows, Index cols, const Scalar& value);
306 EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(Index size, const Scalar& value);
307 EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(const Scalar& value);
308
309 EIGEN_DEPRECATED_WITH_REASON("The method may result in accuracy loss. Use .EqualSpaced() instead.")
310 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar& low,
311 const Scalar& high);
312 EIGEN_DEPRECATED_WITH_REASON("The method may result in accuracy loss. Use .EqualSpaced() instead.")
313 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, const Scalar& low,
314 const Scalar& high);
315
316 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Index size, const Scalar& low,
317 const Scalar& high);
318 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(const Scalar& low, const Scalar& high);
319
320 EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(Index size, const Scalar& low,
321 const Scalar& step);
322 EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(const Scalar& low, const Scalar& step);
323
324 template <typename CustomNullaryOp>
325 EIGEN_DEVICE_FUNC static const CwiseNullaryOp<CustomNullaryOp, PlainObject> NullaryExpr(Index rows, Index cols,
326 const CustomNullaryOp& func);
327 template <typename CustomNullaryOp>
328 EIGEN_DEVICE_FUNC static const CwiseNullaryOp<CustomNullaryOp, PlainObject> NullaryExpr(Index size,
329 const CustomNullaryOp& func);
330 template <typename CustomNullaryOp>
331 EIGEN_DEVICE_FUNC static const CwiseNullaryOp<CustomNullaryOp, PlainObject> NullaryExpr(const CustomNullaryOp& func);
332
333 EIGEN_DEVICE_FUNC static const ZeroReturnType Zero(Index rows, Index cols);
334 EIGEN_DEVICE_FUNC static const ZeroReturnType Zero(Index size);
335 EIGEN_DEVICE_FUNC static const ZeroReturnType Zero();
336 EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols);
337 EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size);
338 EIGEN_DEVICE_FUNC static const ConstantReturnType Ones();
339
340 EIGEN_DEVICE_FUNC void fill(const Scalar& value);
341 EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value);
342 EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
343 EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high);
344 EIGEN_DEVICE_FUNC Derived& setEqualSpaced(Index size, const Scalar& low, const Scalar& step);
345 EIGEN_DEVICE_FUNC Derived& setEqualSpaced(const Scalar& low, const Scalar& step);
346 EIGEN_DEVICE_FUNC Derived& setZero();
347 EIGEN_DEVICE_FUNC Derived& setOnes();
348 EIGEN_DEVICE_FUNC Derived& setRandom();
349
350 template <typename OtherDerived>
351 EIGEN_DEVICE_FUNC constexpr bool isApprox(const DenseBase<OtherDerived>& other,
352 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
353 EIGEN_DEVICE_FUNC constexpr bool isMuchSmallerThan(
354 const RealScalar& other, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
355 template <typename OtherDerived>
356 EIGEN_DEVICE_FUNC constexpr bool isMuchSmallerThan(
357 const DenseBase<OtherDerived>& other, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
358
359 EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value,
360 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
361 EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value,
362 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
363 EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
364 EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
365
366 EIGEN_DEVICE_FUNC inline bool hasNaN() const;
367 EIGEN_DEVICE_FUNC inline bool allFinite() const;
368
369 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other);
370 template <bool Enable = internal::complex_array_access<Scalar>::value, typename = std::enable_if_t<Enable>>
371 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator*=(const RealScalar& other);
372
373 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other);
374 template <bool Enable = internal::complex_array_access<Scalar>::value, typename = std::enable_if_t<Enable>>
375 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator/=(const RealScalar& other);
376 // A template: naming IntDivider<Scalar> directly would instantiate it during overload resolution for a /= 2.0.
377 template <typename DividerScalar>
378 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const IntDivider<DividerScalar>& divider);
379
380 using EvalReturnType = internal::add_const_on_value_type_t<typename internal::eval<Derived>::type>;
389 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvalReturnType eval() const {
390 // Even though MSVC does not honor strong inlining when the return type
391 // is a dynamic matrix, we desperately need strong inlining for fixed
392 // size types on MSVC.
393 return typename internal::eval<Derived>::type(derived());
394 }
395
399 template <typename OtherDerived>
400 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(const DenseBase<OtherDerived>& other) {
401 EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase, THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
402 EIGEN_INTERNAL_ASSERT_SAME_SHAPE(*this, other);
403 call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
404 }
405
409 template <typename OtherDerived>
410 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(PlainObjectBase<OtherDerived>& other) {
411 EIGEN_INTERNAL_ASSERT_SAME_SHAPE(*this, other);
412 call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
413 }
414
415 EIGEN_DEVICE_FUNC constexpr inline const NestByValue<Derived> nestByValue() const;
416
417 EIGEN_DEVICE_FUNC Scalar sum() const;
418 EIGEN_DEVICE_FUNC Scalar mean() const;
419 EIGEN_DEVICE_FUNC Scalar trace() const;
420
421 EIGEN_DEVICE_FUNC Scalar prod() const;
422
423 // The default PropagateFast gives undefined behavior on NaN inputs but the fastest code.
424 template <int NaNPropagation = PropagateFast>
425 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const;
426 template <int NaNPropagation = PropagateFast>
427 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const;
428
429 template <int NaNPropagation = PropagateFast, typename IndexType>
430 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
431 template <int NaNPropagation = PropagateFast, typename IndexType>
432 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
433 template <int NaNPropagation = PropagateFast, typename IndexType>
434 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
435 template <int NaNPropagation = PropagateFast, typename IndexType>
436 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
438 template <typename BinaryOp>
439 EIGEN_DEVICE_FUNC Scalar redux(const BinaryOp& func) const;
440
441 template <typename Visitor>
442 EIGEN_DEVICE_FUNC void visit(Visitor& func) const;
443
451 inline const WithFormat<Derived> format(const IOFormat& fmt) const { return WithFormat<Derived>(derived(), fmt); }
452
454 EIGEN_DEVICE_FUNC CoeffReturnType value() const {
455 EIGEN_INTERNAL_ASSERT_SCALAR(*this);
456 return derived().coeff(0, 0);
457 }
458
459 EIGEN_DEVICE_FUNC bool all() const;
460 EIGEN_DEVICE_FUNC bool any() const;
461 EIGEN_DEVICE_FUNC Index count() const;
462
463 using RowwiseReturnType = VectorwiseOp<Derived, Horizontal>;
464 using ConstRowwiseReturnType = const VectorwiseOp<const Derived, Horizontal>;
465 using ColwiseReturnType = VectorwiseOp<Derived, Vertical>;
466 using ConstColwiseReturnType = const VectorwiseOp<const Derived, Vertical>;
467
468 /** \returns a VectorwiseOp wrapper of *this for broadcasting and partial reductions
469 *
470 * Example: \include MatrixBase_rowwise.cpp
471 * Output: \verbinclude MatrixBase_rowwise.out
472 *
473 * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
474 */
475 // Code moved here due to a CUDA compiler bug
476 EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const { return ConstRowwiseReturnType(derived()); }
477 EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();
478
486 EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const { return ConstColwiseReturnType(derived()); }
487 EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
488
489 using RandomReturnType = CwiseNullaryOp<internal::scalar_random_op<Scalar>, PlainObject>;
490 static const RandomReturnType Random(Index rows, Index cols);
491 static const RandomReturnType Random(Index size);
492 static const RandomReturnType Random();
493
494 template <typename ThenDerived, typename ElseDerived>
495 inline EIGEN_DEVICE_FUNC constexpr CwiseTernaryOp<
496 internal::scalar_boolean_select_op<typename DenseBase<ThenDerived>::Scalar,
497 typename DenseBase<ElseDerived>::Scalar, Scalar>,
498 ThenDerived, ElseDerived, Derived>
499 select(const DenseBase<ThenDerived>& thenMatrix, const DenseBase<ElseDerived>& elseMatrix) const;
500
501 template <typename ThenDerived>
502 inline EIGEN_DEVICE_FUNC constexpr CwiseTernaryOp<
503 internal::scalar_boolean_select_op<typename DenseBase<ThenDerived>::Scalar,
505 ThenDerived, typename DenseBase<ThenDerived>::ConstantReturnType, Derived>
506 select(const DenseBase<ThenDerived>& thenMatrix, const typename DenseBase<ThenDerived>::Scalar& elseScalar) const;
507
508 template <typename ElseDerived>
509 inline EIGEN_DEVICE_FUNC constexpr CwiseTernaryOp<
510 internal::scalar_boolean_select_op<typename DenseBase<ElseDerived>::Scalar,
512 typename DenseBase<ElseDerived>::ConstantReturnType, ElseDerived, Derived>
513 select(const typename DenseBase<ElseDerived>::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
514
515 template <int p>
516 EIGEN_DEVICE_FUNC RealScalar lpNorm() const;
517
518 template <int RowFactor, int ColFactor>
519 EIGEN_DEVICE_FUNC const Replicate<Derived, RowFactor, ColFactor> replicate() const;
520
525
531 template <typename NRowsType, typename NColsType>
532 EIGEN_DEVICE_FUNC const
533 Replicate<Derived, internal::get_fixed_value<NRowsType>::value, internal::get_fixed_value<NColsType>::value>
534 replicate(NRowsType nRows, NColsType nCols) const {
535 return Replicate<Derived, internal::get_fixed_value<NRowsType>::value, internal::get_fixed_value<NColsType>::value>(
536 derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols));
537 }
541
545 * \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), DenseBase::replicate(NRowsType,NColsType) const,
546 * class Replicate
547 */
548 // Code moved here due to a CUDA compiler bug
549 EIGEN_DEVICE_FUNC const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const {
550 return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor);
551 }
552
553 using ReverseReturnType = Reverse<Derived, BothDirections>;
554 using ConstReverseReturnType = const Reverse<const Derived, BothDirections>;
555 EIGEN_DEVICE_FUNC ReverseReturnType reverse();
557 // Code moved here due to a CUDA compiler bug
558 EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const { return ConstReverseReturnType(derived()); }
559 EIGEN_DEVICE_FUNC void reverseInPlace();
560
561#ifdef EIGEN_PARSED_BY_DOXYGEN
565 using iterator = random_access_iterator_type;
567 using const_iterator = random_access_iterator_type;
568#else
569 using iterator_type =
570 std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit, internal::pointer_based_stl_iterator<Derived>,
571 internal::generic_randaccess_stl_iterator<Derived>>;
572
573 using const_iterator_type = std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit,
574 internal::pointer_based_stl_iterator<const Derived>,
575 internal::generic_randaccess_stl_iterator<const Derived>>;
577 // Stl-style iterators are supported only for vectors.
578
579 using iterator = std::conditional_t<IsVectorAtCompileTime, iterator_type, void>;
580
581 using const_iterator = std::conditional_t<IsVectorAtCompileTime, const_iterator_type, void>;
582#endif
583
584 inline iterator begin();
585 inline const_iterator begin() const;
586 inline const_iterator cbegin() const;
587 inline iterator end();
588 inline const_iterator end() const;
589 inline const_iterator cend() const;
590
591 using RealViewReturnType = std::conditional_t<NumTraits<Scalar>::IsComplex, RealView<Derived>, Derived&>;
592 using ConstRealViewReturnType =
593 std::conditional_t<NumTraits<Scalar>::IsComplex, RealView<const Derived>, const Derived&>;
594
604 /// \code m.realView().cwiseAbs().maxCoeff() \endcode
605 /// covers both components in a single vectorized pass. Operations that must distinguish the
606 /// components, or that need only one of them, still require real()/imag().
607 ///
608 /// Writing through the returned expression additionally requires the scalar type to be
609 /// std::complex, whose storage the standard fixes as its two components interleaved.
610 ///
611 /// \sa real(), imag()
612 EIGEN_DEVICE_FUNC RealViewReturnType realView();
614 EIGEN_DEVICE_FUNC ConstRealViewReturnType realView() const;
615
616#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
617#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
618#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
619#define EIGEN_DOC_UNARY_ADDONS(X, Y)
620#include "../plugins/CommonCwiseUnaryOps.inc"
621#include "../plugins/BlockMethods.inc"
622// Defines operator()(const RowIndices&, const ColIndices&) and other indexed view methods.
623#include "../plugins/IndexedViewMethods.inc"
624#include "../plugins/ReshapedMethods.inc"
625#ifdef EIGEN_DENSEBASE_PLUGIN
626#include EIGEN_DENSEBASE_PLUGIN
627#endif
628#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
629#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
630#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
631#undef EIGEN_DOC_UNARY_ADDONS
632
633 // disable the use of evalTo for dense objects with a nice compilation error
634 template <typename Dest>
635 EIGEN_DEVICE_FUNC inline void evalTo(Dest&) const {
636 EIGEN_STATIC_ASSERT((std::is_same<Dest, void>::value),
637 THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
639
640 protected:
641 EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase)
643#ifdef EIGEN_INTERNAL_DEBUGGING
644 EIGEN_DEVICE_FUNC constexpr DenseBase() {
645 /* Just checks for self-consistency of the flags.
646 * Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down
647 */
648 EIGEN_STATIC_ASSERT(
649 (internal::check_implication(MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1, int(IsRowMajor)) &&
650 internal::check_implication(MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1, int(!IsRowMajor))),
651 INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
652 }
653#else
654 EIGEN_DEVICE_FUNC constexpr DenseBase() = default;
655#endif
656
657 private:
658 EIGEN_DEVICE_FUNC explicit DenseBase(int);
659 EIGEN_DEVICE_FUNC DenseBase(int, int);
660 template <typename OtherDerived>
661 EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&);
662};
663
666template <typename DerivedA, typename DerivedB>
667EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
668 // Use forwarding references to capture all combinations of cv-qualified l+r-value cases.
669 std::enable_if_t<std::is_base_of<DenseBase<std::decay_t<DerivedA>>, std::decay_t<DerivedA>>::value &&
670 std::is_base_of<DenseBase<std::decay_t<DerivedB>>, std::decay_t<DerivedB>>::value,
671 void>
672 swap(DerivedA&& a, DerivedB&& b) {
673 a.swap(b);
674}
675
676} // end namespace Eigen
677
678#endif // EIGEN_DENSEBASE_H
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:828
Eigen::InnerIterator< Derived > InnerIterator
Definition DenseBase.h:50
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Predicator.h:615
CommaInitializer< Derived > operator<<(const Scalar &s)
Definition CommaInitializer.h:135
const WithFormat< Derived > format(const IOFormat &fmt) const
Definition DenseBase.h:451
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:314
constexpr ColXpr col(Index i)
Definition DenseBase.h:1082
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
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:40
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:460
void swap(PlainObjectBase< OtherDerived > &other)
Definition DenseBase.h:410
const Replicate< Derived, internal::get_fixed_value< NRowsType >::value, internal::get_fixed_value< NColsType >::value > replicate(NRowsType nRows, NColsType nCols) const
Definition DenseBase.h:534
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
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Predicator.h:632
iterator begin()
Definition StlIterators.h:598
ConstColwiseReturnType colwise() const
Definition DenseBase.h:486
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
constexpr RowXpr row(Index i)
Definition DenseBase.h:1095
RealViewReturnType realView()
Definition RealView.h:361
const Replicate< Derived, Dynamic, Dynamic > replicate(Index rowFactor, Index colFactor) const
Definition DenseBase.h:549
internal::traits< Derived >::Scalar maxCoeff() const
Definition Redux.h:841
EIGEN_DEPRECATED constexpr Derived & lazyAssign(const DenseBase< OtherDerived > &other)
bool allFinite() const
Definition Predicator.h:609
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:454
constexpr bool isApprox(const DenseBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition ApproxComparisons.h:559
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
random_access_iterator_type const_iterator
Definition DenseBase.h:567
void fill(const Scalar &value)
Definition CwiseNullaryOp.h:323
ConstReverseReturnType reverse() const
Definition DenseBase.h:558
constexpr DenseBase()=default
ConstRowwiseReturnType rowwise() const
Definition DenseBase.h:476
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:649
EvalReturnType eval() const
Definition DenseBase.h:389
typename internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:63
constexpr Index innerSize() const
Definition DenseBase.h:220
Index count() const
Definition Visitor.h:470
Derived & setConstant(const Scalar &value)
Definition CwiseNullaryOp.h:333
Derived & setRandom()
Definition Random.h:130
void transposeInPlace()
Definition Transpose.h:333
Scalar value_type
Definition DenseBase.h:68
EIGEN_DEPRECATED const Derived & flagged() const
Definition DenseBase.h:292
RealScalar lpNorm() const
Definition Dot.h:544
iterator end()
Definition StlIterators.h:624
const_iterator cbegin() const
Definition StlIterators.h:614
const_iterator cend() const
Definition StlIterators.h:640
random_access_iterator_type iterator
Definition DenseBase.h:565
static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition CwiseNullaryOp.h:235
Derived & setZero()
Definition CwiseNullaryOp.h:521
void swap(const DenseBase< OtherDerived > &other)
Definition DenseBase.h:400
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:38
Divides integers by a divisor that is fixed at run time, with multiplications and shifts in place of ...
Definition IntegerDivision.h:440
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
Pseudo expression providing matrix output with given format.
Definition IO.h:106
@ 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
Stores a set of parameters controlling the way matrices are printed.
Definition IO.h:53
Definition Constants.h:557
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:267