RSpectra
RSpectra copied to clipboard
Symmetric sparse matrices
Thanks for this great package! Was wondering if you could help with a issue.
The documentation suggests that eigs_sym()
should be able to handle sparse matrix input, but there appears to be some subtleties to handling sparsity in symmetric matrices. Specifically, I get an error when I run this code:
# Create sparse, symmetric matrix
library(Matrix)
set.seed(1)
n <- 4
M <- matrix(0, nrow = n, ncol = n)
M[sample(n, 2), sample(n, 2)] <- rnorm(n)
A <- crossprod(M)
A <- as(A, 'sparseMatrix') # Note the class of A is dsCMatrix
# This works
e <- eigs(A, k = 2)
# This does not
e <- eigs_sym(A, k = 2)
The last line generates the following error:
Error in UseMethod("eigs_sym") :
no applicable method for 'eigs_sym' applied to an object of class "c('dsCMatrix', 'CsparseMatrix', 'dsparseMatrix', 'symmetricMatrix', 'dMatrix', 'sparseMatrix', 'Matrix')"
Interestingly, I do not get the same error when passing a dgeMatrix
to eigs_sym
. Hopefully this is an easy fix?