Get matrix representations / blocks from Eigen :: VectorXd without copying (shared memory)

Does anyone know how I can extract blocks from Eigen :: VectorXf that can be interpreted as concrete Eigen :: MatrixXf without copying data? (the vector must contain several flattened matrices)

eg. something like this (pseudo code):

VectorXd W = VectorXd::Zero(8);

// Use data from W and create a matrix view from first four elements
Block<2,2> A = W.blockFromIndex(0, 2, 2);
// Use data from W and create a matrix view from last four elements
Block<2,2> B = W.blockFromIndex(4, 2, 2);

// Should also change data in W
A(0,0) = 1.0
B(0,0) = 1.0

The goal is simple - to have multiple views pointing to the same data in memory.

This can be done, for example, in python / numpy by extracting submatrix views and modifying them.

A = numpy.reshape(W[0:0 + 2 * 2], (2,2))

I do not know if Eigen supports rewriting methods for Eigen :: Block.

I assume that Eigen :: Map is very similar, except that it expects simple c-arrays / raw memory. (Link: Eigen :: Map ).

Chris

+3
1

, , Map:

Map<Matrix2d> A(W.data());          // using the first 4 elements
Map<Matrix2d> B(W.tail(4).data());  // using the last 4 elements
Map<MatrixXd> C(W.data()+6, 2,2);   // using the 6th to 10th elements
                                    // with sizes defined at runtime.
+4

All Articles