Skip to content
Prev 1433 / 10988 Next

[Rcpp-devel] Help with SubMatrix test case

Interesting.  Here's a fully-formed example:

src3 <- '
    int rr = 4, cc = 5;
    List ret;
    NumericMatrix xx(rr, cc);
    RNGScope scope;
    NumericVector zz = rnorm(rr*cc);
    for (int i = 0; i<rr*cc; i++) {
        xx[i] = zz[i];
    }
    xx(1,_) = xx(0,_);
    xx(_,1) = xx(_,0);

    ret["fullmat"] = xx;
    NumericMatrix yy1 = xx( Range(0,2), Range(0,3) ) ;
    ret["submat"] = yy1;

    NumericVector zz2 = xx( _, 1);
    ret["col"] = zz2;

    arma::mat mm( xx.begin(), rr, cc, false );
    arma::mat sm = mm.submat(0,0,2,3);
    ret["arma"] = wrap(sm);
    return(ret);
'

myfun3 <- cxxfunction( , src3, plugin='RcppArmadillo')
aa3 <- myfun3()

identical(aa3$col, aa3$fullmat[,2])
[1] TRUE
identical(aa3$arma, aa3$fullmat[1:3,1:4])
[1] TRUE
identical(aa3$submat, aa3$arma)
[1] FALSE

-christian