Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparse matrix support #79

Closed
bdpedigo opened this issue Dec 5, 2018 · 4 comments · Fixed by #523
Closed

sparse matrix support #79

bdpedigo opened this issue Dec 5, 2018 · 4 comments · Fixed by #523
Labels
enhancement New feature or request
Projects

Comments

@bdpedigo
Copy link
Collaborator

bdpedigo commented Dec 5, 2018

Should be easy, most functions should already work on sparse matrices but we will need to update our typechecking in several places and write tests to make sure.

Also J1c says that one of the SVDs does not work on sparse

Possibly could include support for rank 1 + sparse matrices where rather than many 0s they have many of some constant

@bdpedigo bdpedigo added the enhancement New feature or request label Jan 26, 2019
@j1c
Copy link
Collaborator

j1c commented Feb 5, 2019

Never really understood the point of that function.

def safe_sparse_dot(a, b, dense_output=False):
    """Dot product that handle the sparse matrix case correctly
    Uses BLAS GEMM as replacement for numpy.dot where possible
    to avoid unnecessary copies.
    Parameters
    ----------
    a : array or sparse matrix
    b : array or sparse matrix
    dense_output : boolean, default False
        When False, either ``a`` or ``b`` being sparse will yield sparse
        output. When True, output will always be an array.
    Returns
    -------
    dot_product : array or sparse matrix
        sparse if ``a`` or ``b`` is sparse and ``dense_output=False``.
    """
    if sparse.issparse(a) or sparse.issparse(b):
        ret = a * b
        if dense_output and hasattr(ret, "toarray"):
            ret = ret.toarray()
        return ret
    else:
        return np.dot(a, b)

Just does * instead of @, which I think is equivalent in later versions of python.

import numpy as np
from scipy.sparse import csr_matrix

X = csr_matrix(np.random.normal(size=(100, 4)))
U = X * X.T
V = X @ X.T

(U != V).nnz == 0
>>> True

@j1c
Copy link
Collaborator

j1c commented Feb 6, 2019

TODO:

  • ASE should require no changes
  • LSE might require changes to to_laplace
  • Omni requires change in omnibus matrix creation
  • cmds requires change for matrix pairwise distance computation, but no change for vector pairwise distance computation

@j1c
Copy link
Collaborator

j1c commented Mar 4, 2019

More TODO:

  • Change PTR to output sparse matrix if input is sparse
  • Changes to simulations to output sparse matrix similar to link
    • This is lots of work
  • Need to check the following if output is sparse if input is sparse
    • LCC functions
    • symmetrize
    • augment_diagonal
    • remove_loops

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Sprint 2
  
Awaiting triage
Development

Successfully merging a pull request may close this issue.

2 participants