Skip to content

Commit

Permalink
removed scipy sparse utils dependency for better python version compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
mfinzi committed Apr 7, 2021
1 parent f426eed commit 8ccc705
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions emlp/reps/linear_operator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@

import jax.numpy as np

from scipy.sparse import isspmatrix
from scipy.sparse.sputils import isshape, isintlike, asmatrix, is_pydata_spmatrix

__all__ = ['LinearOperator', 'aslinearoperator']


Expand Down Expand Up @@ -638,7 +635,7 @@ def __init__(self, A, p):
raise ValueError('LinearOperator expected as A')
if A.shape[0] != A.shape[1]:
raise ValueError('square LinearOperator expected, got %r' % A)
if not isintlike(p) or p < 0:
if not isinstance(p,int) or p < 0:
raise ValueError('non-negative integer expected as p')

super(_PowerLinearOperator, self).__init__(_get_dtype([A]), A.shape)
Expand Down Expand Up @@ -784,4 +781,25 @@ def invT(self):
# rmatmat=rmatmat, dtype=dtype)

# else:
# raise TypeError('type not understood')
# raise TypeError('type not understood')


def isintlike(x):
return isinstance(x,int)


def isshape(x, nonneg=False):
"""Is x a valid 2-tuple of dimensions?
If nonneg, also checks that the dimensions are non-negative.
"""
try:
# Assume it's a tuple of matrix dimensions (M, N)
(M, N) = x
except Exception:
return False
else:
if isintlike(M) and isintlike(N):
if np.ndim(M) == 0 and np.ndim(N) == 0:
if not nonneg or (M >= 0 and N >= 0):
return True
return False

0 comments on commit 8ccc705

Please sign in to comment.