Add scipy2ri conversion for csr / coo sparse matrices

Issue #596 resolved
Scott Gigante created an issue

The R Matrix package and scipy both provide support for CSR, CSC and COO matrices, and yet rpy2 does not provide support to convert these. Are there any plans to provide such support?


Comments (9)

  1. Laurent Gautier

    There no immediate plans, but a first implementation in a independent package would make sense.

    I just don’t have the bandwidth at the moment, but I am happy to help someone get started by setting up the initial skeleton and how to wire things to rpy2 (conversion mechanisms, etc…)

  2. Scott Gigante reporter

    Depending on how difficult it is I could be interested. I implemented the inverse conversion from reticulate. Do you mind sharing the skeleton?

  3. Laurent Gautier


    The R package Matrix is somewhat complex with quite a few S4 classes, so this only a hint at how much there is to be done to fully map it. A minimal viable mapping would not have to be exhaustive.

    Let me know what you think.

  4. Scott Gigante reporter

    Sounds good. The way we did this in reticulate is that any unmapped sparse matrix classes were first converted in R to a suitable matrix class (with a warning) and then converted back if possible.

  5. Scott Gigante reporter

    Silly question because I’m not super familiar with rpy2’s internals: where should I implement the actual conversion functions (equivalent of py2rpy and rpy2py)?

  6. Laurent Gautier

    Modules rpy2.robjects.numpy2ri or rpy2.robjects.pandas2ri are examples of converters.

    What a converter for Matrix could do is to check whether R S4 objects are R Matrix objects can be converted to a corresponding scipy object (or leave them as S4 objects otherwise), and the other waty around (whether a scipyobject can be converted to an rpy2/R Matrix object, ideally as instance of subclasses of rpy2.robjects.RS4).

    So far the code in is only building an rpy2 class hierarchy for some of the Matrix classes in the R packages. I should have time in few days to add a functioning mimal converter to build on.

  7. Log in to comment