Reputation: 643
It takes (on my MBP with 2.9 GHz Intel Core i7 and 16 GB memory) more than 20 seconds to get cross-product of a 40,000 x 1,000 matrix:
> system.time(a <- crossprod(matrix(pi,40000,1000)))
user system elapsed
23.808 0.139 24.001
Is there any way ever to make it faster? Thanks for your help.
Upvotes: 1
Views: 580
Reputation: 146120
By changing your code? Basically no. crossprod
directly calls compiled code, you'll be hard pressed to find any performance gains, and any you find will be small.
(Barring extenuating circumstances--how dense is your matrix? If you've got a lot of 0s, then using a sparse matrix may help. I'm also assuming your matrix isn't just a constant matrix as in your example.)
You could also use Microsoft's Revolution R Open which is compiled to use a different BLAS, or compile R yourself with a more optimized BLAS. This link has good details on that. For pure linear algebra manipulations, this could have a quite large effect. This site shows order of magnitude speed-ups for matrix multiplication, cholesky decomposition, etc.
Upvotes: 5