RCpp:期望出现单值错误
RCpp: expecting a single value error
我正在尝试构建一个使用RCpp执行简单卷积的函数包。代码看起来像
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector conv_filter(NumericVector x, NumericVector c){
int T = x.size();
int M = (c.size()-1)/2;
int t, i;
NumericVector fx(T);
for(t=0; t<T; t++){
for(i=-M; i<M+1; i++){
if(t+i>=0 && t+i<T){
fx(t) += c(M+i)*x(t+i);
}
}
}
return fx;
}
在采购时工作得很好,但是当构建到包中时,我一直得到错误说"期望单个值"。我想我犯了非常基本的错误,但即使在阅读相关主题后,我也看不出它是从哪里来的。非常感谢您的帮助。
你的程序为我工作:
R> Rcpp::sourceCpp("/tmp/hrcho.cpp")
R> conv_filter(1:4, 4:1)
[1] 7 16 25 24
R>
使用这个(只是缩进)源代码:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector conv_filter(NumericVector x, NumericVector c){
int T = x.size();
int M = (c.size()-1)/2;
int t, i;
NumericVector fx(T);
for(t=0; t<T; t++){
for(i=-M; i<M+1; i++){
if(t+i>=0 && t+i<T){
fx(t) += c(M+i)*x(t+i);
}
}
}
return fx;
}
/*** R
conv_filter(1:4, 4:1)
*/
相关文章:
- 使用 mat.at<uchar>(i,j) 的 opencv C++中的矩阵赋值错误
- 我想在 c++ 中对单向链表进行冒泡排序,但我一直面临左值错误,无法解决它
- For 循环 C++ 中的值错误
- HBOEHM 垃圾回收器未初始化的值错误和泄漏
- C:试图将指针值复制到另一个指针中,得到可修改的左值错误
- CUDA返回值错误35的含义是什么
- 枚举输出的值错误
- 将VS2013 更新为VS2019会导致左值错误,想知道原因
- cudaMemcpy 在从设备复制到主机时抛出无效值错误
- 我应该如何修复瓦尔格林德的未初始化值错误?
- C++:构造函数中的向量赋值错误
- 实现链接方法时打印的值错误
- gcc添加符号时出现无效版本(max)错误:值错误
- 尝试为图像缓冲区分配内存时 ptr 值错误
- 使用DPI从C 函数中从SV中的读取值错误
- gsl_interp_linear的插值错误
- Python C++ 生成生成值错误:"Symbol table not found"
- 类返回值错误
- 当使用单例包含指针数组时,左值错误
- RCpp:期望出现单值错误