The comment of Doug Bates on this thread motivated me to better examine
opportunities for algorithm improvements in my R package c++ code written
under Rcpp and RcppArmadillo. I performed a few changes: firstly, i
removed all general matrix inverse computations, replacing many with
triangular so
And actually, i got three different types of errors:
1)Error in betahat(ker, inv[l], cbind(inv[1:ll], inv[(ll + 1):(2 * ll)]), :
unused argument(s) (n = 1)
Calls: system.time ... apply -> FUN -> betahat -> .External -> cpp_exception
Execution halted
2)Error in betahat(ker, inv[l], cbind(inv[1:
Dear All,
I have modified the code as following. Since I found the old code had the
memory allocation issue, I calculated each term of the matrix with dim 4.
The speed is pretty much good now. But since I am not familiar with Rcpp,
the code sometimes will get error, like
*** caught segfault ***
a
I tried out that if the dim of the matrix less than or equal to 4, inv()
and solve() have the same speed.
Best wishes!
Honglang Wang
Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu
On Mon
Hi Honglang,
I recommend looking into using the solve() function in Armadillo, instead
of inv(). Using solve() will be considerably faster.
More details here:
http://arma.sourceforge.net/docs.html#solve
On Thursday, December 6, 2012, Honglang Wang
wrote:
> The following is a full example altho
Thanks Douglas, I will study your code and Eigen carefully.
Best wishes!
Honglang Wang
Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu
On Thu, Dec 6, 2012 at 1:33 PM, Douglas Bates wrote
On 6 December 2012 at 12:33, Douglas Bates wrote:
| // [[Rcpp::depends(RcppEigen)]]
| #include
|
| typedef Eigen::MatrixXd Mat;
| typedef Eigen::MapMMat;
| typedef Eigen::HouseholderQRQR;
| typedef Eigen::VectorXd Vec;
| typedef Eigen::Map
I don't know as much about Armadillo as I do about Eigen so I will cheat
and write using RcppEigen instead of RcppArmadillo. Page 6 of the Eigen
tutorial at http://eigen.tuxfamily.org/dox/ discusses decompositions and
solving linear systems of equations. One of the simplest ways of solving a
weig
> this part will always make your code crawl along:
>> arma::vec betahat = arma::inv(Inv)*arma::trans(D)*W*y;
I'd be very interested to see the before/after version of your code
code, Honglang. With timings. It'll make a good blog post or academic
paper (depending on just how many learnings you
this part will always make your code crawl along:
On Wed, Dec 5, 2012 at 11:09 AM, Honglang Wang
wrote:
> arma::vec betahat = arma::inv(Inv)*arma::trans(D)*W*y;
>
first time I wrote a GLM engine, I wrote it the way statistics books
illustrate it (i.e. actually invert things to do IWLS) and it
I am sorry. I think you are right. I know little about computation. And it
will be great that you write what you would like to wrote to explain to me.
I am really learning a lot from this discussion. Before I even have not
heard of profiling of a program. Thanks.
Best wishes!
Honglang Wang
Offic
The following is a full example although I don't know whether it's minimal
or not:
library(Rcpp)
library(RcppArmadillo)
sourceCpp("betahat_mod.cpp")
#The following is data generation.
n=200
m=20
p=2
t=runif(m*n,min=0, max=1)
X1=rnorm(m*n,0,1)
X1=as.matrix(1+2*exp(t)+X1)
X2=rnorm(m*n
On Tue, Dec 4, 2012 at 9:39 PM, Honglang Wang wrote:
> Yes, the main issue for my coding is the allocation of memory. And I have
> fixed one of the biggest memory allocation issue: 4000 by 4000 diagonal
> matrix. And since I am not familiar with Rcpp and RcppArmadillo, I have no
> idea how to reu
Can you post a minimal full example?
-Christian
On Tue, Dec 4, 2012 at 8:39 PM, Honglang Wang
wrote:
> Yes, the main issue for my coding is the allocation of memory. And I have
> fixed one of the biggest memory allocation issue: 4000 by 4000 diagonal
> matrix. And since I am not familiar with Rc
Yes, the main issue for my coding is the allocation of memory. And I have
fixed one of the biggest memory allocation issue: 4000 by 4000 diagonal
matrix. And since I am not familiar with Rcpp and RcppArmadillo, I have no
idea how to reuse the memory. I hope I can have some materials to learn
this.
I have the book on my desk as it happens, and it is a great one, but the
appendix is better than I remembered, so I parceled it out:
http://www.flaver.com/BoydVandenberghe_appendixC_numericalLinearAlgebra.pdf
(hope this helps a few other people)
I bought the text because I like being able to writ
On Tue, Dec 4, 2012 at 9:55 PM, Christian Gunning wrote:
> What exactly do these timings show? A single call you your function?
> How many calls?
>
> Building on Romain's point: -- a portion of your function's runtime is
> in memory allocation
> (and you have a lot of allocations here).
> If you'
What exactly do these timings show? A single call you your function?
How many calls?
Building on Romain's point: -- a portion of your function's runtime is
in memory allocation
(and you have a lot of allocations here).
If you're calling your function thousands or millions of times, then
it might
On 4 December 2012 at 20:39, Yan Zhou wrote:
| You cannot expect C++ to magically make your code faster. If speed is of
| concern, you need profiling to find the bottleneck instead of blind guessing.
I
Precisely. As I told Honglang just yesterday on this very list:
Some general advice: when
Le 04/12/12 21:27, Honglang Wang a écrit :
Since the "ker" function defined in R is very simple and vectorized, I
thought it was fine to call this function in C++. And I tried to code
this function inside C++, and I found it became ever slower: from
47.310s to 49.536s.
Hard to say what is going
You cannot expect C++ to magically make your code faster. If speed is of
concern, you need profiling to find the bottleneck instead of blind guessing. I
am not quite sure how to profile an Rcpp R program. Maybe someone else can help.
But my intuition is that your program simply need that much ti
Since the "ker" function defined in R is very simple and vectorized, I
thought it was fine to call this function in C++. And I tried to code this
function inside C++, and I found it became ever slower: from 47.310s to
49.536s.
// [[Rcpp::depends(RcppArmadillo)]]
#include
using namespace Rcpp;
You are calling back to R using Function. This is expensive.
What is ker ? Can you implement it in C++. This is a wild guess, but
that is I think where the bottleneck is.
Romain
Le 04/12/12 20:14, Honglang Wang a écrit :
Dear All,
I have tried out the first example by using RcppArmadillo, bu
Dear All,
I have tried out the first example by using RcppArmadillo, but I am not
sure whether the code is efficient or not. And I did the comparison of the
computation time.
1) R code using for loop in R: 87.22s
2) R code using apply: 77.86s
3) RcppArmadillo by using for loop in C++: 53.102s
4) R
24 matches
Mail list logo