Git Product home page Git Product logo

Comments (9)

flying-sheep avatar flying-sheep commented on June 15, 2024 1

Well, eigs_sym only uses a triangle, right? so you could just do this, right?

##' @rdname eigs
##' @export
eigs.dsCMatrix <- function(A, k, which = "LM", opts = list(), ...)
{
    if (! which %in% c("LM", "SM", "LR", "SR"))
        stop('Symmetric matrices can only support `which %in% c("LM", "SM", "LR", "SR")`')
    if (which == "LR") which <- "LA"
    if (which == "SR") which <- "SA"
    # I think you can just use it as a dgCMatrix without adding a mattype here
    eigs_real_sym(A, nrow(A), k, which, sigma, opts, mattype = "sym_dgCMatrix",
                  extra_args = list(use_lower = A@uplo == "L"))
}

Also you are more than welcome to contribute. πŸ˜ƒ

With pleasure! If above code is about correct, I’ll happily send a PR.

from rspectra.

flying-sheep avatar flying-sheep commented on June 15, 2024 1

I would do the following:

  1. Check if you can somehow coerce a dgCMatrix to a dsCMatrix while setting the uplo slot and not copying the data
  2. Check if that works if more than that triangle is filled in the dgCmatrix
  3. Change the internal names sym_dgCMatrix β†’ dsCMatrix and the lower parameter to use the uplo slot instead
  4. change the R methods so that eigs.dgCMatrix delegates to eigs_sym.dsCMatrix if isSymmetric(A) and so on

from rspectra.

yixuan avatar yixuan commented on June 15, 2024

Yeah, adding new matrix classes should be a relatively easy task. However, the downside for these two is that they do not have a counterpart in the Eigen library. It may take some effort to implement all the matrix operations, but I'll gradually add them if I get some time. Also you are more than welcome to contribute. πŸ˜ƒ

from rspectra.

yixuan avatar yixuan commented on June 15, 2024

The R code is good. What I mean is that the C++ part needs to correctly handle the dsCMatrix object, whose internal structure may be different from dgCMatrix.

from rspectra.

privefl avatar privefl commented on June 15, 2024

You could always use the function interface, right?

library(Matrix)
mat <- sparseMatrix(i = 1:2, j = c(2, 2), x = 1:2, dims = c(3, 3))
(mat2 <- forceSymmetric(mat))
RSpectra::eigs_sym(mat2, k = 1)                                # NOK
RSpectra::eigs_sym(function(x, args) as.vector(mat2 %*% x), 
                   k = 1, n = nrow(mat2))                      # OK

Would this be slower to do it like this?

from rspectra.

flying-sheep avatar flying-sheep commented on June 15, 2024

@yixuan look at the comment in the R code: I think it’s the exact same thing except for the uplo property and the fact that only a triangle is specified. Which matches exactly your usage of sym_dgCMatrix. (I think you could just rename that to dsCMatrix)

@privefl as said: since I think that dsCMatrix is exactly what @yixuan calls sym_dgCMatrix (with an added uplo attribute), it’s just much more elegant to directly use that.

from rspectra.

yixuan avatar yixuan commented on June 15, 2024

Great. I'll take a look later.

from rspectra.

yixuan avatar yixuan commented on June 15, 2024

I've checked the structure of dsCMatrix and can confirm that it is compatible with dgCMatrix. So, yes, go ahead and submit a PR. πŸ˜ƒ

from rspectra.

alexpghayes avatar alexpghayes commented on June 15, 2024

Thanks for starting the PR, this will be very useful for a project I'm currently working on!

from rspectra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.