Eigen::RefBase< Derived > Class Template Reference

#include <Ref.h>

+ Inheritance diagram for Eigen::RefBase< Derived >:

Public Types

typedef MapBase< Derived > Base
 

Public Member Functions

EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride () const
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride () const
 
EIGEN_DEVICE_FUNC RefBase ()
 

Protected Types

typedef Stride< StrideType::OuterStrideAtCompileTime, StrideType::InnerStrideAtCompileTime > StrideBase
 

Protected Member Functions

template<typename Expression >
EIGEN_DEVICE_FUNC bool construct (Expression &expr)
 

Static Protected Member Functions

static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveInnerStride (Index inner)
 
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveOuterStride (Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor)
 

Protected Attributes

StrideBase m_stride
 

Private Types

typedef internal::traits< Derived >::PlainObjectType PlainObjectType
 
typedef internal::traits< Derived >::StrideType StrideType
 

Member Typedef Documentation

◆ Base

template<typename Derived >
typedef MapBase<Derived> Eigen::RefBase< Derived >::Base

◆ PlainObjectType

template<typename Derived >
typedef internal::traits<Derived>::PlainObjectType Eigen::RefBase< Derived >::PlainObjectType
private

◆ StrideBase

template<typename Derived >
typedef Stride<StrideType::OuterStrideAtCompileTime, StrideType::InnerStrideAtCompileTime> Eigen::RefBase< Derived >::StrideBase
protected

◆ StrideType

template<typename Derived >
typedef internal::traits<Derived>::StrideType Eigen::RefBase< Derived >::StrideType
private

Constructor & Destructor Documentation

◆ RefBase()

template<typename Derived >
EIGEN_DEVICE_FUNC Eigen::RefBase< Derived >::RefBase ( )
inline
88  : Base(0, RowsAtCompileTime == Dynamic ? 0 : RowsAtCompileTime,
89  ColsAtCompileTime == Dynamic ? 0 : ColsAtCompileTime),
90  // Stride<> does not allow default ctor for Dynamic strides, so let' initialize it with dummy values:
91  m_stride(StrideType::OuterStrideAtCompileTime == Dynamic ? 0 : StrideType::OuterStrideAtCompileTime,
92  StrideType::InnerStrideAtCompileTime == Dynamic ? 0 : StrideType::InnerStrideAtCompileTime) {}
StrideBase m_stride
Definition: Ref.h:195
MapBase< Derived > Base
Definition: Ref.h:73
const int Dynamic
Definition: Constants.h:25

Member Function Documentation

◆ construct()

template<typename Derived >
template<typename Expression >
EIGEN_DEVICE_FUNC bool Eigen::RefBase< Derived >::construct ( Expression &  expr)
inlineprotected
111  {
112  // Check matrix sizes. If this is a compile-time vector, we do allow
113  // implicitly transposing.
115  // If it is a vector, the transpose sizes might match.
116  || (PlainObjectType::IsVectorAtCompileTime &&
117  ((int(PlainObjectType::RowsAtCompileTime) == Eigen::Dynamic ||
118  int(Expression::ColsAtCompileTime) == Eigen::Dynamic ||
119  int(PlainObjectType::RowsAtCompileTime) == int(Expression::ColsAtCompileTime)) &&
120  (int(PlainObjectType::ColsAtCompileTime) == Eigen::Dynamic ||
121  int(Expression::RowsAtCompileTime) == Eigen::Dynamic ||
122  int(PlainObjectType::ColsAtCompileTime) == int(Expression::RowsAtCompileTime)))),
123  YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
124 
125  // Determine runtime rows and columns.
126  Index rows = expr.rows();
127  Index cols = expr.cols();
128  if (PlainObjectType::RowsAtCompileTime == 1) {
129  eigen_assert(expr.rows() == 1 || expr.cols() == 1);
130  rows = 1;
131  cols = expr.size();
132  } else if (PlainObjectType::ColsAtCompileTime == 1) {
133  eigen_assert(expr.rows() == 1 || expr.cols() == 1);
134  rows = expr.size();
135  cols = 1;
136  }
137  // Verify that the sizes are valid.
138  eigen_assert((PlainObjectType::RowsAtCompileTime == Dynamic) || (PlainObjectType::RowsAtCompileTime == rows));
139  eigen_assert((PlainObjectType::ColsAtCompileTime == Dynamic) || (PlainObjectType::ColsAtCompileTime == cols));
140 
141  // If this is a vector, we might be transposing, which means that stride should swap.
142  const bool transpose = PlainObjectType::IsVectorAtCompileTime && (rows != expr.rows());
143  // If the storage format differs, we also need to swap the stride.
144  const bool row_major = ((PlainObjectType::Flags)&RowMajorBit) != 0;
145  const bool expr_row_major = (Expression::Flags & RowMajorBit) != 0;
146  const bool storage_differs = (row_major != expr_row_major);
147 
148  const bool swap_stride = (transpose != storage_differs);
149 
150  // Determine expr's actual strides, resolving any defaults if zero.
151  const Index expr_inner_actual = resolveInnerStride(expr.innerStride());
152  const Index expr_outer_actual = resolveOuterStride(expr_inner_actual, expr.outerStride(), expr.rows(), expr.cols(),
153  Expression::IsVectorAtCompileTime != 0, expr_row_major);
154 
155  // If this is a column-major row vector or row-major column vector, the inner-stride
156  // is arbitrary, so set it to either the compile-time inner stride or 1.
157  const bool row_vector = (rows == 1);
158  const bool col_vector = (cols == 1);
159  const Index inner_stride =
160  ((!row_major && row_vector) || (row_major && col_vector))
161  ? (StrideType::InnerStrideAtCompileTime > 0 ? Index(StrideType::InnerStrideAtCompileTime) : 1)
162  : swap_stride ? expr_outer_actual
163  : expr_inner_actual;
164 
165  // If this is a column-major column vector or row-major row vector, the outer-stride
166  // is arbitrary, so set it to either the compile-time outer stride or vector size.
167  const Index outer_stride =
168  ((!row_major && col_vector) || (row_major && row_vector))
169  ? (StrideType::OuterStrideAtCompileTime > 0 ? Index(StrideType::OuterStrideAtCompileTime)
170  : rows * cols * inner_stride)
171  : swap_stride ? expr_inner_actual
172  : expr_outer_actual;
173 
174  // Check if given inner/outer strides are compatible with compile-time strides.
175  const bool inner_valid = (StrideType::InnerStrideAtCompileTime == Dynamic) ||
176  (resolveInnerStride(Index(StrideType::InnerStrideAtCompileTime)) == inner_stride);
177  if (!inner_valid) {
178  return false;
179  }
180 
181  const bool outer_valid =
182  (StrideType::OuterStrideAtCompileTime == Dynamic) ||
183  (resolveOuterStride(inner_stride, Index(StrideType::OuterStrideAtCompileTime), rows, cols,
184  PlainObjectType::IsVectorAtCompileTime != 0, row_major) == outer_stride);
185  if (!outer_valid) {
186  return false;
187  }
188 
189  internal::construct_at<Base>(this, expr.data(), rows, cols);
190  internal::construct_at(&m_stride, (StrideType::OuterStrideAtCompileTime == 0) ? 0 : outer_stride,
191  (StrideType::InnerStrideAtCompileTime == 0) ? 0 : inner_stride);
192  return true;
193  }
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:66
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
internal::traits< Derived >::PlainObjectType PlainObjectType
Definition: Ref.h:69
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveInnerStride(Index inner)
Definition: Ref.h:100
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor)
Definition: Ref.h:103
const unsigned int RowMajorBit
Definition: Constants.h:70
EIGEN_DEVICE_FUNC T * construct_at(T *p, Args &&... args)
Definition: Memory.h:1321
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void transpose()
Definition: skew_symmetric_matrix3.cpp:135

