Displaying 20 results from an estimated 27 matches for "csparsematrix".
Did you mean:
sparsematrix
2007 Apr 16
1
colSum() in Matrix objects
...column-wise using Matrix objects (Csparse).
It looks like one can apply mosty any base function to these objects
(i.e., apply, colSums), but there is a nasty conversion to traditional
matrix objects if one does that.
Is there any workaround? I can see colSum listed in the help for Class
'CsparseMatrix' , but I wonder whether I'm using the default colSums() or
the one specific to CsparseMatrix...
#example
(z = Matrix(c(0,1,0,0), 10,10))
zr = rowSums(z)
class(zr) # numeric; I'd like it to be a CSparseMatrix object
Thanks a lot in advance,
-Jose
--
Jose Quesada, PhD.
http://www.an...
2007 Jan 26
2
%*% in Matrix objects
...of row vectors. At a certain point I need to divide a matrix by a vector of norms. I find that the behavior of Matrix objects differs from normal matrix objects. Example the following code examples differ only in xnormed changing from normal to Matrix object:
x = matrix(1:12,3,4)
x = as(x, "CsparseMatrix")
xnorms = sqrt(colSums(x^2))
(xnormed = t(x) * (1/xnorms))
This produces a "warning: coercing sparse to dense matrix for arithmetic
in: t(x) * 1/xnorms." but gets the result (a 4 x 3 matrix)
I want to stay in sparse format anyway (if it helps!) so I tried
x = matrix(1:12,3,4)...
2007 Jun 19
1
Matrix library error: "should never happen; please report"
...x = x, i = i, j = j) :
'i' has no integer column number should never happen; please report
In addition: Warning messages:
1: Ambiguous method selection for "%*%", target "ddiMatrix#dgCMatrix" (the
first of the signatures shown will be used)
diagonalMatrix#CsparseMatrix
ddenseMatrix#CsparseMatrix
in: .findInheritedMethods(classes, fdef, mtable)
I got 4 other copies of the same warning. Will play around a bit more...
This is really strange.
Thanks
--
Jose Quesada, PhD.
http://www.andrew.cmu.edu/~jquesada
2025 Jan 18
0
How setClass() may introduce a binary dependency between packages
...quot;
# Error in validityMethod(as(object, superClass)) :
# object 'Csparse_validate' not found
detach('package:Matrix', unload = TRUE); library(Matrix)
sparseMatrix(1,1)
# 1 x 1 sparse Matrix of class "ngCMatrix"
#
# [1,] |
In turn, this can be traced to a copy of the CsparseMatrix class from
Matrix_1.5-1 remaining in the namespace and the lazy-load database of
SeuratObject:
readRDS('SeuratObject/R/SeuratObject.rdx')$variables |> names() |>
grep('sparseM', x = _, value = TRUE)
# [1] ".__C__CsparseMatrix" ".__C__dsparseMatrix" "....
2025 Jan 18
0
How setClass() may introduce a binary dependency between packages
...ct, superClass)) :
> # object 'Csparse_validate' not found
> detach('package:Matrix', unload = TRUE); library(Matrix)
> sparseMatrix(1,1)
> # 1 x 1 sparse Matrix of class "ngCMatrix"
> #
> # [1,] |
>
> In turn, this can be traced to a copy of the CsparseMatrix class from
> Matrix_1.5-1 remaining in the namespace and the lazy-load database of
> SeuratObject:
>
> readRDS('SeuratObject/R/SeuratObject.rdx')$variables |> names() |>
> grep('sparseM', x = _, value = TRUE)
> # [1] ".__C__CsparseMatrix" ".__...
2016 Apr 20
0
Matrix: How create a _row-oriented_ sparse Matrix (=dgRMatrix)?
...n 'Matrix' with all the class
hierarchies and the many specific classes has been to allow and
foster coercing to abstract super classes,
i.e, to "dMatrix" or "generalMatrix", "triangularMatrix", or
then "denseMatrix", "sparseMatrix", "CsparseMatrix" or
"RsparseMatrix", etc
So in the above as(*, "RsparseMatrix") should work always.
As a summary, in other words, for what you want,
as(sparseMatrix(.....), "RsparseMatrix")
should give you what you want reliably and efficiently.
> Am I doing...
2016 Jan 04
2
R, AIX 64-bit builds - trying to understand root cause for message: "Error: Line starting 'Package: tools ...' is malformed!"
The bulk is on my forums - the final post for today is:
Results to date:
A. It looks like I am going to need a newer compiler for C - xlc/xlC V11
apparently does not understand this code:
"/data/prj/cran/R-3.2.3/src/main/memory.c", line 2149.31: 1506-046 (S)
Syntax error.
I will have to check if R-devel has different code before asking for
assistence.
+2139 #ifdef
2016 Apr 19
2
Matrix: How create a _row-oriented_ sparse Matrix (=dgRMatrix)?
Using the Matrix package, how can I create a row-oriented sparse
Matrix from scratch populated with some data? By default a
column-oriented one is created and I'm aware of the note that the
package is optimized for column-oriented ones, but I'm only interested
in using it for holding my sparse row-oriented data and doing basic
subsetting by rows (even using drop=FALSE).
Here is what I
2007 May 15
1
Matrix package: writeMM
Hi,
I'm finding that readMM() cannot read a file written with writeMM().
Example:
library(Matrix)
a = Matrix(c(1,0,3,0,0,5), 10, 10)
a = as(a, "CsparseMatrix")
writeMM(a, "kk.mm")
b = readMM("kk.mm")
Error in validObject(.Object) : invalid class "dgTMatrix" object: all row
indices must be between 0 and nrow-1
Thoughts?
Thanks,
-Jose
--
Jose Quesada, PhD.
http://www.andrew.cmu.edu/~jquesada
2017 Oct 21
1
What exactly is an dgCMatrix-class. There are so many attributes.
....) is a simple utility from Matrix
> which -- very efficiently for sparseMatrix objects -- gives the
> number of nonzero entries of the matrix.
>
> All of these classes are formally defined classes and have
> therefore help pages. Here ?dgCMatrix-class which then points
> to ?CsparseMatrix-class (and I forget if Rstudio really helps
> you find these ..; in emacs ESS they are found nicely via the usual key)
>
> To get started, you may further look at ?Matrix _and_ ?sparseMatrix
> (and possibly the Matrix package vignettes --- though they need
> work -- I'm happy...
2006 Dec 19
1
preserving sparse matrices (Matrix)
Hi,
I have sparse (tridiagonal) matrices, and I use the Matrix package for
handling them. For certain computations, I need to either set the
first row to zero, or double the last row. I find that neither
operation preserves sparsity, eg
> m <- Diagonal(5)
> m
5 x 5 diagonal matrix of class "ddiMatrix"
[,1] [,2] [,3] [,4] [,5]
[1,] 1 . . . .
[2,] . 1
2020 Jul 21
2
trivial typo in ?Matrix::sparse.model.matrix.Rd
...at least need to be slightly fixed
before that Matrix version becomes default on CRAN, as these
packages make assumptions about unspecified behavior of some
Matrix functions, notably Matrix::Matrix() which in that next version
of Matrix will produce "diagonalMatrix" instead of
"CsparseMatrix" objects in more cases.... a good thing, but not
what those packages have assumed...
@Spencer: Are you actively using 'giveCsparse = ..' somewhere
in your code?
If not, why would you be interested in the details of the changes
(which would be entirely invisible to you as user...
2007 Jan 23
3
[fixed] vectorized nested loop: apply a function that takes two rows
...n R, but after reading the docs for
do.call, apply, etc, I still don't know how to write the nested loop in a
vectorized way.
Example data:
x = matrix(rnorm(100), 10, 10)
# this is actually a very large sparse matrix, but it doesn't matter for the
# example
library(Matrix)
x = as(x,"CsparseMatrix")
# cosine function
cosine = function (x, y){
if (is.vector(x) && is.vector(y)) {
return(crossprod(x, y)/sqrt(crossprod(x) * crossprod(y)))
} else {stop("cosine: argument mismatch. Two vectors needed as input.")}
}
# The loop-based solution I have is:
if (is(x, "...
2007 Jan 23
3
[fixed] vectorized nested loop: apply a function that takes two rows
...n R, but after reading the docs for
do.call, apply, etc, I still don't know how to write the nested loop in a
vectorized way.
Example data:
x = matrix(rnorm(100), 10, 10)
# this is actually a very large sparse matrix, but it doesn't matter for the
# example
library(Matrix)
x = as(x,"CsparseMatrix")
# cosine function
cosine = function (x, y){
if (is.vector(x) && is.vector(y)) {
return(crossprod(x, y)/sqrt(crossprod(x) * crossprod(y)))
} else {stop("cosine: argument mismatch. Two vectors needed as input.")}
}
# The loop-based solution I have is:
if (is(x, "...
2009 Oct 24
1
operations on sparse matrices, and dense intermediary steps
...pMatrix(nrow, ncol,
i = sample(nrow, nnz, replace = TRUE),
j = sample(ncol, nnz, replace = TRUE),
x = rand.x(nnz))
}
## (original ir a term x doc matrix of the entire wikipedia)
mm <- rSpMatrix(793251, 1027355, nnz = 205746204)
# make it column based:
mm <- as(mm, "CsparseMatrix")
a=mm[1,,drop=F]#this takes close to 30 seconds on a 3Ghz machine
Thanks,
- -Jose
- --
=== I'm learning a new keyboard layout. I type slowly. Please excuse
typos and slower-that-usual responses. Thanks for your patience===
Jose Quesada, PhD.
Max Planck Institute,
Center for Adaptive Beh...
2009 Jan 20
1
Creating a Sparse Matrix from a Sparse Vector
Hello,
I am working with a sparse matrix that is approx. 13,900 by 14,100. My
goal is to select a row out of the matrix and create a new matrix with that
row repeated 13,900 times without having to do any looping. Example:
Starting Matrix:
exampleMatrix
3 x 4 sparse Matrix of class "dgCMatrix"
[1,] 1 . . .
[2,] . 1 . 0.5
[3,] . . 1 ..
New Matrix:..
newExampleMatrix
3 x 4 sparse
2017 Oct 21
0
What exactly is an dgCMatrix-class. There are so many attributes.
...teger overflow)
and nnzero(.) is a simple utility from Matrix
which -- very efficiently for sparseMatrix objects -- gives the
number of nonzero entries of the matrix.
All of these classes are formally defined classes and have
therefore help pages. Here ?dgCMatrix-class which then points
to ?CsparseMatrix-class (and I forget if Rstudio really helps
you find these ..; in emacs ESS they are found nicely via the usual key)
To get started, you may further look at ?Matrix _and_ ?sparseMatrix
(and possibly the Matrix package vignettes --- though they need
work -- I'm happy for collaborators there...
2016 May 10
1
recursion problem using do.call(rbind, list(..,<S4>,..))
...le MRE (minimal reproducible example) for the problem seen with Matrix:
S <- sparseMatrix(i=1:4, j=9:6, x=pi*1:4)
n <- 410 # it succeeds for 407 -- sometimes even with 408
X <- replicate(n, S, simplify = FALSE)
Xb <- do.call("rbind", X)
## -> Error in as(x, "CsparseMatrix") : node stack overflow
But as I said, that's not really the Matrix package. A small
reproducible example, not involving the Matrix package at all:
MM <- setClass("mmatrix", contains="matrix")
setMethod("rbind2", signature(x="mmatrix", y=&qu...
2020 Jul 21
0
trivial typo in ?Matrix::sparse.model.matrix.Rd
...htly fixed
> before that Matrix version becomes default on CRAN, as these
> packages make assumptions about unspecified behavior of some
> Matrix functions, notably Matrix::Matrix() which in that next version
> of Matrix will produce "diagonalMatrix" instead of
> "CsparseMatrix" objects in more cases.... a good thing, but not
> what those packages have assumed...
>
> @Spencer: Are you actively using 'giveCsparse = ..' somewhere
> in your code?
> If not, why would you be interested in the details of the changes
> (which would be en...
2023 Jul 19
0
proposal for WRE: clarify that use of S4 classes implies use of superclasses
...problems
with stale caches that I described in this thread from September:
https://stat.ethz.ch/pipermail/r-devel/2022-September/081971.html
I've attached a script demonstrating my point. It creates and installs a
package named TestPackage with
importClassesFrom(Matrix, dgCMatrix, CsparseMatrix)
in NAMESPACE and
setClass("whatever", contains = "dgCMatrix")
in R/*.R. After installing the package, I see:
> ns <- asNamespace("TestPackage")
> names(ns)
[1] ".__C__generalMatrix" ".__C__Matrix" ".__C__sparse...