[Rcpp-devel] broken package after udpate
baptiste auguie
baptiste.auguie at gmail.com
Sat Nov 17 00:59:55 CET 2012
I see, thanks a lot for tracking this down.
In practical terms, should I change all such functions to use SEXP +
explicit wrap, or will you submit a new CRAN version soon enough fixing
this? Personally I don't mind waiting a bit for the CRAN fix of cda;
probably noone else uses my package and I'd rather avoid making unnecessary
workaround fixes. That being said, I would be surprised if no other
packages broke because of this.
All the best,
baptiste
On 17 November 2012 12:44, Romain Francois <romain at r-enthusiasts.com> wrote:
> This is about one of C++ most annoying things. order of includes.
>
> To make it short, the function that is responsible for making an R object
> out of the returned arma::mat is module_wrap, which calls wrap,
>
> Where module_wrap is currently written, it does not "see" the wrap()
> overloads from RcpppArmadillo so it just uses a version that uses begin()
> and end() and therefor just creates a vector.
>
> So, alright. I broke this. This is an easy fix, although I'm afraid one
> that has to happen in Rcpp.
>
> A contingency measure might be to write your euler function like this:
>
>
>
> SEXP euler(const double phi, const double theta, const double psi)
> {
> arma::mat Rot(3,3);
> const double cosphi = cos(phi), cospsi = cos(psi), costheta =
> cos(theta);
> const double sinphi = sin(phi), sinpsi = sin(psi), sintheta =
> sin(theta);
> Rot(0,0) = cospsi*cosphi - costheta*sinphi*sinpsi;
> Rot(0,1) = cospsi*sinphi + costheta*cosphi*sinpsi;
> Rot(0,2) = sinpsi*sintheta;
>
> Rot(1,0) = -sinpsi*cosphi - costheta*sinphi*cospsi;
> Rot(1,1) = -sinpsi*sinphi + costheta*cosphi*cospsi;
> Rot(1,2) = cospsi*sintheta;
>
> Rot(2,0) = sinphi*sintheta;
> Rot(2,1) = -cosphi*sintheta;
> Rot(2,2) = costheta;
>
> return wrap(Rot);
> }
>
> because there you call the right "wrap".
>
> Of course, the desired behaviour of having arma::mat as returned type will
> be brought back.
>
> Romain
>
> Le 17/11/12 00:08, Dirk Eddelbuettel a écrit :
>
>
>> On 17 November 2012 at 11:31, baptiste auguie wrote:
>> | Hi,
>> |
>> | (Hopefully this makes it to the list; I believe I've had problems
>> reaching it
>> | because of a recent change between @gmail and @googlemail).
>>
>> Looks like it.
>>
>> | I made a minimal package * to illustrate the problem of my recently
>> broken
>> | package cda (since yesterday's update of Rcpp). There's only one
>> function euler
>> | () in a Module named cda. It used to return a 3x3 matrix, but after
>> updating to
>> | Rcpp 0.10 it returns a vector. You can run the example with
>> |
>> | $ R -f inst/testing/test.r
>> |
>> | What am I doing wrong?
>> |
>> | Best,
>> |
>> | baptiste
>> |
>> | * https://dl.dropbox.com/u/**352834/cda_1.2.1.tar.gz<https://dl.dropbox.com/u/352834/cda_1.2.1.tar.gz>
>>
>> Good example. I added one line
>> Rcpp::Rcout << "In Euler, Rot is " << std::endl << Rot << std::endl;
>> and the end of 'Euler' and we see that the dimension is in fact there, but
>> then gets lost on the way out:
>>
>>
>> edd at max:/tmp/baptiste$ r -lcda -p -e'M <- cda$euler(1.1, 2.0, 3.1);
>> dim(M); class(M); M'
>> [1] "cda" "grid" "reshape2" "randtoolbox"
>> [5] "rngWELL" "statmod" "plyr" "RcppArmadillo"
>> [9] "Rcpp" "methods" "base"
>> In Euler, Rot is
>> -0.4378 -0.8983 0.0378
>> -0.3894 0.1515 -0.9085
>> 0.8104 -0.4125 -0.4161
>>
>> [1] -0.43778268 -0.38941320 0.81037256 -0.89828547 0.15154235
>> -0.41245379
>> [7] 0.03780919 -0.90851102 -0.41614684
>> NULL
>> [1] "numeric"
>> [1] -0.43778268 -0.38941320 0.81037256 -0.89828547 0.15154235
>> -0.41245379
>> [7] 0.03780919 -0.90851102 -0.41614684
>> edd at max:/tmp/baptiste$
>>
>> That is with the newest Rcpp and RcppArmadillo. So somewhere we are
>> loosing
>> the matrix attribute.
>>
>> If I 'make the whole thing slower' by explicitly converting, it works -- I
>> just add euler2 as
>>
>> NumericMatrix euler2(const double phi, const double theta, const double
>> psi) {
>> arma::mat M(3,3);
>> M = euler(phi, theta, psi);
>> return Rcpp::wrap(M);
>> }
>> // [...]
>> function( "euler2", &euler2, "Constructs a 3x3 Euler rotation matrix" ) ;\
>>
>> as seen here:
>>
>>
>> edd at max:/tmp/baptiste$ r -lcda -p -e'M <- cda$euler2(1.1, 2.0, 3.1);
>> dim(M); class(M); M'
>> [1] "cda" "grid" "reshape2" "randtoolbox"
>> [5] "rngWELL" "statmod" "plyr" "RcppArmadillo"
>> [9] "Rcpp" "methods" "base"
>> In Euler, Rot is
>> -0.4378 -0.8983 0.0378
>> -0.3894 0.1515 -0.9085
>> 0.8104 -0.4125 -0.4161
>>
>> [,1] [,2] [,3]
>> [1,] -0.4377827 -0.8982855 0.03780919
>> [2,] -0.3894132 0.1515423 -0.90851102
>> [3,] 0.8103726 -0.4124538 -0.41614684
>> [1] 3 3
>> [1] "matrix"
>> [,1] [,2] [,3]
>> [1,] -0.4377827 -0.8982855 0.03780919
>> [2,] -0.3894132 0.1515423 -0.90851102
>> [3,] 0.8103726 -0.4124538 -0.41614684
>> edd at max:/tmp/baptiste$
>>
>> So somewhere between the compiler getting smarter, Conrad optimising
>> expression and us, an attribute got lost.
>>
>> Maybe Romain can find a way to make this explicit.
>>
>> Cheers, Dirk
>>
>>
>>
>>
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
>
> R Graph Gallery: http://gallery.r-enthusiasts.**com<http://gallery.r-enthusiasts.com>
> `- http://bit.ly/SweN1Z : SuperStorm Sandy
>
> blog: http://romainfrancois.blog.**free.fr<http://romainfrancois.blog.free.fr>
> |- http://bit.ly/RE6sYH : OOP with Rcpp modules
> `- http://bit.ly/Thw7IK : Rcpp modules more flexible
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121117/f253854f/attachment.html>
More information about the Rcpp-devel
mailing list