References cols, Eigen::internal::construct_at(), Eigen::Dynamic, eigen_assert, EIGEN_PREDICATE_SAME_MATRIX_SIZE, EIGEN_STATIC_ASSERT, Eigen::RefBase< Derived >::m_stride, Eigen::RefBase< Derived >::resolveInnerStride(), Eigen::RefBase< Derived >::resolveOuterStride(), Eigen::RowMajorBit, rows, and anonymous_namespace{skew_symmetric_matrix3.cpp}::transpose().

Referenced by Eigen::Ref< const TPlainObjectType, Options, StrideType >::construct(), Eigen::Ref< const SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType >::construct(), Eigen::Ref< const SparseVector< MatScalar, MatOptions, MatIndex >, Options, StrideType >::construct(), Eigen::Ref< PlainObjectType, Options, StrideType >::Ref(), Eigen::Ref< const TPlainObjectType, Options, StrideType >::Ref(), Eigen::Ref< SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType >::Ref(), and Eigen::Ref< SparseVector< MatScalar, MatOptions, MatIndex >, Options, StrideType >::Ref().

◆ innerStride()

template<typename Derived >
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index Eigen::RefBase< Derived >::innerStride ( ) const
inline
76  {
77  return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
78  }
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index inner() const
Definition: Stride.h:83

References Eigen::Stride< OuterStrideAtCompileTime_, InnerStrideAtCompileTime_ >::inner(), and Eigen::RefBase< Derived >::m_stride.

◆ outerStride()

template<typename Derived >
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index Eigen::RefBase< Derived >::outerStride ( ) const
inline
80  {
81  return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
82  : IsVectorAtCompileTime ? this->size()
83  : int(Flags) & RowMajorBit ? this->cols()
84  : this->rows();
85  }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outer() const
Definition: Stride.h:81
return int(ret)+1
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56

References cols, int(), Eigen::RefBase< Derived >::m_stride, Eigen::Stride< OuterStrideAtCompileTime_, InnerStrideAtCompileTime_ >::outer(), rows, and size.

◆ resolveInnerStride()

template<typename Derived >
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index Eigen::RefBase< Derived >::resolveInnerStride ( Index  inner)
inlinestaticprotected
100 { return inner == 0 ? 1 : inner; }

Referenced by Eigen::RefBase< Derived >::construct().

◆ resolveOuterStride()

template<typename Derived >
static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index Eigen::RefBase< Derived >::resolveOuterStride ( Index  inner,
Index  outer,
Index  rows,
Index  cols,
bool  isVectorAtCompileTime,
bool  isRowMajor 
)
inlinestaticprotected
104  {
105  return outer == 0 ? isVectorAtCompileTime ? inner * rows * cols : isRowMajor ? inner * cols : inner * rows : outer;
106  }

References cols, and rows.

Referenced by Eigen::RefBase< Derived >::construct().

Member Data Documentation

◆ m_stride


The documentation for this class was generated from the following file: