Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-lazyarray for
openSUSE:Factory checked in at 2021-11-10 21:46:31
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-lazyarray (Old)
and /work/SRC/openSUSE:Factory/.python-lazyarray.new.1890 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-lazyarray"
Wed Nov 10 21:46:31 2021 rev:4 rq:930576 version:0.5.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-lazyarray/python-lazyarray.changes
2021-02-15 23:19:41.543699788 +0100
+++
/work/SRC/openSUSE:Factory/.python-lazyarray.new.1890/python-lazyarray.changes
2021-11-10 21:47:02.959827171 +0100
@@ -1,0 +2,12 @@
+Wed Nov 10 04:15:34 UTC 2021 - Steve Kowalik <[email protected]>
+
+- Update to 0.5.0:
+ * Drop support for Python 2.7
+ * Added a more general way to specify that an array-like object should be
+ treated as a scalar by lazyarray (for arrays of arrays, etc.)
+ * Add partial support for NumPy ufuncs that require two arguments,
+ e.g. "power".
+- Add patch use-pytest.patch:
+ * Drop use of nose, use pytest methods.
+
+-------------------------------------------------------------------
Old:
----
lazyarray-0.3.3.tar.gz
New:
----
lazyarray-0.5.0.tar.gz
use-pytest.patch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-lazyarray.spec ++++++
--- /var/tmp/diff_new_pack.Quroq3/_old 2021-11-10 21:47:03.487827401 +0100
+++ /var/tmp/diff_new_pack.Quroq3/_new 2021-11-10 21:47:03.487827401 +0100
@@ -17,20 +17,21 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
+%define skip_python2 1
%global skip_python36 1
Name: python-lazyarray
-Version: 0.3.3
+Version: 0.5.0
Release: 0
Summary: Lazily-evaluated numerical array class, compatible with NumPy
arrays
License: BSD-3-Clause
-Group: Development/Languages/Python
URL: http://github.com/NeuralEnsemble/lazyarray/
Source:
https://files.pythonhosted.org/packages/source/l/lazyarray/lazyarray-%{version}.tar.gz
+# gh#NeuralEnsemble/lazyarray/pulls/15
+Patch0: use-pytest.patch
BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
# SECTION test requirements
-BuildRequires: %{python_module nose}
BuildRequires: %{python_module numpy >= 1.5}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module scipy}
@@ -59,6 +60,7 @@
%prep
%setup -q -n lazyarray-%{version}
+%autopatch -p1
%build
%python_build
++++++ lazyarray-0.3.3.tar.gz -> lazyarray-0.5.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/LICENSE new/lazyarray-0.5.0/LICENSE
--- old/lazyarray-0.3.3/LICENSE 2019-05-13 13:40:11.000000000 +0200
+++ new/lazyarray-0.5.0/LICENSE 2021-03-16 10:55:39.129128000 +0100
@@ -1,4 +1,4 @@
-Copyright (c) 2012-2017, Andrew P. Davison, Jo??l Chavas and Elodie Legou??e
(CNRS)
+Copyright (c) 2012-2020, Andrew P. Davison, Jo??l Chavas and Elodie Legou??e
(CNRS)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/PKG-INFO new/lazyarray-0.5.0/PKG-INFO
--- old/lazyarray-0.3.3/PKG-INFO 2019-05-13 13:49:08.000000000 +0200
+++ new/lazyarray-0.5.0/PKG-INFO 2021-11-09 13:39:44.744317300 +0100
@@ -1,10 +1,10 @@
Metadata-Version: 1.1
Name: lazyarray
-Version: 0.3.3
+Version: 0.5.0
Summary: a Python package that provides a lazily-evaluated numerical array
class, larray, based on and compatible with NumPy arrays.
Home-page: http://github.com/NeuralEnsemble/lazyarray/
Author: Andrew P. Davison
-Author-email: [email protected]
+Author-email: [email protected]
License: Modified BSD
Description:
=========
@@ -45,6 +45,5 @@
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
-Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/changelog.txt
new/lazyarray-0.5.0/changelog.txt
--- old/lazyarray-0.3.3/changelog.txt 2019-05-13 13:45:05.000000000 +0200
+++ new/lazyarray-0.5.0/changelog.txt 2021-11-09 13:30:33.910052300 +0100
@@ -98,6 +98,25 @@
* Do not raise a "shape mismatch" `ValueError` if the value shape is empty.
+Release 0.3.4
+=============
+
+* Add support for Brian quantities, and perhaps NumPy scalars in general
+* Updated to test with more recent versions of Python, NumPy and SciPy
+* Can now compare equality of lazyarrays to numbers and arrays
+
+Release 0.4.0
+=============
+
+* Drop support for Python 2.7
+* Added a more general way to specify that an array-like object should be
treated as a scalar by lazyarray (for arrays of arrays, etc.)
+
+Release 0.5.0
+=============
+
+* Add partial support for NumPy ufuncs that require two arguments, e.g.
"power".
+ The second argument must be a scalar, array-valued second args are not yet
supported.
+
.. _`#3`: https://bitbucket.org/apdavison/lazyarray/issue/3/
.. _`#4`: https://bitbucket.org/apdavison/lazyarray/issue/4/
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/doc/installation.txt
new/lazyarray-0.5.0/doc/installation.txt
--- old/lazyarray-0.3.3/doc/installation.txt 2019-05-13 13:47:53.000000000
+0200
+++ new/lazyarray-0.5.0/doc/installation.txt 2021-11-09 13:37:44.368170700
+0100
@@ -5,9 +5,9 @@
Dependencies
============
- * Python >= 2.7
- * numpy_ >= 1.8 (or >= 1.12 for Python 3)
- * (optional) scipy_ >= 0.14
+ * Python >= 3.4
+ * numpy_ >= 1.12
+ * (optional) scipy_ >= 0.17
Installing from the Python Package Index
========================================
@@ -21,12 +21,12 @@
To download and install manually, download:
- https://pypi.python.org/packages/source/l/lazyarray/lazyarray-0.3.3.tar.gz
+ https://pypi.python.org/packages/source/l/lazyarray/lazyarray-0.5.0.tar.gz
Then::
- $ tar xzf lazyarray-0.3.3.tar.gz
- $ cd lazyarray-0.3.3
+ $ tar xzf lazyarray-0.5.0.tar.gz
+ $ cd lazyarray-0.5.0
$ python setup.py install
or::
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/lazyarray.py
new/lazyarray-0.5.0/lazyarray.py
--- old/lazyarray-0.3.3/lazyarray.py 2019-05-13 13:48:55.000000000 +0200
+++ new/lazyarray-0.5.0/lazyarray.py 2021-11-09 13:30:33.911081300 +0100
@@ -3,17 +3,17 @@
lazyarray is a Python package that provides a lazily-evaluated numerical array
class, ``larray``, based on and compatible with NumPy arrays.
-Copyright Andrew P. Davison, Jo??l Chavas and Elodie Legou??e (CNRS), 2012-2019
+Copyright Andrew P. Davison, Jo??l Chavas and Elodie Legou??e (CNRS), 2012-2020
"""
-from __future__ import division
-import numpy
+import numbers
import operator
from copy import deepcopy
import collections
-from functools import wraps
+from functools import wraps, reduce
import logging
+import numpy as np
try:
from scipy import sparse
from scipy.sparse import bsr_matrix, coo_matrix, csc_matrix, csr_matrix,
dia_matrix, dok_matrix, lil_matrix
@@ -22,24 +22,7 @@
have_scipy = False
-__version__ = "0.3.3"
-
-# stuff for Python 3 compatibility
-try:
- long
-except NameError:
- long = int
-
-try:
- reduce
-except NameError:
- from functools import reduce
-
-try:
- basestring
-except NameError:
- basestring = str
-
+__version__ = "0.5.0"
logger = logging.getLogger("lazyarray")
@@ -51,7 +34,7 @@
"""
@wraps(meth)
def wrapped_meth(self, val):
- if isinstance(val, (larray, numpy.ndarray)) and val.shape:
+ if isinstance(val, (larray, np.ndarray)) and val.shape:
if val.shape != self._shape:
raise ValueError("shape mismatch: objects cannot be broadcast
to a single shape")
return meth(self, val)
@@ -68,7 +51,7 @@
def full_address(addr, full_shape):
- if not (isinstance(addr, numpy.ndarray) and addr.dtype == bool and
addr.ndim == len(full_shape)):
+ if not (isinstance(addr, np.ndarray) and addr.dtype == bool and addr.ndim
== len(full_shape)):
if not isinstance(addr, tuple):
addr = (addr,)
if len(addr) < len(full_shape):
@@ -84,7 +67,7 @@
Calculate the size of the sub-array represented by `addr`
"""
def size(x, max):
- if isinstance(x, (int, long, numpy.integer)):
+ if isinstance(x, (int, np.integer)):
return None
elif isinstance(x, slice):
y = min(max, x.stop or max) # slice limits can go past the bounds
@@ -98,7 +81,7 @@
raise TypeError("Unsupported index type %s" % type(x))
addr = full_address(addr, full_shape)
- if isinstance(addr, numpy.ndarray) and addr.dtype == bool:
+ if isinstance(addr, np.ndarray) and addr.dtype == bool:
return (addr.sum(),)
elif all(isinstance(x, collections.Sized) for x in addr):
return (len(addr[0]),)
@@ -145,6 +128,25 @@
return op
+def is_array_like(value):
+ # False for numbers, generators, functions, iterators
+ if not isinstance(value, collections.Sized):
+ return False
+ if sparse.issparse(value):
+ return True
+ if isinstance(value, collections.Mapping):
+ # because we may wish to have lazy arrays in which each
+ # item is a dict, for example
+ return False
+ if getattr(value, "is_lazyarray_scalar", False):
+ # for user-defined classes that are "Sized" but that should
+ # be treated as individual elements in a lazy array
+ # the attribute "is_lazyarray_scalar" can be defined with value
+ # True.
+ return False
+ return True
+
+
class larray(object):
"""
@@ -166,7 +168,7 @@
"""
Create a new lazy array.
- `value` : may be an int, long, float, bool, NumPy array, iterator,
+ `value` : may be an int, float, bool, NumPy array, iterator,
generator or a function, `f(i)` or `f(i,j)`, depending on the
dimensions of the array.
@@ -177,7 +179,7 @@
self.dtype = dtype
self.operations = []
- if isinstance(value, basestring):
+ if isinstance(value, str):
raise TypeError("An larray cannot be created from a string")
elif isinstance(value, larray):
if shape is not None and value.shape is not None:
@@ -187,20 +189,23 @@
self.dtype = dtype or value.dtype
self.operations = value.operations # should deepcopy?
- elif isinstance(value, collections.Sized): # False for numbers,
generators, functions, iterators
+ elif is_array_like(value): # False for numbers, generators,
functions, iterators
if have_scipy and sparse.issparse(value): # For sparse matrices
self.dtype = dtype or value.dtype
- elif not isinstance(value, numpy.ndarray):
- value = numpy.array(value, dtype=dtype)
+ elif not isinstance(value, np.ndarray):
+ value = np.array(value, dtype=dtype)
elif dtype is not None:
- assert numpy.can_cast(value.dtype, dtype, casting='safe') # or
could convert value to the provided dtype
- if shape and value.shape != shape:
+ assert np.can_cast(value.dtype, dtype, casting='safe') # or
could convert value to the provided dtype
+ if shape and value.shape and value.shape != shape:
raise ValueError("Array has shape %s, value has shape %s" %
(shape, value.shape))
- self._shape = value.shape
+ if value.shape:
+ self._shape = value.shape
+ else:
+ self._shape = shape
self.base_value = value
else:
- assert numpy.isreal(value) # also True for callables, generators,
iterators
+ assert np.isreal(value) # also True for callables, generators,
iterators
self._shape = shape
if dtype is None or isinstance(value, dtype):
self.base_value = value
@@ -211,7 +216,19 @@
self.base_value = value
def __eq__(self, other):
- return self.base_value == other.base_value and self.operations ==
other.operations and self._shape == other.shape
+ if isinstance(other, self.__class__):
+ return self.base_value == other.base_value and self.operations ==
other.operations and self._shape == other.shape
+ elif isinstance(other, numbers.Number):
+ if len(self.operations) == 0:
+ if isinstance(self.base_value, numbers.Number):
+ return self.base_value == other
+ elif isinstance(self.base_value, np.ndarray):
+ return (self.base_value == other).all()
+ # todo: we could perform the evaluation ourselves, but that could
have a performance hit
+ raise Exception("You will need to evaluate this lazyarray before
checking for equality")
+ else:
+ # todo: add support for NumPy arrays
+ raise TypeError("Cannot at present compare equality of lazyarray
and {}".format(type(other)))
def __deepcopy__(self, memo):
obj = type(self).__new__(type(self))
@@ -226,7 +243,7 @@
obj.dtype = self.dtype
obj.operations = []
for f, arg in self.operations:
- if isinstance(f, numpy.ufunc):
+ if isinstance(f, np.ufunc):
obj.operations.append((f, deepcopy(arg)))
else:
obj.operations.append((deepcopy(f), deepcopy(arg)))
@@ -240,7 +257,7 @@
def _set_shape(self, value):
if (hasattr(self.base_value, "shape") and
- self.base_value.shape and # values of type numpy.float have
an empty shape
+ self.base_value.shape and # values of type np.float have an
empty shape
self.base_value.shape != value):
raise ValueError("Lazy array has fixed shape %s, cannot be changed
to %s" % (self.base_value.shape, value))
self._shape = value
@@ -274,7 +291,7 @@
@property
def is_homogeneous(self):
"""True if all the elements of the array are the same."""
- hom_base = isinstance(self.base_value, (int, long, numpy.integer,
float, bool)) \
+ hom_base = isinstance(self.base_value, (int, np.integer, float, bool))
\
or type(self.base_value) == self.dtype \
or (isinstance(self.dtype, type) and
isinstance(self.base_value, self.dtype))
hom_ops = all(obj.is_homogeneous for f, obj in self.operations if
isinstance(obj, larray))
@@ -289,7 +306,7 @@
def _homogeneous_array(self, addr):
self.check_bounds(addr)
shape = self._partial_shape(addr)
- return numpy.ones(shape, type(self.base_value))
+ return np.ones(shape, type(self.base_value))
def _full_address(self, addr):
return full_address(addr, self._shape)
@@ -298,28 +315,28 @@
self.check_bounds(addr)
def axis_indices(x, max):
- if isinstance(x, (int, long, numpy.integer)):
+ if isinstance(x, (int, np.integer)):
return x
elif isinstance(x, slice): # need to handle negative values in
slice
- return numpy.arange((x.start or 0),
+ return np.arange((x.start or 0),
(x.stop or max),
(x.step or 1),
dtype=int)
elif isinstance(x, collections.Sized):
if hasattr(x, 'dtype') and x.dtype == bool:
- return numpy.arange(max)[x]
+ return np.arange(max)[x]
else:
- return numpy.array(x)
+ return np.array(x)
else:
raise TypeError("Unsupported index type %s" % type(x))
addr = self._full_address(addr)
- if isinstance(addr, numpy.ndarray) and addr.dtype == bool:
+ if isinstance(addr, np.ndarray) and addr.dtype == bool:
if addr.ndim == 1:
- return (numpy.arange(self._shape[0])[addr],)
+ return (np.arange(self._shape[0])[addr],)
else:
raise NotImplementedError()
elif all(isinstance(x, collections.Sized) for x in addr):
- indices = [numpy.array(x) for x in addr]
+ indices = [np.array(x) for x in addr]
return indices
else:
indices = [axis_indices(x, max) for (x, max) in zip(addr,
self._shape)]
@@ -328,7 +345,7 @@
elif len(indices) == 2:
if isinstance(indices[0], collections.Sized):
if isinstance(indices[1], collections.Sized):
- mesh_xy = numpy.meshgrid(*indices)
+ mesh_xy = np.meshgrid(*indices)
return (mesh_xy[0].T, mesh_xy[1].T) # meshgrid works
on (x,y), not (i,j)
return indices
else:
@@ -353,16 +370,16 @@
base_val = self.base_value
else:
base_val = self._homogeneous_array(addr) * self.base_value
- elif isinstance(self.base_value, (int, long, numpy.integer, float,
bool)):
+ elif isinstance(self.base_value, (int, np.integer, float, bool)):
base_val = self._homogeneous_array(addr) * self.base_value
- elif isinstance(self.base_value, numpy.ndarray):
+ elif isinstance(self.base_value, np.ndarray):
base_val = self.base_value[addr]
elif have_scipy and sparse.issparse(self.base_value): # For sparse
matrices larr[2, :]
base_val = self.base_value[addr]
elif callable(self.base_value):
indices = self._array_indices(addr)
base_val = self.base_value(*indices)
- if isinstance(base_val, numpy.ndarray) and base_val.shape == (1,):
+ if isinstance(base_val, np.ndarray) and base_val.shape == (1,):
base_val = base_val[0]
elif hasattr(self.base_value, "lazily_evaluate"):
base_val = self.base_value.lazily_evaluate(addr, shape=self._shape)
@@ -392,7 +409,7 @@
return hasattr(arr, 'dtype') and arr.dtype == bool
def check_axis(x, size):
- if isinstance(x, (int, long, numpy.integer)):
+ if isinstance(x, (int, np.integer)):
lower = upper = x
elif isinstance(x, slice):
lower = x.start or 0
@@ -417,7 +434,7 @@
if (lower < -size) or (upper >= size):
raise IndexError("Index out of bounds")
full_addr = self._full_address(addr)
- if isinstance(addr, numpy.ndarray) and addr.dtype == bool:
+ if isinstance(addr, np.ndarray) and addr.dtype == bool:
if len(addr.shape) > len(self._shape):
raise IndexError("Too many indices for array")
for xmax, size in zip(addr.shape, self._shape):
@@ -434,7 +451,7 @@
where `x` will be a scalar or a numpy array.
>>> m = larray(4, shape=(2,2))
- >>> m.apply(numpy.sqrt)
+ >>> m.apply(np.sqrt)
>>> m.evaluate()
array([[ 2., 2.],
[ 2., 2.]])
@@ -468,13 +485,13 @@
if simplify:
x = self.base_value
else:
- x = self.base_value * numpy.ones(self._shape, dtype=self.dtype)
- elif isinstance(self.base_value, (int, long, numpy.integer, float,
bool, numpy.bool_)):
- x = self.base_value * numpy.ones(self._shape, dtype=self.dtype)
- elif isinstance(self.base_value, numpy.ndarray):
+ x = self.base_value * np.ones(self._shape, dtype=self.dtype)
+ elif isinstance(self.base_value, (int, np.integer, float, bool,
np.bool_)):
+ x = self.base_value * np.ones(self._shape, dtype=self.dtype)
+ elif isinstance(self.base_value, np.ndarray):
x = self.base_value
elif callable(self.base_value):
- x = numpy.array(numpy.fromfunction(self.base_value,
shape=self._shape, dtype=int), dtype=self.dtype)
+ x = np.array(np.fromfunction(self.base_value, shape=self._shape,
dtype=int), dtype=self.dtype)
elif hasattr(self.base_value, "lazily_evaluate"):
x = self.base_value.lazily_evaluate(shape=self._shape)
elif isinstance(self.base_value, VectorizedIterable):
@@ -484,11 +501,11 @@
elif have_scipy and sparse.issparse(self.base_value): # For sparse
matrices
if empty_val!=0:
x = self.base_value.toarray((sparse.csc_matrix))
- x = numpy.where(x, x, numpy.nan)
+ x = np.where(x, x, np.nan)
else:
x = self.base_value.toarray((sparse.csc_matrix))
elif isinstance(self.base_value, collections.Iterator):
- x = numpy.fromiter(self.base_value, dtype=self.dtype or float,
count=self.size)
+ x = np.fromiter(self.base_value, dtype=self.dtype or float,
count=self.size)
if x.shape != self._shape:
x = x.reshape(self._shape)
else:
@@ -537,6 +554,15 @@
__abs__ = lazy_unary_operation('abs')
+class VectorizedIterable(object):
+ """
+ Base class for any class which has a method `next(n)`, i.e., where you
+ can choose how many values to return rather than just returning one at a
+ time.
+ """
+ pass
+
+
def _build_ufunc(func):
"""Return a ufunc that works with lazy arrays"""
def larray_compatible_ufunc(x):
@@ -549,19 +575,28 @@
return larray_compatible_ufunc
-class VectorizedIterable(object):
- """
- Base class for any class which has a method `next(n)`, i.e., where you
- can choose how many values to return rather than just returning one at a
- time.
- """
- pass
+def _build_ufunc_2nd_arg(func):
+ """Return a ufunc taking a second, non-array argument, that works with
lazy arrays"""
+ def larray_compatible_ufunc2(x1, x2):
+ if not isinstance(x2, numbers.Number):
+ raise TypeError("lazyarry ufuncs do not accept an array as the
second argument")
+ if isinstance(x1, larray):
+ def partial(x):
+ return func(x, x2)
+ y = deepcopy(x1)
+ y.apply(partial)
+ return y
+ else:
+ return func(x1, x2)
+ return larray_compatible_ufunc2
# build lazy-array compatible versions of NumPy ufuncs
namespace = globals()
-for name in dir(numpy):
- obj = getattr(numpy, name)
- if isinstance(obj, numpy.ufunc):
- namespace[name] = _build_ufunc(obj)
-
+for name in dir(np):
+ obj = getattr(np, name)
+ if isinstance(obj, np.ufunc) and name not in namespace:
+ if name in ("power", "fmod", "arctan2, hypot, ldexp, maximum,
minimum"):
+ namespace[name] = _build_ufunc_2nd_arg(obj)
+ else:
+ namespace[name] = _build_ufunc(obj)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/setup.py new/lazyarray-0.5.0/setup.py
--- old/lazyarray-0.3.3/setup.py 2019-05-13 13:46:09.000000000 +0200
+++ new/lazyarray-0.5.0/setup.py 2021-11-09 13:30:33.911701700 +0100
@@ -4,11 +4,11 @@
setup(
name='lazyarray',
- version='0.3.3',
+ version='0.5.0',
py_modules=['lazyarray'],
license='Modified BSD',
author="Andrew P. Davison",
- author_email="[email protected]",
+ author_email="[email protected]",
url="http://github.com/NeuralEnsemble/lazyarray/",
description="a Python package that provides a lazily-evaluated numerical
array class, larray, based on and compatible with NumPy arrays.",
long_description=open('README.rst').read(),
@@ -21,7 +21,6 @@
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: OS Independent',
- 'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering',
]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lazyarray-0.3.3/test/test_lazy_arrays_from_Sparse_Matrices.py
new/lazyarray-0.5.0/test/test_lazy_arrays_from_Sparse_Matrices.py
--- old/lazyarray-0.3.3/test/test_lazy_arrays_from_Sparse_Matrices.py
2019-05-13 13:40:11.000000000 +0200
+++ new/lazyarray-0.5.0/test/test_lazy_arrays_from_Sparse_Matrices.py
2021-03-25 15:39:01.584000800 +0100
@@ -1,6 +1,6 @@
-# Support creating lazy arrays from SciPy sparse matrices
+# Support creating lazy arrays from SciPy sparse matrices
#
-# 1 program for the 7 sparse matrices classes :
+# 1 program for the 7 sparse matrices classes :
#
# csc_matrix(arg1[, shape, dtype, copy]) Compressed Sparse
Column matrix
# csr_matrix(arg1[, shape, dtype, copy]) Compressed Sparse
Row matrix
@@ -14,7 +14,7 @@
import numpy as np
from lazyarray import larray
-from scipy import sparse
+from scipy import sparse
import random
@@ -52,14 +52,14 @@
#print "n =", n
#print "p =", p
#print "q =", q
-#print "r =", r
+#print "r =", r
##############################################################
# Definition of an array
##############################################################
-def test_function_array_general():
+def test_function_array_general():
A = np.array([[i, j, k], [l, m, n], [p, q, r]])
#print "A ="
#print A
@@ -112,9 +112,9 @@
#print dia
return dia
-
-if __name__ == "__main__":
+
+if __name__ == "__main__":
##############################################################
@@ -124,10 +124,10 @@
##############################################################
#print "Array general ="
- test_function_array_general()
+ test_function_array_general()
#print "Array ="
#print test_function_array_general()
-
+
# print "----"
# print "Sparse array csc general ="
@@ -174,18 +174,18 @@
#print "----------------------------------------------------------------------"
-
+
##############################################################
# Call the sparse matrices
# Create a lazy array from sparse matrices
##############################################################
-
-
+
+
Array_csc_matrices = sparse_csc_matrices().toarray()
#print "Array csc matrices ="
#print Array_csc_matrices
-
+
Array_csr_matrices = sparse_csr_matrices().toarray()
#print "Array csr matrices ="
#print Array_csr_matrices
@@ -197,7 +197,7 @@
Array_lil_matrices = sparse_lil_matrices().toarray()
#print "Array lil matrices ="
#print Array_lil_matrices
-
+
Array_dok_matrices = sparse_dok_matrices().toarray()
#print "Array dok matrices ="
#print Array_dok_matrices
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/test/test_lazyarray.py
new/lazyarray-0.5.0/test/test_lazyarray.py
--- old/lazyarray-0.3.3/test/test_lazyarray.py 2019-05-13 13:40:11.000000000
+0200
+++ new/lazyarray-0.5.0/test/test_lazyarray.py 2021-03-25 15:39:01.584420000
+0100
@@ -2,12 +2,12 @@
"""
Unit tests for ``larray`` class
-Copyright Andrew P. Davison, Jo??l Chavas and Elodie Legou??e (CNRS), 2012-2017
+Copyright Andrew P. Davison, Jo??l Chavas and Elodie Legou??e (CNRS), 2012-2020
"""
from lazyarray import larray, VectorizedIterable, sqrt, partial_shape
-import numpy
-from nose.tools import assert_raises, assert_equal
+import numpy as np
+from nose.tools import assert_raises, assert_equal, assert_not_equal
from nose import SkipTest
from numpy.testing import assert_array_equal, assert_array_almost_equal
import operator
@@ -25,7 +25,7 @@
def next(self, n):
s = self.start
self.start += n * self.delta
- return s + self.delta * numpy.arange(n)
+ return s + self.delta * np.arange(n)
# test larray
@@ -50,19 +50,19 @@
def test_create_with_list():
A = larray([1, 2, 3], shape=(3,))
assert A.shape == (3,)
- assert_array_equal(A.evaluate(), numpy.array([1, 2, 3]))
+ assert_array_equal(A.evaluate(), np.array([1, 2, 3]))
def test_create_with_array():
- A = larray(numpy.array([1, 2, 3]), shape=(3,))
+ A = larray(np.array([1, 2, 3]), shape=(3,))
assert A.shape == (3,)
- assert_array_equal(A.evaluate(), numpy.array([1, 2, 3]))
+ assert_array_equal(A.evaluate(), np.array([1, 2, 3]))
def test_create_with_array_and_dtype():
- A = larray(numpy.array([1, 2, 3]), shape=(3,), dtype=int)
+ A = larray(np.array([1, 2, 3]), shape=(3,), dtype=int)
assert A.shape == (3,)
- assert_array_equal(A.evaluate(), numpy.array([1, 2, 3]))
+ assert_array_equal(A.evaluate(), np.array([1, 2, 3]))
def test_create_with_generator():
@@ -73,25 +73,25 @@
i += 1
A = larray(plusone(), shape=(5, 11))
assert_array_equal(A.evaluate(),
- numpy.arange(55).reshape((5, 11)))
+ np.arange(55).reshape((5, 11)))
def test_create_with_function1D():
A = larray(lambda i: 99 - i, shape=(3,))
assert_array_equal(A.evaluate(),
- numpy.array([99, 98, 97]))
+ np.array([99, 98, 97]))
def test_create_with_function1D_and_dtype():
A = larray(lambda i: 99 - i, shape=(3,), dtype=float)
assert_array_equal(A.evaluate(),
- numpy.array([99.0, 98.0, 97.0]))
+ np.array([99.0, 98.0, 97.0]))
def test_create_with_function2D():
A = larray(lambda i, j: 3 * j - 2 * i, shape=(2, 3))
assert_array_equal(A.evaluate(),
- numpy.array([[0, 3, 6],
+ np.array([[0, 3, 6],
[-2, 1, 4]]))
@@ -107,23 +107,23 @@
A = 3 + larray(lambda i: 99 - i, shape=(3,))
B = larray(A, shape=(3,), dtype=int)
assert_array_equal(B.evaluate(),
- numpy.array([102, 101, 100]))
+ np.array([102, 101, 100]))
## For sparse matrices
def test_create_with_sparse_array():
- row = numpy.array([0, 2, 2, 0, 1, 2])
- col = numpy.array([0, 0, 1, 2, 2, 2])
- data = numpy.array([1, 2, 3, 4, 5, 6])
+ row = np.array([0, 2, 2, 0, 1, 2])
+ col = np.array([0, 0, 1, 2, 2, 2])
+ data = np.array([1, 2, 3, 4, 5, 6])
bsr = larray(bsr_matrix((data, (row, col)), shape=(3, 3))) # For bsr_matrix
coo = larray(coo_matrix((data, (row, col)), shape=(3, 3))) # For coo_matrix
csc = larray(csc_matrix((data, (row, col)), shape=(3, 3))) # For csc_matrix
csr = larray(csr_matrix((data, (row, col)), shape=(3, 3))) # For csr_matrix
- data_dia = numpy.array([[1, 2, 3, 4]]).repeat(3, axis=0) # For dia_matrix
- offsets_dia = numpy.array([0, -1, 2]) # For dia_matrix
+ data_dia = np.array([[1, 2, 3, 4]]).repeat(3, axis=0) # For dia_matrix
+ offsets_dia = np.array([0, -1, 2]) # For dia_matrix
dia = larray(dia_matrix((data_dia, offsets_dia), shape=(4, 4))) # For
dia_matrix
dok = larray(dok_matrix(((row, col)), shape=(3, 3))) # For dok_matrix
- lil = larray(lil_matrix(data, shape=(3, 3))) # For lil_matrix
+ lil = larray(lil_matrix(data, shape=(3, 3))) # For lil_matrix
assert bsr.shape == (3, 3)
assert coo.shape == (3, 3)
assert csc.shape == (3, 3)
@@ -161,7 +161,7 @@
csr0 = csr /100.0
csr1 = 0.2 + csr0
assert_array_almost_equal(csc0.evaluate(), np.array([[0.01, 0., 0.04],
[0., 0., 0.05], [0.02, 0.03, 0.06]]))
- assert_array_almost_equal(csc0.evaluate(), np.array([[0.21, 0.2,
0.24], [0.2, 0.2, 0.25], [0.22, 0.23, 0.26]]))
+ assert_array_almost_equal(csc0.evaluate(), np.array([[0.21, 0.2,
0.24], [0.2, 0.2, 0.25], [0.22, 0.23, 0.26]]))
# For dia_matrix
dia0 = dia /100.0
dia1 = 0.2 + dia0
@@ -187,7 +187,7 @@
assert_raises(IndexError, dia.__getitem__, (3, 0))
assert_raises(IndexError, dok.__getitem__, (3, 0))
assert_raises(IndexError, lil.__getitem__, (3, 0))
-
+
# def test_columnwise_iteration_with_flat_array():
# m = larray(5, shape=(4,3)) # 4 rows, 3 columns
@@ -195,7 +195,7 @@
# assert_equal(cols, [5, 5, 5])
#
# def test_columnwise_iteration_with_structured_array():
-# input = numpy.arange(12).reshape((4,3))
+# input = np.arange(12).reshape((4,3))
# m = larray(input, shape=(4,3)) # 4 rows, 3 columns
# cols = [col for col in m.by_column()]
# assert_array_equal(cols[0], input[:,0])
@@ -205,20 +205,20 @@
# input = lambda i,j: 2*i + j
# m = larray(input, shape=(4,3))
# cols = [col for col in m.by_column()]
-# assert_array_equal(cols[0], numpy.array([0, 2, 4, 6]))
-# assert_array_equal(cols[1], numpy.array([1, 3, 5, 7]))
-# assert_array_equal(cols[2], numpy.array([2, 4, 6, 8]))
+# assert_array_equal(cols[0], np.array([0, 2, 4, 6]))
+# assert_array_equal(cols[1], np.array([1, 3, 5, 7]))
+# assert_array_equal(cols[2], np.array([2, 4, 6, 8]))
#
# def test_columnwise_iteration_with_flat_array_and_mask():
# m = larray(5, shape=(4,3)) # 4 rows, 3 columns
-# mask = numpy.array([True, False, True])
+# mask = np.array([True, False, True])
# cols = [col for col in m.by_column(mask=mask)]
# assert_equal(cols, [5, 5])
#
# def test_columnwise_iteration_with_structured_array_and_mask():
-# input = numpy.arange(12).reshape((4,3))
+# input = np.arange(12).reshape((4,3))
# m = larray(input, shape=(4,3)) # 4 rows, 3 columns
-# mask = numpy.array([False, True, True])
+# mask = np.array([False, True, True])
# cols = [col for col in m.by_column(mask=mask)]
# assert_array_equal(cols[0], input[:,1])
# assert_array_equal(cols[1], input[:,2])
@@ -241,11 +241,11 @@
def test_evaluate_with_flat_array():
m = larray(5, shape=(4, 3))
- assert_array_equal(m.evaluate(), 5 * numpy.ones((4, 3)))
+ assert_array_equal(m.evaluate(), 5 * np.ones((4, 3)))
def test_evaluate_with_structured_array():
- input = numpy.arange(12).reshape((4, 3))
+ input = np.arange(12).reshape((4, 3))
m = larray(input, shape=(4, 3))
assert_array_equal(m.evaluate(), input)
@@ -254,7 +254,7 @@
input = lambda i, j: 2 * i + j
m = larray(input, shape=(4, 3))
assert_array_equal(m.evaluate(),
- numpy.array([[0, 1, 2],
+ np.array([[0, 1, 2],
[2, 3, 4],
[4, 5, 6],
[6, 7, 8]]))
@@ -264,7 +264,7 @@
input = MockRNG(0, 1)
m = larray(input, shape=(7, 3))
assert_array_equal(m.evaluate(),
- numpy.arange(21).reshape((7, 3)))
+ np.arange(21).reshape((7, 3)))
def test_evaluate_twice_with_vectorized_iterable():
@@ -272,9 +272,9 @@
m1 = larray(input, shape=(7, 3)) + 3
m2 = larray(input, shape=(7, 3)) + 17
assert_array_equal(m1.evaluate(),
- numpy.arange(3, 24).reshape((7, 3)))
+ np.arange(3, 24).reshape((7, 3)))
assert_array_equal(m2.evaluate(),
- numpy.arange(38, 59).reshape((7, 3)))
+ np.arange(38, 59).reshape((7, 3)))
def test_evaluate_structured_array_size_1_simplify():
@@ -287,7 +287,7 @@
def test_iadd_with_flat_array():
m = larray(5, shape=(4, 3))
m += 2
- assert_array_equal(m.evaluate(), 7 * numpy.ones((4, 3)))
+ assert_array_equal(m.evaluate(), 7 * np.ones((4, 3)))
assert_equal(m.base_value, 5)
assert_equal(m.evaluate(simplify=True), 7)
@@ -307,43 +307,43 @@
def test_lt_with_structured_array():
- input = numpy.arange(12).reshape((4, 3))
+ input = np.arange(12).reshape((4, 3))
m0 = larray(input, shape=(4, 3))
m1 = m0 < 5
assert_array_equal(m1.evaluate(simplify=True), input < 5)
def test_structured_array_lt_array():
- input = numpy.arange(12).reshape((4, 3))
+ input = np.arange(12).reshape((4, 3))
m0 = larray(input, shape=(4, 3))
- comparison = 5 * numpy.ones((4, 3))
+ comparison = 5 * np.ones((4, 3))
m1 = m0 < comparison
assert_array_equal(m1.evaluate(simplify=True), input < comparison)
def test_rsub_with_structured_array():
- m = larray(numpy.arange(12).reshape((4, 3)))
+ m = larray(np.arange(12).reshape((4, 3)))
assert_array_equal((11 - m).evaluate(),
- numpy.arange(11, -1, -1).reshape((4, 3)))
+ np.arange(11, -1, -1).reshape((4, 3)))
def test_inplace_mul_with_structured_array():
m = larray((3 * x for x in range(4)), shape=(4,))
m *= 7
assert_array_equal(m.evaluate(),
- numpy.arange(0, 84, 21))
+ np.arange(0, 84, 21))
def test_abs_with_structured_array():
m = larray(lambda i, j: i - j, shape=(3, 4))
assert_array_equal(abs(m).evaluate(),
- numpy.array([[0, 1, 2, 3],
+ np.array([[0, 1, 2, 3],
[1, 0, 1, 2],
[2, 1, 0, 1]]))
def test_multiple_operations_with_structured_array():
- input = numpy.arange(12).reshape((4, 3))
+ input = np.arange(12).reshape((4, 3))
m0 = larray(input, shape=(4, 3))
m1 = (m0 + 2) < 5
m2 = (m0 < 5) + 2
@@ -356,16 +356,16 @@
m = larray(lambda i: i, shape=(5,))
m0 = m / 100.0
m1 = 0.2 + m0
- assert_array_almost_equal(m0.evaluate(), numpy.array([0.0, 0.01, 0.02,
0.03, 0.04]), decimal=12)
- assert_array_almost_equal(m1.evaluate(), numpy.array([0.20, 0.21, 0.22,
0.23, 0.24]), decimal=12)
+ assert_array_almost_equal(m0.evaluate(), np.array([0.0, 0.01, 0.02, 0.03,
0.04]), decimal=12)
+ assert_array_almost_equal(m1.evaluate(), np.array([0.20, 0.21, 0.22, 0.23,
0.24]), decimal=12)
assert_equal(m1[0], 0.2)
def test_operations_combining_constant_and_structured_arrays():
m0 = larray(10, shape=(5,))
- m1 = larray(numpy.arange(5))
+ m1 = larray(np.arange(5))
m2 = m0 + m1
- assert_array_almost_equal(m2.evaluate(), numpy.arange(10, 15))
+ assert_array_almost_equal(m2.evaluate(), np.arange(10, 15))
def test_apply_function_to_constant_array():
@@ -381,7 +381,7 @@
def test_apply_function_to_structured_array():
f = lambda m: 2 * m + 3
- input = numpy.arange(12).reshape((4, 3))
+ input = np.arange(12).reshape((4, 3))
m0 = larray(input, shape=(4, 3))
m1 = f(m0)
assert isinstance(m1, larray)
@@ -394,7 +394,7 @@
f = lambda m: 2 * m + 3
m1 = f(m0)
assert_array_equal(m1.evaluate(),
- numpy.array([[3, 5, 7],
+ np.array([[3, 5, 7],
[7, 9, 11],
[11, 13, 15],
[15, 17, 19]]))
@@ -432,7 +432,7 @@
def test_getitem__with_slice_from_constant_array():
m = larray(3, shape=(4, 3))
assert_array_equal(m[:3, 0],
- numpy.array([3, 3, 3]))
+ np.array([3, 3, 3]))
def test_getitem__with_thinslice_from_constant_array():
@@ -443,31 +443,31 @@
def test_getitem__with_mask_from_constant_array():
m = larray(3, shape=(4, 3))
assert_array_equal(m[1, (0, 2)],
- numpy.array([3, 3]))
+ np.array([3, 3]))
def test_getitem_with_numpy_integers_from_2D_constant_array():
- if not hasattr(numpy, "int64"):
+ if not hasattr(np, "int64"):
raise SkipTest("test requires a 64-bit system")
m = larray(3, shape=(4, 3))
- assert m[numpy.int64(0), numpy.int32(0)] == 3
+ assert m[np.int64(0), np.int32(0)] == 3
def test_getslice_from_constant_array():
m = larray(3, shape=(4, 3))
assert_array_equal(m[:2],
- numpy.array([[3, 3, 3],
+ np.array([[3, 3, 3],
[3, 3, 3]]))
def test_getslice_past_bounds_from_constant_array():
m = larray(3, shape=(5,))
assert_array_equal(m[2:10],
- numpy.array([3, 3, 3]))
+ np.array([3, 3, 3]))
def test_getitem_from_structured_array():
- m = larray(3 * numpy.ones((4, 3)), shape=(4, 3))
+ m = larray(3 * np.ones((4, 3)), shape=(4, 3))
assert m[0, 0] == m[3, 2] == m[-1, 2] == m[-4, 2] == m[2, -3] == 3
assert_raises(IndexError, m.__getitem__, (4, 0))
assert_raises(IndexError, m.__getitem__, (2, -4))
@@ -492,7 +492,7 @@
input = MockRNG(0, 1)
m = larray(input, shape=(7,))
m3 = m[3]
- assert isinstance(m3, (int, numpy.integer))
+ assert isinstance(m3, (int, np.integer))
assert_equal(m3, 0)
assert_equal(m[0], 1)
@@ -500,7 +500,7 @@
def test_getitem_with_slice_from_2D_functional_array():
m = larray(lambda i, j: 2 * i + j, shape=(6, 5))
assert_array_equal(m[2:5, 3:],
- numpy.array([[7, 8],
+ np.array([[7, 8],
[9, 10],
[11, 12]]))
@@ -510,34 +510,34 @@
return i * i + 2 * i * j + 3
m = larray(test_function, shape=(3, 15))
assert_array_equal(m[:, 3:14:3],
- numpy.fromfunction(test_function, shape=(3, 15))[:,
3:14:3])
+ np.fromfunction(test_function, shape=(3, 15))[:,
3:14:3])
def test_getitem_with_mask_from_2D_functional_array():
- a = numpy.arange(30).reshape((6, 5))
+ a = np.arange(30).reshape((6, 5))
m = larray(lambda i, j: 5 * i + j, shape=(6, 5))
assert_array_equal(a[[2, 3], [3, 4]],
- numpy.array([13, 19]))
+ np.array([13, 19]))
assert_array_equal(m[[2, 3], [3, 4]],
- numpy.array([13, 19]))
+ np.array([13, 19]))
def test_getitem_with_mask_from_1D_functional_array():
- m = larray(lambda i: numpy.sqrt(i), shape=(10,))
+ m = larray(lambda i: np.sqrt(i), shape=(10,))
assert_array_equal(m[[0, 1, 4, 9]],
- numpy.array([0, 1, 2, 3]))
+ np.array([0, 1, 2, 3]))
def test_getitem_with_boolean_mask_from_1D_functional_array():
- m = larray(lambda i: numpy.sqrt(i), shape=(10,))
- assert_array_equal(m[numpy.array([1, 1, 0, 0, 1, 0, 0, 0, 0, 1],
dtype=bool)],
- numpy.array([0, 1, 2, 3]))
+ m = larray(lambda i: np.sqrt(i), shape=(10,))
+ assert_array_equal(m[np.array([1, 1, 0, 0, 1, 0, 0, 0, 0, 1], dtype=bool)],
+ np.array([0, 1, 2, 3]))
def test_getslice_from_2D_functional_array():
m = larray(lambda i, j: 2 * i + j, shape=(6, 5))
assert_array_equal(m[1:3],
- numpy.array([[2, 3, 4, 5, 6],
+ np.array([[2, 3, 4, 5, 6],
[4, 5, 6, 7, 8]]))
@@ -547,10 +547,10 @@
def test_getitem_from_array_with_operations():
- a1 = numpy.array([[1, 3, 5], [7, 9, 11]])
+ a1 = np.array([[1, 3, 5], [7, 9, 11]])
m1 = larray(a1)
- f = lambda i, j: numpy.sqrt(i * i + j * j)
- a2 = numpy.fromfunction(f, shape=(2, 3))
+ f = lambda i, j: np.sqrt(i * i + j * j)
+ a2 = np.fromfunction(f, shape=(2, 3))
m2 = larray(f, shape=(2, 3))
a3 = 3 * a1 + a2
m3 = 3 * m1 + m2
@@ -582,11 +582,11 @@
def test_partially_evaluate_constant_array_with_one_element():
m = larray(3, shape=(1,))
- a = 3 * numpy.ones((1,))
+ a = 3 * np.ones((1,))
m1 = larray(3, shape=(1, 1))
- a1 = 3 * numpy.ones((1, 1))
+ a1 = 3 * np.ones((1, 1))
m2 = larray(3, shape=(1, 1, 1))
- a2 = 3 * numpy.ones((1, 1, 1))
+ a2 = 3 * np.ones((1, 1, 1))
assert_equal(a[0], m[0])
assert_equal(a.shape, m.shape)
assert_equal(a[:].shape, m[:].shape)
@@ -603,9 +603,9 @@
def test_partially_evaluate_constant_array_with_boolean_index():
m = larray(3, shape=(4, 5))
- a = 3 * numpy.ones((4, 5))
- addr_bool = numpy.array([True, True, False, False, True])
- addr_int = numpy.array([0, 1, 4])
+ a = 3 * np.ones((4, 5))
+ addr_bool = np.array([True, True, False, False, True])
+ addr_int = np.array([0, 1, 4])
assert_equal(a[::2, addr_bool].shape, a[::2, addr_int].shape)
assert_equal(a[::2, addr_int].shape, m[::2, addr_int].shape)
assert_equal(a[::2, addr_bool].shape, m[::2, addr_bool].shape)
@@ -613,37 +613,37 @@
def test_partially_evaluate_constant_array_with_all_boolean_indices_false():
m = larray(3, shape=(3,))
- a = 3 * numpy.ones((3,))
- addr_bool = numpy.array([False, False, False])
+ a = 3 * np.ones((3,))
+ addr_bool = np.array([False, False, False])
assert_equal(a[addr_bool].shape, m[addr_bool].shape)
def test_partially_evaluate_constant_array_with_only_one_boolean_indice_true():
m = larray(3, shape=(3,))
- a = 3 * numpy.ones((3,))
- addr_bool = numpy.array([False, True, False])
+ a = 3 * np.ones((3,))
+ addr_bool = np.array([False, True, False])
assert_equal(a[addr_bool].shape, m[addr_bool].shape)
assert_equal(m[addr_bool][0], a[0])
def
test_partially_evaluate_constant_array_with_boolean_indice_as_random_valid_ndarray():
m = larray(3, shape=(3,))
- a = 3 * numpy.ones((3,))
- addr_bool = numpy.random.rand(3) > 0.5
+ a = 3 * np.ones((3,))
+ addr_bool = np.random.rand(3) > 0.5
while not addr_bool.any():
# random array, but not [False, False, False]
- addr_bool = numpy.random.rand(3) > 0.5
+ addr_bool = np.random.rand(3) > 0.5
assert_equal(a[addr_bool].shape, m[addr_bool].shape)
assert_equal(m[addr_bool][0], a[addr_bool][0])
def test_partially_evaluate_constant_array_size_one_with_boolean_index_true():
m = larray(3, shape=(1,))
- a = numpy.array([3])
- addr_bool = numpy.array([True])
+ a = np.array([3])
+ addr_bool = np.array([True])
m1 = larray(3, shape=(1, 1))
- a1 = 3 * numpy.ones((1, 1))
- addr_bool1 = numpy.array([[True]], ndmin=2)
+ a1 = 3 * np.ones((1, 1))
+ addr_bool1 = np.array([[True]], ndmin=2)
assert_equal(m[addr_bool][0], a[0])
assert_equal(m[addr_bool], a[addr_bool])
assert_equal(m[addr_bool].shape, a[addr_bool].shape)
@@ -653,8 +653,8 @@
def test_partially_evaluate_constant_array_size_two_with_boolean_index_true():
m2 = larray(3, shape=(1, 2))
- a2 = 3 * numpy.ones((1, 2))
- addr_bool2 = numpy.ones((1, 2), dtype=bool)
+ a2 = 3 * np.ones((1, 2))
+ addr_bool2 = np.ones((1, 2), dtype=bool)
assert_equal(m2[addr_bool2][0], a2[addr_bool2][0])
assert_equal(m2[addr_bool2].shape, a2[addr_bool2].shape)
@@ -662,28 +662,28 @@
def test_partially_evaluate_constant_array_size_one_with_boolean_index_false():
m = larray(3, shape=(1,))
m1 = larray(3, shape=(1, 1))
- a = numpy.array([3])
- a1 = numpy.array([[3]], ndmin=2)
- addr_bool = numpy.array([False])
- addr_bool1 = numpy.array([[False]], ndmin=2)
- addr_bool2 = numpy.array([False])
+ a = np.array([3])
+ a1 = np.array([[3]], ndmin=2)
+ addr_bool = np.array([False])
+ addr_bool1 = np.array([[False]], ndmin=2)
+ addr_bool2 = np.array([False])
assert_equal(m[addr_bool].shape, a[addr_bool].shape)
assert_equal(m1[addr_bool1].shape, a1[addr_bool1].shape)
def test_partially_evaluate_constant_array_size_with_empty_boolean_index():
m = larray(3, shape=(1,))
- a = numpy.array([3])
- addr_bool = numpy.array([], dtype='bool')
+ a = np.array([3])
+ addr_bool = np.array([], dtype='bool')
assert_equal(m[addr_bool].shape, a[addr_bool].shape)
assert_equal(m[addr_bool].shape, (0,))
def test_partially_evaluate_functional_array_with_boolean_index():
m = larray(lambda i, j: 5 * i + j, shape=(4, 5))
- a = numpy.arange(20.0).reshape((4, 5))
- addr_bool = numpy.array([True, True, False, False, True])
- addr_int = numpy.array([0, 1, 4])
+ a = np.arange(20.0).reshape((4, 5))
+ addr_bool = np.array([True, True, False, False, True])
+ addr_int = np.array([0, 1, 4])
assert_equal(a[::2, addr_bool].shape, a[::2, addr_int].shape)
assert_equal(a[::2, addr_int].shape, m[::2, addr_int].shape)
assert_equal(a[::2, addr_bool].shape, m[::2, addr_bool].shape)
@@ -693,15 +693,32 @@
input = MockRNG(0, 1)
m = larray(input, shape=(7, 3))
assert_array_equal(m[::2, (0, 2)],
- numpy.arange(8).reshape((4, 2)))
+ np.arange(8).reshape((4, 2)))
-def test_equality():
+def test_equality_with_lazyarray():
m1 = larray(42.0, shape=(4, 5)) / 23.0 + 2.0
m2 = larray(42.0, shape=(4, 5)) / 23.0 + 2.0
assert_equal(m1, m2)
+def test_equality_with_number():
+ m1 = larray(42.0, shape=(4, 5))
+ m2 = larray([42, 42, 42])
+ m3 = larray([42, 42, 43])
+ m4 = larray(42.0, shape=(4, 5)) + 2
+ assert_equal(m1, 42.0)
+ assert_equal(m2, 42)
+ assert_not_equal(m3, 42)
+ assert_raises(Exception, m4.__eq__, 44.0)
+
+
+def test_equality_with_array():
+ m1 = larray(42.0, shape=(4, 5))
+ target = 42.0 * np.ones((4, 5))
+ assert_raises(TypeError, m1.__eq__, target)
+
+
def test_deepcopy():
m1 = 3 * larray(lambda i, j: 5 * i + j, shape=(4, 5)) + 2
m2 = deepcopy(m1)
@@ -716,27 +733,27 @@
m1 = sqrt(larray([x ** 2 for x in range(5)]))
m2 = deepcopy(m1)
m1.base_value[0] = 49
- assert_array_equal(m1.evaluate(), numpy.array([7, 1, 2, 3, 4]))
- assert_array_equal(m2.evaluate(), numpy.array([0, 1, 2, 3, 4]))
+ assert_array_equal(m1.evaluate(), np.array([7, 1, 2, 3, 4]))
+ assert_array_equal(m2.evaluate(), np.array([0, 1, 2, 3, 4]))
def test_set_shape():
m = larray(42) + larray(lambda i: 3 * i)
assert_equal(m.shape, None)
m.shape = (5,)
- assert_array_equal(m.evaluate(), numpy.array([42, 45, 48, 51, 54]))
+ assert_array_equal(m.evaluate(), np.array([42, 45, 48, 51, 54]))
def test_call():
- A = larray(numpy.array([1, 2, 3]), shape=(3,)) - 1
+ A = larray(np.array([1, 2, 3]), shape=(3,)) - 1
B = 0.5 * larray(lambda i: 2 * i, shape=(3,))
C = B(A)
- assert_array_equal(C.evaluate(), numpy.array([0, 1, 2]))
- assert_array_equal(A.evaluate(), numpy.array([0, 1, 2])) # A should be
unchanged
+ assert_array_equal(C.evaluate(), np.array([0, 1, 2]))
+ assert_array_equal(A.evaluate(), np.array([0, 1, 2])) # A should be
unchanged
def test_call2():
- positions = numpy.array(
+ positions = np.array(
[[0., 2., 4., 6., 8.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]])
@@ -747,8 +764,8 @@
def distances(A, B):
d = A - B
d **= 2
- d = numpy.sum(d, axis=-1)
- numpy.sqrt(d, d)
+ d = np.sum(d, axis=-1)
+ np.sqrt(d, d)
return d
def distance_generator(f, g):
@@ -760,7 +777,7 @@
f_delay = 1000 * larray(lambda d: 0.1 * (1 + d), shape=(4, 5))
assert_array_almost_equal(
f_delay(distance_map).evaluate(),
- numpy.array([[100, 300, 500, 700, 900],
+ np.array([[100, 300, 500, 700, 900],
[300, 100, 300, 500, 700],
[500, 300, 100, 300, 500],
[700, 500, 300, 100, 300]], dtype=float),
@@ -768,7 +785,7 @@
# repeat, should be idempotent
assert_array_almost_equal(
f_delay(distance_map).evaluate(),
- numpy.array([[100, 300, 500, 700, 900],
+ np.array([[100, 300, 500, 700, 900],
[300, 100, 300, 500, 700],
[500, 300, 100, 300, 500],
[700, 500, 300, 100, 300]], dtype=float),
@@ -777,16 +794,16 @@
def test__issue4():
# In order to avoid the errors associated with version changes of numpy,
mask1 and mask2 no longer contain boolean values ??????but integer values
- a = numpy.arange(12).reshape((4, 3))
- b = larray(numpy.arange(12).reshape((4, 3)))
+ a = np.arange(12).reshape((4, 3))
+ b = larray(np.arange(12).reshape((4, 3)))
mask1 = (slice(None), int(True))
- mask2 = (slice(None), numpy.array([int(True)]))
+ mask2 = (slice(None), np.array([int(True)]))
assert_equal(b[mask1].shape, partial_shape(mask1, b.shape), a[mask1].shape)
assert_equal(b[mask2].shape, partial_shape(mask2, b.shape), a[mask2].shape)
def test__issue3():
- a = numpy.arange(12).reshape((4, 3))
+ a = np.arange(12).reshape((4, 3))
b = larray(a)
c = larray(lambda i, j: 3*i + j, shape=(4, 3))
assert_array_equal(a[(1, 3), :][:, (0, 2)], b[(1, 3), :][:, (0, 2)])
@@ -796,7 +813,7 @@
def test_partial_shape():
- a = numpy.arange(12).reshape((4, 3))
+ a = np.arange(12).reshape((4, 3))
test_cases = [
(slice(None), (4, 3)),
((slice(None), slice(None)), (4, 3)),
@@ -804,27 +821,27 @@
(1, (3,)),
((1, slice(None)), (3,)),
([0, 2, 3], (3, 3)),
- (numpy.array([0, 2, 3]), (3, 3)),
- ((numpy.array([0, 2, 3]), slice(None)), (3, 3)),
- (numpy.array([True, False, True, True]), (3, 3)),
- #(numpy.array([True, False]), (1, 3)), # not valid with NumPy 1.13
- (numpy.array([[True, False, False], [False, False, False], [True,
True, False], [False, True, False]]), (4,)),
- #(numpy.array([[True, False, False], [False, False, False], [True,
True, False]]), (3,)), # not valid with NumPy 1.13
+ (np.array([0, 2, 3]), (3, 3)),
+ ((np.array([0, 2, 3]), slice(None)), (3, 3)),
+ (np.array([True, False, True, True]), (3, 3)),
+ #(np.array([True, False]), (1, 3)), # not valid with NumPy 1.13
+ (np.array([[True, False, False], [False, False, False], [True, True,
False], [False, True, False]]), (4,)),
+ #(np.array([[True, False, False], [False, False, False], [True, True,
False]]), (3,)), # not valid with NumPy 1.13
((3, 1), tuple()),
((slice(None), 1), (4,)),
((slice(None), slice(1, None, 3)), (4, 1)),
- ((numpy.array([0, 3]), 2), (2,)),
- ((numpy.array([0, 3]), numpy.array([1, 2])), (2,)),
- ((slice(None), numpy.array([2])), (4, 1)),
+ ((np.array([0, 3]), 2), (2,)),
+ ((np.array([0, 3]), np.array([1, 2])), (2,)),
+ ((slice(None), np.array([2])), (4, 1)),
(((1, 3), (0, 2)), (2,)),
- (numpy.array([], bool), (0, 3)),
+ (np.array([], bool), (0, 3)),
]
for mask, expected_shape in test_cases:
assert_equal(partial_shape(mask, a.shape), a[mask].shape)
assert_equal(partial_shape(mask, a.shape), expected_shape)
- b = numpy.arange(5)
+ b = np.arange(5)
test_cases = [
- (numpy.arange(5), (5,))
+ (np.arange(5), (5,))
]
for mask, expected_shape in test_cases:
assert_equal(partial_shape(mask, b.shape), b[mask].shape)
@@ -832,7 +849,7 @@
def test_is_homogeneous():
m0 = larray(10, shape=(5,))
- m1 = larray(numpy.arange(1, 6))
+ m1 = larray(np.arange(1, 6))
m2 = m0 + m1
m3 = 9 + m0 / m1
assert m0.is_homogeneous
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lazyarray-0.3.3/test/test_ufunc.py
new/lazyarray-0.5.0/test/test_ufunc.py
--- old/lazyarray-0.3.3/test/test_ufunc.py 2019-05-13 13:40:11.000000000
+0200
+++ new/lazyarray-0.5.0/test/test_ufunc.py 2021-11-09 13:29:27.532858100
+0100
@@ -4,41 +4,59 @@
Copyright Andrew P. Davison, 2012-2017
"""
-from lazyarray import larray, sqrt, cos
-import numpy
+from lazyarray import larray, sqrt, cos, power, fmod
+import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
+from nose.tools import assert_raises
def test_sqrt_from_array():
- A = larray(numpy.array([1, 4, 9, 16, 25]))
+ A = larray(np.array([1, 4, 9, 16, 25]))
assert_array_equal(sqrt(A).evaluate(),
- numpy.arange(1, 6))
+ np.arange(1, 6))
def test_sqrt_from_iterator():
A = larray(iter([1, 4, 9, 16, 25]), shape=(5,))
assert_array_equal(sqrt(A).evaluate(),
- numpy.arange(1, 6))
+ np.arange(1, 6))
def test_sqrt_from_func():
A = larray(lambda x: (x + 1) ** 2, shape=(5,))
assert_array_equal(sqrt(A).evaluate(),
- numpy.arange(1, 6))
+ np.arange(1, 6))
def test_sqrt_normal_array():
- A = numpy.array([1, 4, 9, 16, 25])
+ A = np.array([1, 4, 9, 16, 25])
assert_array_equal(sqrt(A),
- numpy.arange(1, 6))
+ np.arange(1, 6))
def test_cos_from_generator():
def clock():
- for x in numpy.arange(0, 2 * numpy.pi, numpy.pi / 2):
+ for x in np.arange(0, 2 * np.pi, np.pi / 2):
yield x
A = larray(clock(), shape=(2, 2))
assert_array_almost_equal(cos(A).evaluate(),
- numpy.array([[1.0, 0.0],
+ np.array([[1.0, 0.0],
[-1.0, 0.0]]),
decimal=15)
+
+
+def test_power_from_array():
+ A = larray(np.array([1, 4, 9, 16, 25]))
+ assert_array_equal(power(A, 0.5).evaluate(),
+ np.arange(1, 6))
+
+
+def test_power_with_plain_array():
+ A = np.array([1, 4, 9, 16, 25])
+ assert_array_equal(power(A, 0.5), np.arange(1, 6))
+
+
+def test_fmod_with_array_as_2nd_arg():
+ A = larray(np.array([1, 4, 9, 16, 25]))
+ B = larray(np.array([1, 4, 9, 16, 25]))
+ assert_raises(TypeError, fmod, A, B)
++++++ use-pytest.patch ++++++
>From 69b649519a19eececd738abfa8e879a5d6e09f5d Mon Sep 17 00:00:00 2001
From: "Ankur Sinha (Ankur Sinha Gmail)" <[email protected]>
Date: Sat, 22 May 2021 15:40:03 +0100
Subject: [PATCH 1/2] fix(tests): use pytest
nose is deprecated upstream (the last commit was in 2016.) and is also being
deprecated in Fedora.
https://github.com/nose-devs/nose/commits/master
The nose website says:
https://nose.readthedocs.io/en/latest/
"Nose has been in maintenance mode for the past several years and will likely
cease without a new person/team to take over maintainership. New projects
should consider using Nose2, py.test, or just plain unittest/unittest2."
Deprecation of nose in Fedora:
https://fedoraproject.org/wiki/Changes/DeprecateNose
---
test/test_lazyarray.py | 203 ++++++++++++++++++++---------------------
1 file changed, 101 insertions(+), 102 deletions(-)
Index: lazyarray-0.5.0/test/test_lazyarray.py
===================================================================
--- lazyarray-0.5.0.orig/test/test_lazyarray.py
+++ lazyarray-0.5.0/test/test_lazyarray.py
@@ -7,11 +7,10 @@ Copyright Andrew P. Davison, Jo??l Chava
from lazyarray import larray, VectorizedIterable, sqrt, partial_shape
import numpy as np
-from nose.tools import assert_raises, assert_equal, assert_not_equal
-from nose import SkipTest
from numpy.testing import assert_array_equal, assert_array_almost_equal
import operator
from copy import deepcopy
+import pytest
from scipy.sparse import bsr_matrix, coo_matrix, csc_matrix, csr_matrix,
dia_matrix, dok_matrix, lil_matrix
@@ -96,11 +95,11 @@ def test_create_with_function2D():
def test_create_inconsistent():
- assert_raises(ValueError, larray, [1, 2, 3], shape=4)
+ pytest.raises(ValueError, larray, [1, 2, 3], shape=4)
def test_create_with_string():
- assert_raises(TypeError, larray, "123", shape=3)
+ pytest.raises(TypeError, larray, "123", shape=3)
def test_create_with_larray():
@@ -180,19 +179,19 @@ def test_create_with_sparse_array():
def test_getitem_from_2D_sparse_array():
- assert_raises(IndexError, bsr.__getitem__, (3, 0))
- assert_raises(IndexError, coo.__getitem__, (3, 0))
- assert_raises(IndexError, csc.__getitem__, (3, 0))
- assert_raises(IndexError, csr.__getitem__, (3, 0))
- assert_raises(IndexError, dia.__getitem__, (3, 0))
- assert_raises(IndexError, dok.__getitem__, (3, 0))
- assert_raises(IndexError, lil.__getitem__, (3, 0))
+ pytest.raises(IndexError, bsr.__getitem__, (3, 0))
+ pytest.raises(IndexError, coo.__getitem__, (3, 0))
+ pytest.raises(IndexError, csc.__getitem__, (3, 0))
+ pytest.raises(IndexError, csr.__getitem__, (3, 0))
+ pytest.raises(IndexError, dia.__getitem__, (3, 0))
+ pytest.raises(IndexError, dok.__getitem__, (3, 0))
+ pytest.raises(IndexError, lil.__getitem__, (3, 0))
# def test_columnwise_iteration_with_flat_array():
# m = larray(5, shape=(4,3)) # 4 rows, 3 columns
# cols = [col for col in m.by_column()]
-# assert_equal(cols, [5, 5, 5])
+# assert cols == [5, 5, 5]
#
# def test_columnwise_iteration_with_structured_array():
# input = np.arange(12).reshape((4,3))
@@ -213,7 +212,7 @@ def test_create_with_sparse_array():
# m = larray(5, shape=(4,3)) # 4 rows, 3 columns
# mask = np.array([True, False, True])
# cols = [col for col in m.by_column(mask=mask)]
-# assert_equal(cols, [5, 5])
+# assert cols == [5, 5]
#
# def test_columnwise_iteration_with_structured_array_and_mask():
# input = np.arange(12).reshape((4,3))
@@ -228,15 +227,15 @@ def test_size_related_properties():
m1 = larray(1, shape=(9, 7))
m2 = larray(1, shape=(13,))
m3 = larray(1)
- assert_equal(m1.nrows, 9)
- assert_equal(m1.ncols, 7)
- assert_equal(m1.size, 63)
- assert_equal(m2.nrows, 13)
- assert_equal(m2.ncols, 1)
- assert_equal(m2.size, 13)
- assert_raises(ValueError, lambda: m3.nrows)
- assert_raises(ValueError, lambda: m3.ncols)
- assert_raises(ValueError, lambda: m3.size)
+ assert m1.nrows == 9
+ assert m1.ncols == 7
+ assert m1.size == 63
+ assert m2.nrows == 13
+ assert m2.ncols == 1
+ assert m2.size == 13
+ pytest.raises(ValueError, lambda: m3.nrows)
+ pytest.raises(ValueError, lambda: m3.ncols)
+ pytest.raises(ValueError, lambda: m3.size)
def test_evaluate_with_flat_array():
@@ -279,31 +278,31 @@ def test_evaluate_twice_with_vectorized_
def test_evaluate_structured_array_size_1_simplify():
m = larray([5.0], shape=(1,))
- assert_equal(m.evaluate(simplify=True), 5.0)
+ assert m.evaluate(simplify=True) == 5.0
n = larray([2.0], shape=(1,))
- assert_equal((m/n).evaluate(simplify=True), 2.5)
+ assert (m/n).evaluate(simplify=True) == 2.5
def test_iadd_with_flat_array():
m = larray(5, shape=(4, 3))
m += 2
assert_array_equal(m.evaluate(), 7 * np.ones((4, 3)))
- assert_equal(m.base_value, 5)
- assert_equal(m.evaluate(simplify=True), 7)
+ assert m.base_value == 5
+ assert m.evaluate(simplify=True) == 7
def test_add_with_flat_array():
m0 = larray(5, shape=(4, 3))
m1 = m0 + 2
- assert_equal(m1.evaluate(simplify=True), 7)
- assert_equal(m0.evaluate(simplify=True), 5)
+ assert m1.evaluate(simplify=True) == 7
+ assert m0.evaluate(simplify=True) == 5
def test_lt_with_flat_array():
m0 = larray(5, shape=(4, 3))
m1 = m0 < 10
- assert_equal(m1.evaluate(simplify=True), True)
- assert_equal(m0.evaluate(simplify=True), 5)
+ assert m1.evaluate(simplify=True) is True
+ assert m0.evaluate(simplify=True) == 5
def test_lt_with_structured_array():
@@ -358,7 +357,7 @@ def test_multiple_operations_with_functi
m1 = 0.2 + m0
assert_array_almost_equal(m0.evaluate(), np.array([0.0, 0.01, 0.02, 0.03,
0.04]), decimal=12)
assert_array_almost_equal(m1.evaluate(), np.array([0.20, 0.21, 0.22, 0.23,
0.24]), decimal=12)
- assert_equal(m1[0], 0.2)
+ assert m1[0] == 0.2
def test_operations_combining_constant_and_structured_arrays():
@@ -373,10 +372,10 @@ def test_apply_function_to_constant_arra
m0 = larray(5, shape=(4, 3))
m1 = f(m0)
assert isinstance(m1, larray)
- assert_equal(m1.evaluate(simplify=True), 13)
+ assert m1.evaluate(simplify=True) == 13
# the following tests the internals, not the behaviour
# it is just to check I understand what's going on
- assert_equal(m1.operations, [(operator.mul, 2), (operator.add, 3)])
+ assert m1.operations == [(operator.mul, 2), (operator.add, 3)]
def test_apply_function_to_structured_array():
@@ -404,24 +403,24 @@ def test_add_two_constant_arrays():
m0 = larray(5, shape=(4, 3))
m1 = larray(7, shape=(4, 3))
m2 = m0 + m1
- assert_equal(m2.evaluate(simplify=True), 12)
+ assert m2.evaluate(simplify=True) == 12
# the following tests the internals, not the behaviour
# it is just to check I understand what's going on
- assert_equal(m2.base_value, m0.base_value)
- assert_equal(m2.operations, [(operator.add, m1)])
+ assert m2.base_value == m0.base_value
+ assert m2.operations == [(operator.add, m1)]
def test_add_incommensurate_arrays():
m0 = larray(5, shape=(4, 3))
m1 = larray(7, shape=(5, 3))
- assert_raises(ValueError, m0.__add__, m1)
+ pytest.raises(ValueError, m0.__add__, m1)
def test_getitem_from_2D_constant_array():
m = larray(3, shape=(4, 3))
assert m[0, 0] == m[3, 2] == m[-1, 2] == m[-4, 2] == m[2, -3] == 3
- assert_raises(IndexError, m.__getitem__, (4, 0))
- assert_raises(IndexError, m.__getitem__, (2, -4))
+ pytest.raises(IndexError, m.__getitem__, (4, 0))
+ pytest.raises(IndexError, m.__getitem__, (2, -4))
def test_getitem_from_1D_constant_array():
@@ -437,7 +436,7 @@ def test_getitem__with_slice_from_consta
def test_getitem__with_thinslice_from_constant_array():
m = larray(3, shape=(4, 3))
- assert_equal(m[2:3, 0:1], 3)
+ assert m[2:3, 0:1] == 3
def test_getitem__with_mask_from_constant_array():
@@ -448,7 +447,7 @@ def test_getitem__with_mask_from_constan
def test_getitem_with_numpy_integers_from_2D_constant_array():
if not hasattr(np, "int64"):
- raise SkipTest("test requires a 64-bit system")
+ pytest.skip("test requires a 64-bit system")
m = larray(3, shape=(4, 3))
assert m[np.int64(0), np.int32(0)] == 3
@@ -469,23 +468,23 @@ def test_getslice_past_bounds_from_const
def test_getitem_from_structured_array():
m = larray(3 * np.ones((4, 3)), shape=(4, 3))
assert m[0, 0] == m[3, 2] == m[-1, 2] == m[-4, 2] == m[2, -3] == 3
- assert_raises(IndexError, m.__getitem__, (4, 0))
- assert_raises(IndexError, m.__getitem__, (2, -4))
+ pytest.raises(IndexError, m.__getitem__, (4, 0))
+ pytest.raises(IndexError, m.__getitem__, (2, -4))
def test_getitem_from_2D_functional_array():
m = larray(lambda i, j: 2 * i + j, shape=(6, 5))
- assert_equal(m[5, 4], 14)
+ assert m[5, 4] == 14
def test_getitem_from_1D_functional_array():
m = larray(lambda i: i ** 3, shape=(6,))
- assert_equal(m[5], 125)
+ assert m[5] == 125
def test_getitem_from_3D_functional_array():
m = larray(lambda i, j, k: i + j + k, shape=(2, 3, 4))
- assert_raises(NotImplementedError, m.__getitem__, (0, 1, 2))
+ pytest.raises(NotImplementedError, m.__getitem__, (0, 1, 2))
def test_getitem_from_vectorized_iterable():
@@ -493,8 +492,8 @@ def test_getitem_from_vectorized_iterabl
m = larray(input, shape=(7,))
m3 = m[3]
assert isinstance(m3, (int, np.integer))
- assert_equal(m3, 0)
- assert_equal(m[0], 1)
+ assert m3 == 0
+ assert m[0] == 1
def test_getitem_with_slice_from_2D_functional_array():
@@ -543,7 +542,7 @@ def test_getslice_from_2D_functional_arr
def test_getitem_from_iterator_array():
m = larray(iter([1, 2, 3]), shape=(3,))
- assert_raises(NotImplementedError, m.__getitem__, 2)
+ pytest.raises(NotImplementedError, m.__getitem__, 2)
def test_getitem_from_array_with_operations():
@@ -561,23 +560,23 @@ def test_getitem_from_array_with_operati
def test_evaluate_with_invalid_base_value():
m = larray(range(5))
m.base_value = "foo"
- assert_raises(ValueError, m.evaluate)
+ pytest.raises(ValueError, m.evaluate)
def test_partially_evaluate_with_invalid_base_value():
m = larray(range(5))
m.base_value = "foo"
- assert_raises(ValueError, m._partially_evaluate, 3)
+ pytest.raises(ValueError, m._partially_evaluate, 3)
def test_check_bounds_with_invalid_address():
m = larray([[1, 3, 5], [7, 9, 11]])
- assert_raises(TypeError, m.check_bounds, (object(), 1))
+ pytest.raises(TypeError, m.check_bounds, (object(), 1))
def test_check_bounds_with_invalid_address2():
m = larray([[1, 3, 5], [7, 9, 11]])
- assert_raises(ValueError, m.check_bounds, ([], 1))
+ pytest.raises(ValueError, m.check_bounds, ([], 1))
def test_partially_evaluate_constant_array_with_one_element():
@@ -587,18 +586,18 @@ def test_partially_evaluate_constant_arr
a1 = 3 * np.ones((1, 1))
m2 = larray(3, shape=(1, 1, 1))
a2 = 3 * np.ones((1, 1, 1))
- assert_equal(a[0], m[0])
- assert_equal(a.shape, m.shape)
- assert_equal(a[:].shape, m[:].shape)
- assert_equal(a, m.evaluate())
- assert_equal(a1.shape, m1.shape)
- assert_equal(a1[0,:].shape, m1[0,:].shape)
- assert_equal(a1[:].shape, m1[:].shape)
- assert_equal(a1, m1.evaluate())
- assert_equal(a2.shape, m2.shape)
- assert_equal(a2[:, 0,:].shape, m2[:, 0,:].shape)
- assert_equal(a2[:].shape, m2[:].shape)
- assert_equal(a2, m2.evaluate())
+ assert a[0] == m[0]
+ assert a.shape == m.shape
+ assert a[:].shape == m[:].shape
+ assert a == m.evaluate()
+ assert a1.shape == m1.shape
+ assert a1[0, :].shape == m1[0, :].shape
+ assert a1[:].shape == m1[:].shape
+ assert a1 == m1.evaluate()
+ assert a2.shape == m2.shape
+ assert a2[:, 0, :].shape == m2[:, 0, :].shape
+ assert a2[:].shape == m2[:].shape
+ assert a2 == m2.evaluate()
def test_partially_evaluate_constant_array_with_boolean_index():
@@ -606,24 +605,24 @@ def test_partially_evaluate_constant_arr
a = 3 * np.ones((4, 5))
addr_bool = np.array([True, True, False, False, True])
addr_int = np.array([0, 1, 4])
- assert_equal(a[::2, addr_bool].shape, a[::2, addr_int].shape)
- assert_equal(a[::2, addr_int].shape, m[::2, addr_int].shape)
- assert_equal(a[::2, addr_bool].shape, m[::2, addr_bool].shape)
+ assert a[::2, addr_bool].shape == a[::2, addr_int].shape
+ assert a[::2, addr_int].shape == m[::2, addr_int].shape
+ assert a[::2, addr_bool].shape == m[::2, addr_bool].shape
def test_partially_evaluate_constant_array_with_all_boolean_indices_false():
m = larray(3, shape=(3,))
a = 3 * np.ones((3,))
addr_bool = np.array([False, False, False])
- assert_equal(a[addr_bool].shape, m[addr_bool].shape)
+ assert a[addr_bool].shape == m[addr_bool].shape
def test_partially_evaluate_constant_array_with_only_one_boolean_indice_true():
m = larray(3, shape=(3,))
a = 3 * np.ones((3,))
addr_bool = np.array([False, True, False])
- assert_equal(a[addr_bool].shape, m[addr_bool].shape)
- assert_equal(m[addr_bool][0], a[0])
+ assert a[addr_bool].shape == m[addr_bool].shape
+ assert m[addr_bool][0] == a[0]
def
test_partially_evaluate_constant_array_with_boolean_indice_as_random_valid_ndarray():
@@ -633,8 +632,8 @@ def test_partially_evaluate_constant_arr
while not addr_bool.any():
# random array, but not [False, False, False]
addr_bool = np.random.rand(3) > 0.5
- assert_equal(a[addr_bool].shape, m[addr_bool].shape)
- assert_equal(m[addr_bool][0], a[addr_bool][0])
+ assert a[addr_bool].shape == m[addr_bool].shape
+ assert m[addr_bool][0] == a[addr_bool][0]
def test_partially_evaluate_constant_array_size_one_with_boolean_index_true():
@@ -644,19 +643,19 @@ def test_partially_evaluate_constant_arr
m1 = larray(3, shape=(1, 1))
a1 = 3 * np.ones((1, 1))
addr_bool1 = np.array([[True]], ndmin=2)
- assert_equal(m[addr_bool][0], a[0])
- assert_equal(m[addr_bool], a[addr_bool])
- assert_equal(m[addr_bool].shape, a[addr_bool].shape)
- assert_equal(m1[addr_bool1][0], a1[addr_bool1][0])
- assert_equal(m1[addr_bool1].shape, a1[addr_bool1].shape)
+ assert m[addr_bool][0] == a[0]
+ assert m[addr_bool] == a[addr_bool]
+ assert m[addr_bool].shape == a[addr_bool].shape
+ assert m1[addr_bool1][0] == a1[addr_bool1][0]
+ assert m1[addr_bool1].shape == a1[addr_bool1].shape
def test_partially_evaluate_constant_array_size_two_with_boolean_index_true():
m2 = larray(3, shape=(1, 2))
a2 = 3 * np.ones((1, 2))
addr_bool2 = np.ones((1, 2), dtype=bool)
- assert_equal(m2[addr_bool2][0], a2[addr_bool2][0])
- assert_equal(m2[addr_bool2].shape, a2[addr_bool2].shape)
+ assert m2[addr_bool2][0] == a2[addr_bool2][0]
+ assert m2[addr_bool2].shape == a2[addr_bool2].shape
def test_partially_evaluate_constant_array_size_one_with_boolean_index_false():
@@ -667,16 +666,16 @@ def test_partially_evaluate_constant_arr
addr_bool = np.array([False])
addr_bool1 = np.array([[False]], ndmin=2)
addr_bool2 = np.array([False])
- assert_equal(m[addr_bool].shape, a[addr_bool].shape)
- assert_equal(m1[addr_bool1].shape, a1[addr_bool1].shape)
+ assert m[addr_bool].shape == a[addr_bool].shape
+ assert m1[addr_bool1].shape == a1[addr_bool1].shape
def test_partially_evaluate_constant_array_size_with_empty_boolean_index():
m = larray(3, shape=(1,))
a = np.array([3])
addr_bool = np.array([], dtype='bool')
- assert_equal(m[addr_bool].shape, a[addr_bool].shape)
- assert_equal(m[addr_bool].shape, (0,))
+ assert m[addr_bool].shape == a[addr_bool].shape
+ assert m[addr_bool].shape == (0,)
def test_partially_evaluate_functional_array_with_boolean_index():
@@ -684,9 +683,9 @@ def test_partially_evaluate_functional_a
a = np.arange(20.0).reshape((4, 5))
addr_bool = np.array([True, True, False, False, True])
addr_int = np.array([0, 1, 4])
- assert_equal(a[::2, addr_bool].shape, a[::2, addr_int].shape)
- assert_equal(a[::2, addr_int].shape, m[::2, addr_int].shape)
- assert_equal(a[::2, addr_bool].shape, m[::2, addr_bool].shape)
+ assert a[::2, addr_bool].shape == a[::2, addr_int].shape
+ assert a[::2, addr_int].shape == m[::2, addr_int].shape
+ assert a[::2, addr_bool].shape == m[::2, addr_bool].shape
def test_getslice_with_vectorized_iterable():
@@ -699,7 +698,7 @@ def test_getslice_with_vectorized_iterab
def test_equality_with_lazyarray():
m1 = larray(42.0, shape=(4, 5)) / 23.0 + 2.0
m2 = larray(42.0, shape=(4, 5)) / 23.0 + 2.0
- assert_equal(m1, m2)
+ assert m1 == m2
def test_equality_with_number():
@@ -707,16 +706,16 @@ def test_equality_with_number():
m2 = larray([42, 42, 42])
m3 = larray([42, 42, 43])
m4 = larray(42.0, shape=(4, 5)) + 2
- assert_equal(m1, 42.0)
- assert_equal(m2, 42)
- assert_not_equal(m3, 42)
- assert_raises(Exception, m4.__eq__, 44.0)
+ assert m1 == 42.0
+ assert m2 == 42
+ assert m3 != 42
+ pytest.raises(Exception, m4.__eq__, 44.0)
def test_equality_with_array():
m1 = larray(42.0, shape=(4, 5))
target = 42.0 * np.ones((4, 5))
- assert_raises(TypeError, m1.__eq__, target)
+ pytest.raises(TypeError, m1.__eq__, target)
def test_deepcopy():
@@ -724,8 +723,8 @@ def test_deepcopy():
m2 = deepcopy(m1)
m1.shape = (3, 4)
m3 = deepcopy(m1)
- assert_equal(m1.shape, m3.shape, (3, 4))
- assert_equal(m2.shape, (4, 5))
+ assert m1.shape == m3.shape == (3, 4)
+ assert m2.shape == (4, 5)
assert_array_equal(m1.evaluate(), m3.evaluate())
@@ -739,7 +738,7 @@ def test_deepcopy_with_ufunc():
def test_set_shape():
m = larray(42) + larray(lambda i: 3 * i)
- assert_equal(m.shape, None)
+ assert m.shape is None
m.shape = (5,)
assert_array_equal(m.evaluate(), np.array([42, 45, 48, 51, 54]))
@@ -798,8 +797,8 @@ def test__issue4():
b = larray(np.arange(12).reshape((4, 3)))
mask1 = (slice(None), int(True))
mask2 = (slice(None), np.array([int(True)]))
- assert_equal(b[mask1].shape, partial_shape(mask1, b.shape), a[mask1].shape)
- assert_equal(b[mask2].shape, partial_shape(mask2, b.shape), a[mask2].shape)
+ assert b[mask1].shape == partial_shape(mask1, b.shape) == a[mask1].shape
+ assert b[mask2].shape == partial_shape(mask2, b.shape) == a[mask2].shape
def test__issue3():
@@ -837,15 +836,15 @@ def test_partial_shape():
(np.array([], bool), (0, 3)),
]
for mask, expected_shape in test_cases:
- assert_equal(partial_shape(mask, a.shape), a[mask].shape)
- assert_equal(partial_shape(mask, a.shape), expected_shape)
+ assert partial_shape(mask, a.shape) == a[mask].shape
+ assert partial_shape(mask, a.shape) == expected_shape
b = np.arange(5)
test_cases = [
(np.arange(5), (5,))
]
for mask, expected_shape in test_cases:
- assert_equal(partial_shape(mask, b.shape), b[mask].shape)
- assert_equal(partial_shape(mask, b.shape), expected_shape)
+ assert partial_shape(mask, b.shape) == b[mask].shape
+ assert partial_shape(mask, b.shape) == expected_shape
def test_is_homogeneous():
m0 = larray(10, shape=(5,))
Index: lazyarray-0.5.0/test/test_ufunc.py
===================================================================
--- lazyarray-0.5.0.orig/test/test_ufunc.py
+++ lazyarray-0.5.0/test/test_ufunc.py
@@ -7,7 +7,7 @@ Copyright Andrew P. Davison, 2012-2017
from lazyarray import larray, sqrt, cos, power, fmod
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
-from nose.tools import assert_raises
+import pytest
def test_sqrt_from_array():
@@ -59,4 +59,4 @@ def test_power_with_plain_array():
def test_fmod_with_array_as_2nd_arg():
A = larray(np.array([1, 4, 9, 16, 25]))
B = larray(np.array([1, 4, 9, 16, 25]))
- assert_raises(TypeError, fmod, A, B)
+ pytest.raises(TypeError, fmod, A, B)