(x, dense_func, sparse_func, axis=None)
General wrapper for a function depending on sparse or dense matrices.
General wrapper for a function depending on sparse or dense matrices.
General wrapper for a function depending on sparse or dense matrices .
def _apply_func(x, dense_func, sparse_func, axis=None):
    """ General wrapper for a function depending on sparse or dense matrices. """
    if not sp.issparse(x):
        return dense_func(x, axis=axis)
    if axis is None:
        return sparse_func(x)
    if axis in [0, 1]:
        arr = x if axis == 1 else x.T
        arr = arr.tocsr()
        return np.fromiter((sparse_func(row) for row in arr),
                           dtype=np.double, count=arr.shape[0])
    else:
        raise NotImplementedError
def _apply_func ( x , dense_func , sparse_func , axis = None ) : if not sp . issparse ( x ) : return dense_func ( x , axis = axis ) if axis is None : return sparse_func ( x ) if axis in [ 0 , 1 ] : arr = x if axis == 1 else x . T arr = arr . tocsr ( ) return np . fromiter ( ( sparse_func ( row ) for row in arr ) , dtype = np . double , count = arr . shape [ 0 ] ) else : raise NotImplementedError