Is there a way to concatenate vectors in Eigen without having to duplicate data?
Here how to concatenate Vectors in Eigen? and here Eigen how to concatenate matrix along a specific dimension? concatenation is done by allocating memory for a new vector and then duplicating the data.
What I am asking is whether there is a way to create an expression instead (containing the references to the original data), so that data is not duplicated and no new memory allocated.
The trouble with not allocating a new vector is that it defeats vectorization, unless the compiler can pick up the pieces (which I wouldn't count on). The issue is that now you have an if-else in every access.
Therefore it is usually better to either create a new vector or loop over the vector segments separately.
If you truly want to create a concat operation, you can use nullary-expressions. This is a quick outline of how it might look: