[Rcpp-devel] Multiplication of ComplexVector?

baptiste auguie baptiste.auguie at googlemail.com
Tue Aug 17 10:00:58 CEST 2010


On 17 August 2010 09:20, Romain Francois <romain at r-enthusiasts.com> wrote:
> Le 17/08/10 07:43, baptiste auguie a écrit :
>>
>> Hi,
>>
>> On 17 August 2010 03:24, Dirk Eddelbuettel<edd at debian.org>  wrote:
>>>
>>> On 16 August 2010 at 19:43, Dirk Eddelbuettel wrote:
>>
>> [...]
>>
>>> The only trouble is that nobody has written the corresponding 'glue' code
>>> to
>>> make
>>>
>>>      arma::cx_vec a1(y1.begin(), y1.size(), false);
>>>
>>> happen: create an Armadillo complex vector from an Rcpp::ComplexVector.
>>>  We
>>> can init by scalar size, what you'd need to insert for now is a simply
>>> (and
>>> very pedestrian) copy-loop.
>>
>> I'm confused, isn't
>>
>>  arma::cx_colvec a1 = Rcpp::as<  arma::cx_vec>( y1 );
>>
>> aimed at doing this kind of conversion? (that's what I use, following
>> Romain's tip)
>>
>> baptiste
>
> I don't think you are confused. This works well, but it does require some
> extra copying, which Dirk was trying to spare.
>
> Using the "advanced" constructor in armadillo means that both the
> ComplexVector and the cx_vec use the same memory. although it says loud and
> clear in armadillo documentation :
>
> """
> This is faster, but can be dangerous unless you know what you're doing!
> """


Thanks. Two questions then,

1- reinterpret_cast< std::complex<double>* > seems like a good option,
does it work with real / complex matrices as well? The only things
that came up from googling it were related to RcppGSL, not
RcppArmadillo.

2- when is it not safe? ;)

Thanks!

baptiste

PS: i wouldn't want to hijack the original query; I'll open a new
thread if this seems to raise further questions.


More information about the Rcpp-devel mailing list