$treeview $search $mathjax
Eigen  3.2.5
$projectbrief
$projectbrief
$searchbox

Map< PlainObjectType, MapOptions, StrideType > Class Template Reference
[Core module]

A matrix or vector expression mapping an existing array of data. More...

Inheritance diagram for Map< PlainObjectType, MapOptions, StrideType >:

List of all members.

Public Member Functions

 Map (PointerArgType dataPtr, Index nbRows, Index nbCols, const StrideType &a_stride=StrideType())
 Map (PointerArgType dataPtr, Index a_size, const StrideType &a_stride=StrideType())
 Map (PointerArgType dataPtr, const StrideType &a_stride=StrideType())

Detailed Description

template<typename PlainObjectType, int MapOptions, typename StrideType>
class Eigen::Map< PlainObjectType, MapOptions, StrideType >

A matrix or vector expression mapping an existing array of data.

Template Parameters:
PlainObjectType the equivalent matrix type of the mapped data
MapOptions specifies whether the pointer is Aligned, or Unaligned. The default is Unaligned.
StrideType optionally specifies strides. By default, Map assumes the memory layout of an ordinary, contiguous array. This can be overridden by specifying strides. The type passed here must be a specialization of the Stride template, see examples below.

This class represents a matrix or vector expression mapping an existing array of data. It can be used to let Eigen interface without any overhead with non-Eigen data structures, such as plain C arrays or structures from other libraries. By default, it assumes that the data is laid out contiguously in memory. You can however override this by explicitly specifying inner and outer strides.

Here's an example of simply mapping a contiguous array as a column-major matrix:

int array[9];
for(int i = 0; i < 9; ++i) array[i] = i;
cout << Map<Matrix3i>(array) << endl;

Output:

0 3 6
1 4 7
2 5 8

If you need to map non-contiguous arrays, you can do so by specifying strides:

Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time fixed value.

int array[12];
for(int i = 0; i < 12; ++i) array[i] = i;
cout << Map<VectorXi, 0, InnerStride<2> >
         (array, 6) // the inner stride has already been passed as template parameter
     << endl;

Output:

 0
 2
 4
 6
 8
10

Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns. Here, we're specifying the outer stride as a runtime parameter. Note that here OuterStride<> is a short version of OuterStride<Dynamic> because the default template parameter of OuterStride is Dynamic

int array[12];
for(int i = 0; i < 12; ++i) array[i] = i;
cout << Map<MatrixXi, 0, OuterStride<> >(array, 3, 3, OuterStride<>(4)) << endl;

Output:

 0  4  8
 1  5  9
 2  6 10

For more details and for an example of specifying both an inner and an outer stride, see class Stride.

Tip: to change the array of data mapped by a Map object, you can use the C++ placement new syntax:

Example:

int data[] = {1,2,3,4,5,6,7,8,9};
Map<RowVectorXi> v(data,4);
cout << "The mapped vector v is: " << v << "\n";
new (&v) Map<RowVectorXi>(data+4,5);
cout << "Now v is: " << v << "\n";

Output:

The mapped vector v is: 1 2 3 4
Now v is: 5 6 7 8 9

This class is the return type of PlainObjectBase::Map() but can also be used directly.

See also:
PlainObjectBase::Map(), Storage orders

Constructor & Destructor Documentation

Map ( PointerArgType  dataPtr,
const StrideType &  a_stride = StrideType() 
) [inline]

Constructor in the fixed-size case.

Parameters:
dataPtr pointer to the array to map
a_stride optional Stride object, passing the strides.
Map ( PointerArgType  dataPtr,
Index  a_size,
const StrideType &  a_stride = StrideType() 
) [inline]

Constructor in the dynamic-size vector case.

Parameters:
dataPtr pointer to the array to map
a_size the size of the vector expression
a_stride optional Stride object, passing the strides.
Map ( PointerArgType  dataPtr,
Index  nbRows,
Index  nbCols,
const StrideType &  a_stride = StrideType() 
) [inline]

Constructor in the dynamic-size matrix case.

Parameters:
dataPtr pointer to the array to map
nbRows the number of rows of the matrix expression
nbCols the number of columns of the matrix expression
a_stride optional Stride object, passing the strides.

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