[Rcpp-devel] Help with SubMatrix test case

Romain Francois romain at r-enthusiasts.com
Sat Dec 4 13:09:12 CET 2010


Le 04/12/10 03:45, Christian Gunning a écrit :
> In this test case, I expected yy to be a proper subset of xx.  I
> confess that I don't understand the results at all, but I'm assuming
> that the Row/Column exchange is involved. Am I missing anything?
>
> thanks,
> christian
>
> src<- '
>       NumericMatrix xx(4, 5);
>       xx(0,0) = 3;
>       xx(0,1) = 4;
>       xx(0,2) = 5;
>         Rf_PrintValue(xx);
>       xx(1,_) = xx(0,_);
>         Rf_PrintValue(xx);
>       xx(_,3) = xx(_,2);
>         Rf_PrintValue(xx);
>       SubMatrix<REALSXP>  yy = xx( Range(0,2), Range(0,3) ) ;
>         Rf_PrintValue(wrap(yy));
>       return(wrap(yy));
>   '
>
> myfun<- cxxfunction( , src, plugin='Rcpp')
>
> aa = myfun()

Thanks for reporting this. There was a trivial but quite harful bug in 
the indexing of SubMatrix. Fixed in rev 2705 and 2706.



While I am on this, would it be valuable to have something like this:

typedef SubMatrix<REALSXP> NumericSubMatrix ;

or perhaps inside Matrix we could have:

typedef typename SubMatrix<RTYPE> sub ;

So that we would write

NumericMatrix::sub yy = xx( Range(0,2), Range(0,3) )


Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
|- http://bit.ly/hovakS : RcppGSL initial release
`- http://bit.ly/iaxTdO : parser 0.0-12




More information about the Rcpp-devel mailing list