styvon / cPCG

R package for solving system of linear equations using (preconditioned) conjugate gradient algorithm, with improved efficiency using C++ Armadillo linear algebra library, and flexibility for user-specified preconditioning method.
GNU General Public License v3.0
10 stars 1 forks source link

Not compatible type #3

Open grighi opened 2 years ago

grighi commented 2 years ago

I'm getting a type error when trying to use pcgsolve_sparseOMP. Here's an example:

> library(Matrix)
> library(cPCG)
> library(dplyr)
> 
> aa <- data.frame(id = c(rep(1, 3), rep(2, 3)),
+                  grp = c(3,4,4,3,3,4))
> aa$w = aa$id + (aa$grp-2) + rnorm(6)
> 
> lm(w ~ as.factor(id) + as.factor(grp) - 1, aa) %>% coef %>% unname
[1] 2.0701328 3.2438530 0.1713803
> 
> X <- model.matrix(w ~ as.factor(id) + as.factor(grp) - 1, aa) 
> xx <- t(X) %*% X
> xy <- t(X) %*% aa$w
> pcgsolve(xx, xy) %>% t
         [,1]     [,2]      [,3]
[1,] 2.070133 3.243853 0.1713803
> 
> Sxx <- as(xx, "dgCMatrix")
> Sxy <- as(xy, "dgCMatrix")
> 
> pcgsolve_sparseOMP(Sxx, Sxy)
Error in pcgsolve_sparseOMP(Sxx, Sxy) : 
  Not compatible with requested type: [type=S4; target=double].