Reputation: 1605
I have a pointer to a column-major C double array which would like to convert into a arma::mat
which I understood from the doc is column-major as well.
I have seen the function std::transform
but I believe the matrices in std are row-major. In the armadillo package there is the conv_to<mat>::from()
which seems to work with either std::array
or arma::mat
, will this work with a column-major C array?.
Could you please tell how to pass the C structure to arma::mat
without copying and back to a C array?
Many thanks
Upvotes: 1
Views: 1987
Reputation: 4265
From the documentation of armadillo: (http://arma.sourceforge.net/docs.html#Mat)
Advanced constructors
mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false)
Create a matrix using data from writable auxiliary (external) memory, where ptr_aux_mem is a pointer to the memory. By default the matrix allocates its own memory and copies data from the auxiliary memory (for safety). However, if copy_aux_mem is set to false, the matrix will instead directly use the auxiliary memory (ie. no copying); this is faster, but can be dangerous unless you know what you're doing!
The strict parameter comes into effect only when copy_aux_mem is set to false (ie. the matrix is directly using auxiliary memory)
- when strict is set to false, the matrix will use the auxiliary memory until a size change
- when strict is set to true, the matrix will be bound to the auxiliary memory for its lifetime; the number of elements in the matrix can't be changed
- the default setting of strict in versions 6.000+ is false
- the default setting of strict in versions 5.600 and earlier is true
Upvotes: 3