是否有一个 c++ 矩阵库,我可以在其中索引具有非连续向量的矩阵,如 R 中的矩阵
Is there a c++ matrix library where I can index matrices with non-contiguous vectors as in R?
我相信boost对矩阵的连续或至少逐步一致的切片有局限性。在 R 中,我可以有一个随机向量 c(5,2,8),并使用它来索引到矩阵 M[c(5,2,8),] 例如......
犰狳从两周前发布的3.0版本开始支持此功能。
这是通过RcppArmadillo的一个工作示例:
R> library(inline)
R>
R> code <- '
+ arma::mat M = Rcpp::as<arma::mat>(m); // normal matrix
+ arma::uvec V = Rcpp::as<arma::uvec>(v); // unsigned int vec
+ arma::mat N = M.cols(V); // index matrix by vec
+ return Rcpp::wrap(N);
+ '
R>
R> fun <- cxxfunction(signature(m="numeric", v="integer"),
+ code,
+ plugin="RcppArmadillo")
R> M <- matrix(1:25,5,5)
R> V <- c(1L, 3L, 5L) - 1 # offset by one for zero indexing
R> fun(M, V)
[,1] [,2] [,3]
[1,] 1 11 21
[2,] 2 12 22
[3,] 3 13 23
[4,] 4 14 24
[5,] 5 15 25
R>
有一个匹配函数来选择行而不是列。
相关文章:
- EASTL矢量<向量<int>>连续的
- 向量的内存位置不连续
- 结构化绑定,无需复制即可获取子向量的连续元素
- 处理特征中两种存储布局的固定大小矩阵的连续向量
- 在向量中找到连续数字的更有效方法
- AVX2 根据条件将连续元素扩展到稀疏向量?(如AVX512 VP扩展)
- 为什么连续的向量:: push_back将导致不同数量的构造函数调用
- 在C 中添加连续的向量元素组的最快方法
- 如何在c++中增加向量中k个连续元素的值
- Boost.SSpirit.x3避免将同一类型的两个连续属性塌陷为向量
- 保持类的向量成员与类实例连续
- C++ 向量不分配连续内存
- 是在连续空间中分配的嵌套向量
- 为什么使用 push_back() 赋值时向量元素的地址不连续
- 是否有一个 c++ 矩阵库,我可以在其中索引具有非连续向量的矩阵,如 R 中的矩阵
- 是一个完全连续内存的向量数组
- 向量中连续数的计数
- 计算一个向量中不重复的连续元素的最大数目.c++
- 将R转换为Rcpp:向量中连续日期之间的平均时差
- C++向量总是连续的吗