Skip to content

Rcpp Errror #974

@Kamel20

Description

@Kamel20

Hello everyone,
I am trying to speed up my code by using Rcpp, the last function in this code (myModel) makes a problem for me, when I compile the code, I get this error,

  1. cannot convert 'SEXP {aka SEXPREC*}' to 'Rcpp:traits::input_parameter::{aka Rcpp::InputParameter}' in initialization
  2. cannot convert 'Rcpp::traits::input_parameter::type{aka Rcpp::InputParameter}' to 'double*' for argument '3' to double myModel(double, int, double*, int)
    could anyone helps me for that,
#include <Rcpp.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include
using namespace Rcpp;
// Place the export tag right above function declaration.
// [[Rcpp::export]]
double FactorialC(int n)
{
int ii;
double prod;
if(n==0) return 1;
if(n==1) return 1;
prod=1.0;
for(ii=n; ii>0; ii--) prod *= ii;
return prod;
}
// [[Rcpp::export]]
double PoissonKC(double mu, int n)
{
double prob;
if(n==0) return (exp(-1.0*mu));
prob = (exp(-1.0*mu)*pow(mu,n))/FactorialC(n);
return prob;
}
// [[Rcpp::export]]
double myModel(double d, int m, double Vin, int flag){
double Vout, mu, probk;
int kk, jj, H,R;
Vout = (double) calloc(m+1, sizeof(double));
mu = 2(m+1)*d;
for(kk =0; kk<= 50; kk++){
probk = PoissonKC(mu, kk);
for(jj =0; jj<=m; jj++){
  if(kk>0){
    H = (jj + kk)/(m+1);
    R = (jj + kk)%(m+1);
    if(H >0){
      Vout[R] += 0.5*Vin[jj]*probk;
    }
    else{
      if(flag == 2) Vout[R] += Vin[jj]*probk;
    }
  }
  else{
    if(flag == 2) Vout[jj] += Vin[jj]*probk;
  } 
}
}
Vout;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions