From 814ec27842e5c25980fa4de2825e0838a1f16ad5 Mon Sep 17 00:00:00 2001 From: Samuel <3030760+samuelstjean@users.noreply.github.com> Date: Fri, 11 Mar 2022 09:55:09 +0100 Subject: [PATCH] remove custom scipy rand --- myscipy_rand/__init__.py | 6 ---- myscipy_rand/myscipy_rand.py | 65 ------------------------------------ 2 files changed, 71 deletions(-) delete mode 100644 myscipy_rand/__init__.py delete mode 100644 myscipy_rand/myscipy_rand.py diff --git a/myscipy_rand/__init__.py b/myscipy_rand/__init__.py deleted file mode 100644 index 36116bf..0000000 --- a/myscipy_rand/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -__all__ = ['myscipy_rand'] - -from pkg_resources import get_distribution -__version__ = get_distribution('spams').version - -from .myscipy_rand import * diff --git a/myscipy_rand/myscipy_rand.py b/myscipy_rand/myscipy_rand.py deleted file mode 100644 index 4c292c3..0000000 --- a/myscipy_rand/myscipy_rand.py +++ /dev/null @@ -1,65 +0,0 @@ -from __future__ import absolute_import, division, print_function - -import numpy as np -import scipy.sparse as ssp - - -def rand(m, n, density=0.01, format="coo", dtype=None): - """Generate a sparse matrix of the given shape and density with uniformely - distributed values. - - Parameters - ---------- - m, n: int - shape of the matrix - density: real - density of the generated matrix: density equal to one means a full - matrix, density of 0 means a matrix with no non-zero items. - format: str - sparse matrix format. - dtype: dtype - type of the returned matrix values. - - Notes - ----- - Only float types are supported for now. - """ - if density < 0 or density > 1: - raise ValueError("density expected to be 0 <= density <= 1") - if dtype and not dtype in [np.float32, np.float64, np.longdouble]: - raise NotImplementedError("type %s not supported" % dtype) - - mn = m * n - - # XXX: sparse uses intc instead of intp... - tp = np.intp - if mn > np.iinfo(tp).max: - msg = """\ -Trying to generate a random sparse matrix such as the product of dimensions is -greater than %d - this is not supported on this machine -""" - raise ValueError(msg % np.iinfo(tp).max) - - # Number of non zero values - k = int(density * m * n) - - # Generate a few more values than k so that we can get unique values - # afterwards. - # XXX: one could be smarter here - mlow = 5 - fac = 1.02 - gk = min(k + mlow, fac * k) - - def _gen_unique_rand(_gk): - id = np.random.rand(_gk) - return np.unique(np.floor(id * mn))[:k] - - id = _gen_unique_rand(gk) - while id.size < k: - gk *= 1.05 - id = _gen_unique_rand(gk) - - j = np.floor(id * 1. / m).astype(tp) - i = (id - j * m).astype(tp) - vals = np.random.rand(k).astype(dtype) - return ssp.coo_matrix((vals, (i, j)), shape=(m, n)).asformat(format) -- GitLab