Skip to content
Prev 9503 / 10988 Next

[Rcpp-devel] Timings for a program

Hello Dear

Your suggestions are quite useful. I have deleted two for loops from my
code and trying to use vectors in place of them. It is hard for me to
produce a minimal example. However, now I am trying to use vectorization. I
am having some error. Following is an example code. My basic purpose is
subcube element wise multiplication with matrix's row. The operand % is not
working in this case. Any suggestion would be appreciated.

Here a is a cube of dimension (3, 3, 1) and b is a matrix of dimension (3,
3).

#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace RcppArmadillo;
using namespace arma;
//[[Rcpp::depends(RcppArmadillo)]]
//[[Rcpp::export]]

arma::cube sub(arma::cube a, arma::mat b)
{
        a.subcube(2,0,0,2,2,0) = a.subcube(1, 0, 0, 1, 2, 0) .* b.row(0);
        return a;
}


The error is


subcube.cpp: In function ?arma::cube sub(arma::cube, arma::mat)?:
subcube.cpp:11:65: error: ?arma::Mat<eT>::row(arma::uword) [with eT =
double; arma::uword = unsigned int](0u)? cannot be used as a member
pointer, since it is of type  arma::subview_row<double>?
  a.subcube(2,0,0,2,2,0) = a.subcube(1, 0, 0, 1, 2, 0) .* b.row(0);






Thank You so much again for suggesting how to think about to produce a
speedy code.

Shaami
On Fri, Jan 6, 2017 at 5:03 AM, Martyn Plummer <plummerm at iarc.fr> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170107/f4ea38da/attachment.html>