wrathematics / coop

Fast covariance, correlation, and cosine similarity.
Other
35 stars 6 forks source link

Matrix package support? #1

Closed dselivanov closed 8 years ago

dselivanov commented 8 years ago

Consider to add support for sparse matrices from Matrix package. I suppose Matrix is the standard and most widely used package for linear algebra with sparse matrices in R.

library(Matrix)
library(coop)
m <- sparseMatrix(i = sample(10), j = sample(10), x = sample(10))
cosine(m)

Error in co_vecvec(x, y, CO_SIM) : argument 'x' must be numeric

wrathematics commented 8 years ago

Good idea. I've added support for dgCMatrix by converting the column pointer into a column index. It could be made more efficient by natively operating on the CSC storage, but this is a good first step. I'll try to revisit in the future.

wrathematics commented 8 years ago

Implemented in https://github.com/wrathematics/coop/commit/c9fe174ced45968212166e884486724cd60bb53c?w=1

akhst7 commented 2 years ago

Hi,

I am using the latest coop, 0.6-3 installed from GitHub, and having a related issue as follows;

sparsity(su.int.mtfil@assays$integrated@data)
Error in UseMethod("sparsity") : 
  no applicable method for 'sparsity' applied to an object of class "c('dgCMatrix', 'CsparseMatrix', 'dsparseMatrix', 'generalMatrix', 'dCsparseMatrix', 'AnyMatrix', 'dMatrix', 'sparseMatrix', 'compMatrix', 'Matrix', 'xMatrix', 'mMatrix', 'replValueSp')"

Data are in the dgCMatrix format ;

@ data         :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:230157000] 0 1 2 3 4 5 6 7 8 9 ...
  .. .. ..@ p       : int [1:76720] 0 3000 6000 9000 12000 15000 18000 21000 24000 27000 ...
  .. .. ..@ Dim     : int [1:2] 3000 76719
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:3000] "Cd74" "S100a9" "Fabp4" "S100a8" ...
  .. .. .. ..$ : chr [1:76719] "AAACCCAAGATAGTGT-1_1" "AAACCCAAGGCAATGC-1_1" "AAACCCACACTCAGAT-1_1" "AAACCCACACTCCACT-1_1" ...
  .. .. ..@ x       : num [1:230157000] 19.718 0.473 -1.498 -1.293 8.137 ...
  .. .. ..@ factors : list()

So sparsity does not support sparse matrices ?