2
votes

I have been using the package 'gpuR' to increase speed of code manipulating matrices. A matrix (formed by as.matrix(x)) can be converted to a vclMatrix using the code below (vcl indicates the data is stored on the GPU)

vclm <- vcLMatrix(x)

multmatrix <- vclm * vclm

is much quicker than

multmatrix <- x * x

for a large matrix, but how do I convert the multmatrix back into a standard R matrix for further manipulation?

Also, any idea why multiplication is so much faster but element wise addition e.g.

addmatrix <- vclm + vclm

is significantly slower than adding standard matrices?

Many thanks, Antony

1
I recommend you reading the author's blog in here. Maybe helpful. - Patric

1 Answers

2
votes

The solution is quite simple. You can convert a vclMatrix or gpuMatrix to a matrix by simply passing square brackets.

r_matrix <- multmatrix[]

In the most recent version on the package github version 1.2.2 has a convenience wrapper for as.matrix. It will be available in the next release on CRAN.