Public Types | Public Member Functions | Private Types | Private Member Functions | List of all members
Eigen::Ref< PlainObjectType, Options, StrideType > Class Template Reference

A matrix or vector expression mapping an existing expression. More...

#include <Ref.h>

Inheritance diagram for Eigen::Ref< PlainObjectType, Options, StrideType >:
Inheritance graph
[legend]

Public Types

typedef RefBase< RefBase
 
- Public Types inherited from Eigen::RefBase< Ref< PlainObjectType, Options, StrideType > >
typedef MapBase< Ref< PlainObjectType, Options, StrideType > > Base
 

Public Member Functions

template<typename Derived >
EIGEN_DEVICE_FUNC Ref (const DenseBase< Derived > &expr, typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type *=0)
 
template<typename Derived >
EIGEN_DEVICE_FUNC Ref (PlainObjectBase< Derived > &expr, typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type *=0)
 
- Public Member Functions inherited from Eigen::RefBase< Ref< PlainObjectType, Options, StrideType > >
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride () const
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride () const
 
EIGEN_DEVICE_FUNC RefBase ()
 

Private Types

typedef internal::traits< RefTraits
 

Private Member Functions

template<typename Derived >
EIGEN_DEVICE_FUNC Ref (const PlainObjectBase< Derived > &expr, typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type *=0)
 

Additional Inherited Members

- Protected Types inherited from Eigen::RefBase< Ref< PlainObjectType, Options, StrideType > >
typedef Stride< StrideType::OuterStrideAtCompileTime, StrideType::InnerStrideAtCompileTime > StrideBase
 
- Protected Member Functions inherited from Eigen::RefBase< Ref< PlainObjectType, Options, StrideType > >
EIGEN_DEVICE_FUNC bool construct (Expression &expr)
 
- Static Protected Member Functions inherited from Eigen::RefBase< Ref< PlainObjectType, Options, StrideType > >
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 inherited from Eigen::RefBase< Ref< PlainObjectType, Options, StrideType > >
StrideBase m_stride
 

Detailed Description

template<typename PlainObjectType, int Options, typename StrideType>
class Eigen::Ref< PlainObjectType, Options, StrideType >

A matrix or vector expression mapping an existing expression.

Template Parameters
PlainObjectTypethe equivalent matrix type of the mapped data
Optionsspecifies the pointer alignment in bytes. It can be: Aligned128, , Aligned64, Aligned32, Aligned16, Aligned8 or Unaligned. The default is Unaligned.
StrideTypeoptionally specifies strides. By default, Ref implies a contiguous storage along the inner dimension (inner stride==1), but accepts a variable outer stride (leading dimension). This can be overridden by specifying strides. The type passed here must be a specialization of the Stride template, see examples below.

This class provides a way to write non-template functions taking Eigen objects as parameters while limiting the number of copies. A Ref<> object can represent either a const expression or a l-value:

// in-out argument:
void foo1(Ref<VectorXf> x);
// read-only const argument:
void foo2(const Ref<const VectorXf>& x);

In the in-out case, the input argument must satisfy the constraints of the actual Ref<> type, otherwise a compilation issue will be triggered. By default, a Ref<VectorXf> can reference any dense vector expression of float having a contiguous memory layout. Likewise, a Ref<MatrixXf> can reference any column-major dense matrix expression of float whose column's elements are contiguously stored with the possibility to have a constant space in-between each column, i.e. the inner stride must be equal to 1, but the outer stride (or leading dimension) can be greater than the number of rows.

In the const case, if the input expression does not match the above requirement, then it is evaluated into a temporary before being passed to the function. Here are some examples:

MatrixXf A;
VectorXf a;
foo1(a.head()); // OK
foo1(A.col()); // OK
foo1(A.row()); // Compilation error because here innerstride!=1
foo2(A.row()); // Compilation error because A.row() is a 1xN object while foo2 is expecting a Nx1 object
foo2(A.row().transpose()); // The row is copied into a contiguous temporary
foo2(2*a); // The expression is evaluated into a temporary
foo2(A.col().segment(2,4)); // No temporary

The range of inputs that can be referenced without temporary can be enlarged using the last two template parameters. Here is an example accepting an innerstride!=1:

// in-out argument:
void foo3(Ref<VectorXf,0,InnerStride<> > x);
foo3(A.row()); // OK

The downside here is that the function foo3 might be significantly slower than foo1 because it won't be able to exploit vectorization, and will involve more expensive address computations even if the input is contiguously stored in memory. To overcome this issue, one might propose to overload internally calling a template function, e.g.:

// in the .h:
void foo(const Ref<MatrixXf>& A);
void foo(const Ref<MatrixXf,0,Stride<> >& A);
// in the .cpp:
template<typename TypeOfA> void foo_impl(const TypeOfA& A) {
... // crazy code goes here
}
void foo(const Ref<MatrixXf>& A) { foo_impl(A); }
void foo(const Ref<MatrixXf,0,Stride<> >& A) { foo_impl(A); }

See also the following stackoverflow questions for further references:

See also
PlainObjectBase::Map(), TopicStorageOrders

Definition at line 281 of file Ref.h.

Member Typedef Documentation

◆ Base

template<typename PlainObjectType , int Options, typename StrideType >
typedef RefBase<Ref> Eigen::Ref< PlainObjectType, Options, StrideType >::Base

Definition at line 291 of file Ref.h.

◆ Traits

template<typename PlainObjectType , int Options, typename StrideType >
typedef internal::traits<Ref> Eigen::Ref< PlainObjectType, Options, StrideType >::Traits
private

Definition at line 285 of file Ref.h.

Constructor & Destructor Documentation

◆ Ref() [1/3]

template<typename PlainObjectType , int Options, typename StrideType >
template<typename Derived >
EIGEN_DEVICE_FUNC Eigen::Ref< PlainObjectType, Options, StrideType >::Ref ( const PlainObjectBase< Derived > &  expr,
typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type = 0 
)
inlineprivate

◆ Ref() [2/3]

template<typename PlainObjectType , int Options, typename StrideType >
template<typename Derived >
EIGEN_DEVICE_FUNC Eigen::Ref< PlainObjectType, Options, StrideType >::Ref ( PlainObjectBase< Derived > &  expr,
typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type = 0 
)
inline

Definition at line 297 of file Ref.h.

◆ Ref() [3/3]

template<typename PlainObjectType , int Options, typename StrideType >
template<typename Derived >
EIGEN_DEVICE_FUNC Eigen::Ref< PlainObjectType, Options, StrideType >::Ref ( const DenseBase< Derived > &  expr,
typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type = 0 
)
inline

Definition at line 307 of file Ref.h.


The documentation for this class was generated from the following file:
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
A
Definition: test_numpy_dtypes.cpp:298
foo
void foo(CV_QUALIFIER Matrix3d &m)
Definition: block_nonconst_ctor_on_const_xpr_0.cpp:11
Eigen::Ref::Ref
EIGEN_DEVICE_FUNC Ref(const PlainObjectBase< Derived > &expr, typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type *=0)
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:46:11