In Armadillo, there is a pointer to a single column by using .colptr( col_number ). So, we can write, for example,
mat X(nrow, ncol);
vec y(X.colptr(0), nrow, false, true);
X.col(0) = y;
Is there a way to do this for multiple columns of the matrix X such as
mat X(nrow, ncol);
mat Y(X.Multiple_colptr(0, 3), nrow, false, true);
X.cols(0, 3) = Y;
This can be done directly with
colptr. Pointers can be offset:*(pointer + offset) == pointer[offset]. So a simple way to achieve the functionality you want inmultiple_colptrwould be to offset a simplecolptr. Consider this example (and run it yourself):All the entries in
awill copied to form a 4 elementvecinb. You can obtain any number of columns by varying the pointer froma.colptr(0)and the number of elements to copy (Armadillo follows column-major ordering).To copy part of a matrix into another you could use
Whilst this is possible, there is probably a better way of doing this with Aramdillo functions. The above example does not include bounds checking.