在这个简单的示例中,我想逐行对矩阵进行子集并将其传递给另一个cpp函数;该示例通过首先将输入数组传递给另一个函数来演示此工作。
#include "RcppArrayFire.h"
using namespace Rcpp;
af::array theta_check_cpp( af::array theta){
if(*theta(1).host<double>() >= 1){
theta(1) = 0;
}
return theta;
}
// [[Rcpp::export]]
af::array theta_check(RcppArrayFire::typed_array<f64> theta){
const int theta_size = theta.dims()[0];
af::array X(2, theta_size);
X(0, af::seq(theta_size)) = theta_check_cpp( theta );
X(1, af::seq(theta_size)) = theta;
// return X;
Rcpp::Rcout << " works till here";
return theta_check_cpp( X.row(1) );
}
/*** R
theta <- c( 2, 2, 2)
theta_check(theta)
*/
您用于创建constructor的X
具有用于数据类型的参数ty
,默认为f32
。因此,X
使用32位浮点数,因此您无法从中提取64位主机指针。无论使用
af::array X(2, theta_size, f64);
[使用64位双打创建数组,或通过以下方式提取32位主机指针
if(*theta(1).host<float>() >= 1){
...