c++ - 从 C 数组(主要列)转换为 Armadillo 矩阵(arma::mat)而不复制

标签 c++ c armadillo

我有一个指向列主 C double 数组的指针,它想转换成 arma::mat我从文档中了解到这也是专栏主要的。

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

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

非常感谢

最佳答案

来自 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

关于c++ - 从 C 数组(主要列)转换为 Armadillo 矩阵(arma::mat)而不复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34784242/

相关文章:

c++ - 在字符串字段中查找字符串的索引

c++ - Armadillo 中 find() 的补充索引

c++ - 将 cx_vec 元素转换为双复杂 Armadillo C++

c++ - 陷阱表示

c++ - iterator_category 和 decltype

c++ - 输入结束时应为 '}'

c - 线程显式调度 POSIX API 给出错误

c - 打印出两个输入是否是彼此的字谜

c++ - 在 C++ 中处理许多 commnadline 选项

c++ - 使用迭代器递增