ceslobfer / GPUmatrix

GPUmatrix: An R package for algebra using GPU
32 stars 1 forks source link

Problem related to cov() #4

Closed Backlonhw2468 closed 9 months ago

Backlonhw2468 commented 9 months ago

Dear Authors of this very much needed package,

I seem to get different results doing basic cov calculations. They are far from identical but surprisingly in fixed Ratio. Please help. Thank you so much!

Code Example:

library(GPUmatrix) library(magrittr)

set.seed(1234)

mt_Random<- matrix( rnorm(1000),nrow = 200,byrow = F )

Result_Cov_Calculated_by_GPU<- as.gpu.matrix(mt_Random)%>% cov(.)

Result_Cov_Calculated_default<- mt_Random%>% cov(.)

ceslobfer commented 9 months ago

Dear user, I'm glad that you are using our package and finding it useful.

We have just uploaded a new version of the package where we fixed some bugs and added compatible R functions for GPUmatrix and other new features (See new README). It has been sent to CRAN and the new update will be available in a couple of days. The issue you mentioned has been fixed and is already updated here on GitHub in the main branch. If you want to install it directly from GitHub, you can do so by using: install_github("ceslobfer/GPUmatrix").

Your code:

library(GPUmatrix)
library(magrittr)

set.seed(1234)

mt_Random<-
  matrix(
    rnorm(1000),nrow = 200,byrow = F
  )

Result_Cov_Calculated_by_GPU<-
  as.gpu.matrix(mt_Random)%>%
  cov(.)

Result_Cov_Calculated_default<-
  mt_Random%>%
  cov(.)

Result:

> Result_Cov_Calculated_default
            [,1]        [,2]        [,3]        [,4]        [,5]
[1,]  1.04175945  0.10898664 -0.05987783  0.10973381 -0.20395392
[2,]  0.10898664  1.01408645  0.05833143 -0.01812381 -0.07080393
[3,] -0.05987783  0.05833143  1.05296457 -0.01668027  0.03943891
[4,]  0.10973381 -0.01812381 -0.01668027  0.90475002 -0.06176754
[5,] -0.20395392 -0.07080393  0.03943891 -0.06176754  0.96573560
> Result_Cov_Calculated_by_GPU
GPUmatrix
torch_tensor
 1.0418  0.1090 -0.0599  0.1097 -0.2040
 0.1090  1.0141  0.0583 -0.0181 -0.0708
-0.0599  0.0583  1.0530 -0.0167  0.0394
 0.1097 -0.0181 -0.0167  0.9048 -0.0618
-0.2040 -0.0708  0.0394 -0.0618  0.9657
[ CUDADoubleType{5,5} ]

Best regards and thank you very much for using our package.

Backlonhw2468 commented 9 months ago

Thank you!