Eigen  5.0.1
 
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>;
249 EIGEN_DEPRECATED typedef CwiseNullaryOp<internal::linspaced_op<Scalar>, PlainObject> SequentialLinSpacedReturnType;
251 using RandomAccessLinSpacedReturnType = CwiseNullaryOp<internal::linspaced_op<Scalar>, PlainObject>;
253 using RandomAccessEqualSpacedReturnType = CwiseNullaryOp<internal::equalspaced_op<Scalar>, PlainObject>;
256 internal::traits<Derived>::ColsAtCompileTime, 1>;
257
258#endif // not EIGEN_PARSED_BY_DOXYGEN
259
260
261 template <typename OtherDerived>
262 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other);
263
267 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived& operator=(const DenseBase& other);
268
269 template <typename OtherDerived>
270 EIGEN_DEVICE_FUNC constexpr Derived& operator=(const EigenBase<OtherDerived>& other);
271
272 template <typename OtherDerived>
273 EIGEN_DEVICE_FUNC constexpr Derived& operator+=(const EigenBase<OtherDerived>& other);
274
275 template <typename OtherDerived>
276 EIGEN_DEVICE_FUNC constexpr Derived& operator-=(const EigenBase<OtherDerived>& other);
277
278 template <typename OtherDerived>
279 EIGEN_DEVICE_FUNC Derived& operator=(const ReturnByValue<OtherDerived>& func);
280
283 template <typename OtherDerived>
285 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC constexpr Derived& lazyAssign(const DenseBase<OtherDerived>& other);
286
287 EIGEN_DEVICE_FUNC CommaInitializer<Derived> operator<<(const Scalar& s);
288
289 template <unsigned int Added, unsigned int Removed>
291 EIGEN_DEPRECATED const Derived& flagged() const {
292 return derived();
293 }
294
295 template <typename OtherDerived>
296 EIGEN_DEVICE_FUNC CommaInitializer<Derived> operator<<(const DenseBase<OtherDerived>& other);
297
298 using TransposeReturnType = Transpose<Derived>;
299 EIGEN_DEVICE_FUNC TransposeReturnType transpose();
300 using ConstTransposeReturnType = Transpose<const Derived>;
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);
306 EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(const Scalar& value);
307
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,
310 const Scalar& high);
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,
313 const Scalar& high);
314
315 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Index size, const Scalar& low,
316 const Scalar& high);
317 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(const Scalar& low, const Scalar& high);
318
319 EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(Index size, const Scalar& low,
320 const Scalar& step);
321 EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(const Scalar& low, const Scalar& step);
322
323 template <typename CustomNullaryOp>
324 EIGEN_DEVICE_FUNC static const CwiseNullaryOp<CustomNullaryOp, PlainObject> NullaryExpr(Index rows, Index cols,
325 const CustomNullaryOp& func);
326 template <typename CustomNullaryOp>
327 EIGEN_DEVICE_FUNC static const CwiseNullaryOp<CustomNullaryOp, PlainObject> NullaryExpr(Index size,
328 const CustomNullaryOp& func);
329 template <typename CustomNullaryOp>
330 EIGEN_DEVICE_FUNC static const CwiseNullaryOp<CustomNullaryOp, PlainObject> NullaryExpr(const CustomNullaryOp& func);
331
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();
338
339 EIGEN_DEVICE_FUNC void fill(const Scalar& value);
340 EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value);
341 EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
342 EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high);
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();
347 EIGEN_DEVICE_FUNC Derived& setRandom();
348
349 template <typename OtherDerived>
350 EIGEN_DEVICE_FUNC constexpr bool isApprox(const DenseBase<OtherDerived>& other,
351 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
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(
356 const DenseBase<OtherDerived>& other, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
357
358 EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value,
359 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
360 EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value,
361 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
362 EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
363 EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
364
365 EIGEN_DEVICE_FUNC inline bool hasNaN() const;
366 EIGEN_DEVICE_FUNC inline bool allFinite() const;
367
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);
371
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);
375
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 {
386 // Even though MSVC does not honor strong inlining when the return type
387 // is a dynamic matrix, we desperately need strong inlining for fixed
388 // size types on MSVC.
389 return typename internal::eval<Derived>::type(derived());
390 }
391
394 */
395 template <typename OtherDerived>
396 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(const DenseBase<OtherDerived>& other) {
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>());
400 }
401
405 template <typename OtherDerived>
406 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(PlainObjectBase<OtherDerived>& other) {
407 eigen_assert(rows() == other.rows() && cols() == other.cols());
408 call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
410
411 EIGEN_DEVICE_FUNC constexpr inline const NestByValue<Derived> nestByValue() const;
412
413 EIGEN_DEVICE_FUNC Scalar sum() const;
414 EIGEN_DEVICE_FUNC Scalar mean() const;
415 EIGEN_DEVICE_FUNC Scalar trace() const;
416
417 EIGEN_DEVICE_FUNC Scalar prod() const;
418
419 // The default PropagateFast gives undefined behavior on NaN inputs but the fastest code.
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;
424
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;
433
434 template <typename BinaryOp>
435 EIGEN_DEVICE_FUNC Scalar redux(const BinaryOp& func) const;
436
437 template <typename Visitor>
438 EIGEN_DEVICE_FUNC void visit(Visitor& func) const;
439
440
447 inline const WithFormat<Derived> format(const IOFormat& fmt) const { return WithFormat<Derived>(derived(), fmt); }
448
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);
453 }
454
455 EIGEN_DEVICE_FUNC bool all() const;
456 EIGEN_DEVICE_FUNC bool any() const;
457 EIGEN_DEVICE_FUNC Index count() const;
458
459 using RowwiseReturnType = VectorwiseOp<Derived, Horizontal>;
460 using ConstRowwiseReturnType = const VectorwiseOp<const Derived, Horizontal>;
461 using ColwiseReturnType = VectorwiseOp<Derived, Vertical>;
462 using ConstColwiseReturnType = const VectorwiseOp<const Derived, Vertical>;
463
465
469 * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
470 */
471 // Code moved here due to a CUDA compiler bug
472 EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const { return ConstRowwiseReturnType(derived()); }
473 EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();
474
482 EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const { return ConstColwiseReturnType(derived()); }
483 EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
484
485 using RandomReturnType = CwiseNullaryOp<internal::scalar_random_op<Scalar>, PlainObject>;
486 static const RandomReturnType Random(Index rows, Index cols);
487 static const RandomReturnType Random(Index size);
488 static const RandomReturnType Random();
489
490 template <typename ThenDerived, typename ElseDerived>
491 inline EIGEN_DEVICE_FUNC constexpr CwiseTernaryOp<
492 internal::scalar_boolean_select_op<typename DenseBase<ThenDerived>::Scalar,
493 typename DenseBase<ElseDerived>::Scalar, Scalar>,
494 ThenDerived, ElseDerived, Derived>
495 select(const DenseBase<ThenDerived>& thenMatrix, const DenseBase<ElseDerived>& elseMatrix) const;
496
497 template <typename ThenDerived>
498 inline EIGEN_DEVICE_FUNC constexpr CwiseTernaryOp<
499 internal::scalar_boolean_select_op<typename DenseBase<ThenDerived>::Scalar,
501 ThenDerived, typename DenseBase<ThenDerived>::ConstantReturnType, Derived>
502 select(const DenseBase<ThenDerived>& thenMatrix, const typename DenseBase<ThenDerived>::Scalar& elseScalar) const;
503
504 template <typename ElseDerived>
505 inline EIGEN_DEVICE_FUNC constexpr CwiseTernaryOp<
506 internal::scalar_boolean_select_op<typename DenseBase<ElseDerived>::Scalar,
508 typename DenseBase<ElseDerived>::ConstantReturnType, ElseDerived, Derived>
509 select(const typename DenseBase<ElseDerived>::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
510
511 template <int p>
512 RealScalar lpNorm() const;
513
514 template <int RowFactor, int ColFactor>
515 EIGEN_DEVICE_FUNC const Replicate<Derived, RowFactor, ColFactor> replicate() const;
516
518 * \return an expression of the replication of \c *this
519 *
520 * The replication factors can be passed at run time as integers, or at compile time as Eigen::fix<N> or
521 * Eigen::fix<N>(n). In the latter case, \c n is the runtime value used when \c N equals Eigen::Dynamic, and must
522 * equal \c N otherwise. For example, with a fixed row factor \c NRows and a runtime column factor \c cols:
523 * \code mat.replicate(fix<NRows>, cols) \endcode
524 *
525 * \sa DenseBase::replicate(Index,Index) const, DenseBase::replicate<int,int>(), class Replicate, fix, fix<N>(int)
526 */
527 template <typename NRowsType, typename NColsType>
528 EIGEN_DEVICE_FUNC const
529 Replicate<Derived, internal::get_fixed_value<NRowsType>::value, internal::get_fixed_value<NColsType>::value>
530 replicate(NRowsType nRows, NColsType nCols) const {
531 return Replicate<Derived, internal::get_fixed_value<NRowsType>::value, internal::get_fixed_value<NColsType>::value>(
532 derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols));
533 }
534
538 * Example: \include MatrixBase_replicate_int_int.cpp
539 * Output: \verbinclude MatrixBase_replicate_int_int.out
540 *
541 * \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), DenseBase::replicate(NRowsType,NColsType) const,
542 * class Replicate
543 */
544 // Code moved here due to a CUDA compiler bug
545 EIGEN_DEVICE_FUNC const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const {
546 return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor);
547 }
548
549 using ReverseReturnType = Reverse<Derived, BothDirections>;
550 using ConstReverseReturnType = const Reverse<const Derived, BothDirections>;
551 EIGEN_DEVICE_FUNC ReverseReturnType reverse();
553 // Code moved here due to a CUDA compiler bug
554 EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const { return ConstReverseReturnType(derived()); }
555 EIGEN_DEVICE_FUNC void reverseInPlace();
556
557#ifdef EIGEN_PARSED_BY_DOXYGEN
561 typedef random_access_iterator_type iterator;
563 typedef random_access_iterator_type const_iterator;
564#else
565 using iterator_type =
566 std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit, internal::pointer_based_stl_iterator<Derived>,
567 internal::generic_randaccess_stl_iterator<Derived>>;
568
569 using const_iterator_type = std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit,
570 internal::pointer_based_stl_iterator<const Derived>,
571 internal::generic_randaccess_stl_iterator<const Derived>>;
572
573 // Stl-style iterators are supported only for vectors.
574
575 using iterator = std::conditional_t<IsVectorAtCompileTime, iterator_type, void>;
576
577 using const_iterator = std::conditional_t<IsVectorAtCompileTime, const_iterator_type, void>;
578#endif
579
580 inline iterator begin();
581 inline const_iterator begin() const;
582 inline const_iterator cbegin() const;
583 inline iterator end();
584 inline const_iterator end() const;
585 inline const_iterator cend() const;
586
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&>;
590
603 ///
604 /// Writing through the returned expression additionally requires the scalar type to be
605 /// std::complex, whose storage the standard fixes as its two components interleaved.
606 ///
607 /// \sa real(), imag()
608 EIGEN_DEVICE_FUNC RealViewReturnType realView();
610 EIGEN_DEVICE_FUNC ConstRealViewReturnType realView() const;
611
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"
618// Defines operator()(const RowIndices&, const ColIndices&) and other indexed view methods.
619#include "../plugins/IndexedViewMethods.inc"
620#include "../plugins/ReshapedMethods.inc"
621#ifdef EIGEN_DENSEBASE_PLUGIN
622#include EIGEN_DENSEBASE_PLUGIN
623#endif
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
628
629 // disable the use of evalTo for dense objects with a nice compilation error
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);
634 }
635
636 protected:
637 EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase)
639#ifdef EIGEN_INTERNAL_DEBUGGING
640 EIGEN_DEVICE_FUNC constexpr DenseBase() {
641 /* Just checks for self-consistency of the flags.
642 * Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down
643 */
644 EIGEN_STATIC_ASSERT(
645 (internal::check_implication(MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1, int(IsRowMajor)) &&
646 internal::check_implication(MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1, int(!IsRowMajor))),
647 INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
648 }
649#else
650 EIGEN_DEVICE_FUNC constexpr DenseBase() = default;
651#endif
652
653 private:
654 EIGEN_DEVICE_FUNC explicit DenseBase(int);
655 EIGEN_DEVICE_FUNC DenseBase(int, int);
656 template <typename OtherDerived>
657 EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&);
658};
659
662template <typename DerivedA, typename DerivedB>
663EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
664 // Use forwarding references to capture all combinations of cv-qualified l+r-value cases.
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,
667 void>
668 swap(DerivedA&& a, DerivedB&& b) {
669 a.swap(b);
671
672} // end namespace Eigen
673
674#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: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
Pseudo expression providing matrix output with given format.
Definition IO.h:102
@ 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:233