Skip to content

Instantly share code, notes, and snippets.

@ogrisel
Last active April 27, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogrisel/851992e4c555af67881c9e0f2281c5df to your computer and use it in GitHub Desktop.
Save ogrisel/851992e4c555af67881c9e0f2281c5df to your computer and use it in GitHub Desktop.
___________________________________________ TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full[reciprocal] ____________________________________________
self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x15b5324f0>, ufunc = <ufunc 'reciprocal'>
@pytest.mark.parametrize("ufunc", UNARY_OBJECT_UFUNCS)
def test_unary_PyUFunc_O_O_method_full(self, ufunc):
"""Compare the result of the object loop with non-object one"""
val = np.float64(np.pi/4)
class MyFloat(np.float64):
def __getattr__(self, attr):
try:
return super().__getattr__(attr)
except AttributeError:
return lambda: getattr(np.core.umath, attr)(val)
num_arr = np.array([val], dtype=np.float64)
obj_arr = np.array([MyFloat(val)], dtype="O")
with np.errstate(all="raise"):
try:
> res_num = ufunc(num_arr)
E FloatingPointError: divide by zero encountered in reciprocal
MyFloat = <class 'numpy.core.tests.test_ufunc.TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat'>
num_arr = array([0.78539816])
obj_arr = array([0.7853981633974483], dtype=object)
self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x15b5324f0>
ufunc = <ufunc 'reciprocal'>
val = 0.7853981633974483
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/core/tests/test_ufunc.py:172: FloatingPointError
During handling of the above exception, another exception occurred:
self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x15b5324f0>, ufunc = <ufunc 'reciprocal'>
@pytest.mark.parametrize("ufunc", UNARY_OBJECT_UFUNCS)
def test_unary_PyUFunc_O_O_method_full(self, ufunc):
"""Compare the result of the object loop with non-object one"""
val = np.float64(np.pi/4)
class MyFloat(np.float64):
def __getattr__(self, attr):
try:
return super().__getattr__(attr)
except AttributeError:
return lambda: getattr(np.core.umath, attr)(val)
num_arr = np.array([val], dtype=np.float64)
obj_arr = np.array([MyFloat(val)], dtype="O")
with np.errstate(all="raise"):
try:
res_num = ufunc(num_arr)
except Exception as exc:
with assert_raises(type(exc)):
> ufunc(obj_arr)
MyFloat = <class 'numpy.core.tests.test_ufunc.TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat'>
num_arr = array([0.78539816])
obj_arr = array([0.7853981633974483], dtype=object)
self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x15b5324f0>
ufunc = <ufunc 'reciprocal'>
val = 0.7853981633974483
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/core/tests/test_ufunc.py:175:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
miniforge3/envs/tmp/lib/python3.9/unittest/case.py:226: in __exit__
self._raiseFailure("{} not raised".format(exc_name))
exc_name = 'FloatingPointError'
exc_type = None
exc_value = None
self = <unittest.case._AssertRaisesContext object at 0x15b532700>
tb = None
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <unittest.case._AssertRaisesContext object at 0x15b532700>, standardMsg = 'FloatingPointError not raised'
def _raiseFailure(self, standardMsg):
msg = self.test_case._formatMessage(self.msg, standardMsg)
> raise self.test_case.failureException(msg)
E AssertionError: FloatingPointError not raised
msg = 'FloatingPointError not raised'
self = <unittest.case._AssertRaisesContext object at 0x15b532700>
standardMsg = 'FloatingPointError not raised'
miniforge3/envs/tmp/lib/python3.9/unittest/case.py:163: AssertionError
____________________________________________________ TestSharedMemory.test_in_from_2casttype[LONGDOUBLE] ____________________________________________________
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fb812b0>
def test_in_from_2casttype(self):
for t in self.type.cast_types():
obj = np.array(self.num2seq, dtype=t.dtype)
> a = self.array([len(self.num2seq)], intent.in_, obj)
a = <numpy.f2py.tests.test_array_from_pyobj.Array object at 0x15fb81340>
obj = array([1, 2])
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fb812b0>
t = <numpy.f2py.tests.test_array_from_pyobj.Type object at 0x15f6f9910>
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/f2py/tests/test_array_from_pyobj.py:323:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/f2py/tests/test_array_from_pyobj.py:314: in <lambda>
Array(Type(request.param), dims, intent, obj)
dims = [2]
intent = Intent(['in'])
obj = array([1, 2])
request = <SubRequest 'setup_type' for <Function test_in_from_2seq[LONGDOUBLE]>>
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fb812b0>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <numpy.f2py.tests.test_array_from_pyobj.Array object at 0x15fb815b0>, typ = <numpy.f2py.tests.test_array_from_pyobj.Type object at 0x15f6f9a60>
dims = [2], intent = Intent(['in']), obj = array([1, 2])
def __init__(self, typ, dims, intent, obj):
self.type = typ
self.dims = dims
self.intent = intent
self.obj_copy = copy.deepcopy(obj)
self.obj = obj
# arr.dtypechar may be different from typ.dtypechar
self.arr = wrap.call(typ.type_num, dims, intent.flags, obj)
assert_(isinstance(self.arr, np.ndarray), repr(type(self.arr)))
self.arr_attr = wrap.array_attrs(self.arr)
if len(dims) > 1:
if self.intent.is_intent('c'):
assert_(intent.flags & wrap.F2PY_INTENT_C)
assert_(not self.arr.flags['FORTRAN'],
repr((self.arr.flags, getattr(obj, 'flags', None))))
assert_(self.arr.flags['CONTIGUOUS'])
assert_(not self.arr_attr[6] & wrap.FORTRAN)
else:
assert_(not intent.flags & wrap.F2PY_INTENT_C)
assert_(self.arr.flags['FORTRAN'])
assert_(not self.arr.flags['CONTIGUOUS'])
assert_(self.arr_attr[6] & wrap.FORTRAN)
if obj is None:
self.pyarr = None
self.pyarr_attr = None
return
if intent.is_intent('cache'):
assert_(isinstance(obj, np.ndarray), repr(type(obj)))
self.pyarr = np.array(obj).reshape(*dims).copy()
else:
self.pyarr = np.array(
np.array(obj, dtype=typ.dtypechar).reshape(*dims),
order=self.intent.is_intent('c') and 'C' or 'F')
assert_(self.pyarr.dtype == typ,
repr((self.pyarr.dtype, typ)))
self.pyarr.setflags(write=self.arr.flags['WRITEABLE'])
assert_(self.pyarr.flags['OWNDATA'], (obj, intent))
self.pyarr_attr = wrap.array_attrs(self.pyarr)
if len(dims) > 1:
if self.intent.is_intent('c'):
assert_(not self.pyarr.flags['FORTRAN'])
assert_(self.pyarr.flags['CONTIGUOUS'])
assert_(not self.pyarr_attr[6] & wrap.FORTRAN)
else:
assert_(self.pyarr.flags['FORTRAN'])
assert_(not self.pyarr.flags['CONTIGUOUS'])
assert_(self.pyarr_attr[6] & wrap.FORTRAN)
assert_(self.arr_attr[1] == self.pyarr_attr[1]) # nd
assert_(self.arr_attr[2] == self.pyarr_attr[2]) # dimensions
if self.arr_attr[1] <= 1:
assert_(self.arr_attr[3] == self.pyarr_attr[3],
repr((self.arr_attr[3], self.pyarr_attr[3],
self.arr.tobytes(), self.pyarr.tobytes()))) # strides
assert_(self.arr_attr[5][-2:] == self.pyarr_attr[5][-2:],
repr((self.arr_attr[5], self.pyarr_attr[5]))) # descr
assert_(self.arr_attr[6] == self.pyarr_attr[6],
repr((self.arr_attr[6], self.pyarr_attr[6],
flags2names(0 * self.arr_attr[6] - self.pyarr_attr[6]),
flags2names(self.arr_attr[6]), intent))) # flags
if intent.is_intent('cache'):
assert_(self.arr_attr[5][3] >= self.type.elsize,
repr((self.arr_attr[5][3], self.type.elsize)))
else:
assert_(self.arr_attr[5][3] == self.type.elsize,
repr((self.arr_attr[5][3], self.type.elsize)))
assert_(self.arr_equal(self.pyarr, self.arr))
if isinstance(self.obj, np.ndarray):
if typ.elsize == Type(obj.dtype).elsize:
if not intent.is_intent('copy') and self.arr_attr[1] <= 1:
> assert_(self.has_shared_memory())
E AssertionError
dims = [2]
intent = Intent(['in'])
obj = array([1, 2])
self = <numpy.f2py.tests.test_array_from_pyobj.Array object at 0x15fb815b0>
typ = <numpy.f2py.tests.test_array_from_pyobj.Type object at 0x15f6f9a60>
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/f2py/tests/test_array_from_pyobj.py:274: AssertionError
__________________________________________________ TestSharedMemory.test_f_in_from_23casttype[LONGDOUBLE] ___________________________________________________
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fb98c40>
def test_f_in_from_23casttype(self):
for t in self.type.cast_types():
obj = np.array(self.num23seq, dtype=t.dtype, order='F')
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_, obj)
if t.elsize == self.type.elsize:
> assert_(a.has_shared_memory(), repr(t.dtype))
E AssertionError: dtype('int64')
a = <numpy.f2py.tests.test_array_from_pyobj.Array object at 0x15fb987c0>
obj = array([[1, 2, 3],
[4, 5, 6]])
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fb98c40>
t = <numpy.f2py.tests.test_array_from_pyobj.Type object at 0x15f6f9910>
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/f2py/tests/test_array_from_pyobj.py:404: AssertionError
__________________________________________________ TestSharedMemory.test_c_in_from_23casttype[LONGDOUBLE] ___________________________________________________
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fba23a0>
def test_c_in_from_23casttype(self):
for t in self.type.cast_types():
obj = np.array(self.num23seq, dtype=t.dtype)
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_.c, obj)
if t.elsize == self.type.elsize:
> assert_(a.has_shared_memory(), repr(t.dtype))
E AssertionError: dtype('int64')
a = <numpy.f2py.tests.test_array_from_pyobj.Array object at 0x15fba2790>
obj = array([[1, 2, 3],
[4, 5, 6]])
self = <numpy.f2py.tests.test_array_from_pyobj.TestSharedMemory object at 0x15fba23a0>
t = <numpy.f2py.tests.test_array_from_pyobj.Type object at 0x15f6f9910>
miniforge3/envs/tmp/lib/python3.9/site-packages/numpy/f2py/tests/test_array_from_pyobj.py:414: AssertionError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment