Coder Social home page Coder Social logo

sparse matrix support about graspologic HOT 4 CLOSED

microsoft avatar microsoft commented on May 22, 2024
sparse matrix support

from graspologic.

Comments (4)

bdpedigo avatar bdpedigo commented on May 22, 2024

https://scikit-learn.org/stable/modules/generated/sklearn.utils.extmath.safe_sparse_dot.html#sklearn.utils.extmath.safe_sparse_dot

from graspologic.

j1c avatar j1c commented on May 22, 2024

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

from graspologic.

j1c avatar j1c commented on May 22, 2024

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

from graspologic.

j1c avatar j1c commented on May 22, 2024

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

from graspologic.

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.