<reponame>larsmans/crab
"""
Extended math utilities.
"""
# Authors: <NAME>
# License: BSD

import numpy as np


def safe_sparse_dot(a, b, dense_output=False):
    """Dot product that handle the sparse matrix case correctly"""
    from scipy import sparse
    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)

"""
Extended math utilities.
"""
# Authors: <NAME>
# License: BSD

import numpy as np


def safe_sparse_dot(a, b, dense_output=False):
    """Dot product that handle the sparse matrix case correctly"""
    from scipy import sparse
    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)
Extended math utilities. # Authors: <NAME> # License: BSD Dot product that handle the sparse matrix case correctly