从 C 数组(主要列)转换为犰狳矩阵(arma::mat)而不复制

convert from C array (column-major) to armadillo matrix (arma::mat) without copying

我有一个指向列优先 C 双精度数组的指针,它想转换成一个 arma::mat,我从文档中了解到它也是列优先的。

我看过函数 std::transform 但我相信 std 中的矩阵是行优先的。在 armadillo 包中有 conv_to<mat>::from() 似乎可以与 std::arrayarma::mat 一起使用,这是否适用于列主 C 数组?

你能告诉我如何将 C 结构传递给 arma::mat 而无需复制并返回到 C 数组吗?

非常感谢

来自犰狳的文档: (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