值' SET_ATTRIB'必须是一个pairlist或NULL,而不是一个整数'

时间:2017-07-20 02:24:25

标签: rcpp armadillo

我正在尝试使用RcppArmadillo对象在Rcpp中实现遗传算法的交叉操作。代码如下:

cppFunction( 'IntegerMatrix EBD_RS_BR3( arma::umat parents ){

    int nrow = parents.n_rows;
    int ncol = parents.n_cols;

    //Make two temporary matrices
    arma::umat fathers( nrow, ncol );
    arma::umat mothers( nrow, ncol );

    IntegerVector selector(2);

    for ( int i = 0; i < ncol; i ++ ){
        //Sample two columns from *parents* without replacement
        //Subtract 1 so we sample from [0,ncol-1]
        selector = sample( ncol, 2, false )-1;
        //Assign selected columns
        fathers.col(i) = parents.col( selector(0) );
        mothers.col(i) = parents.col( selector(1) );
    }

    // Make an indicator matrix
    arma::umat p = arma::randi<arma::umat>( nrow, ncol, arma::distr_param(0,1) );
    arma::umat return_matrix = p % fathers + (1-p) % mothers;

    return( wrap( return_matrix ) );
}', depends = "RcppArmadillo" )

当我在循环中多次运行代码时,例如
system.time( for( i in 1:100000 ){ print(i); EBD_RS_BR3( parents ) } )
 我有时会遇到错误:

Error in .Primitive(".Call")(<pointer: 0x0000000071282e00>, parents) : 
  value of 'SET_ATTRIB' must be a pairlist or NULL, not a 'integer'

在其他情况下,我收到错误:

Error in .Primitive(".Call")(<pointer: 0x0000000071282e00>, parents) : 
    unimplemented type 'NULL' in 'coerceToInteger'

有时,Rstudio在没有报告任何内容的情况下崩溃。

但是,我无法始终如一地重现此错误。请问如何解决这个问题?

由于

0 个答案:

没有答案