MCPcopy Index your code
hub / github.com/numpy/numpy / check

Method check

numpy/_core/tests/test_multiarray.py:4454–4542  ·  view source on GitHub ↗
(obj, binop_override_expected, ufunc_override_expected,
                  inplace_override_expected, check_scalar=True)

Source from the content-addressed store, hash-verified

4452 return MyType()
4453
4454 def check(obj, binop_override_expected, ufunc_override_expected,
4455 inplace_override_expected, check_scalar=True):
4456 for op, (ufunc, has_inplace, dtype) in ops.items():
4457 err_msg = (f'op: {op}, ufunc: {ufunc}, '
4458 f'has_inplace: {has_inplace}, dtype: {dtype}')
4459 check_objs = [np.arange(3, 7, dtype=dtype).reshape(2, 2)]
4460 if check_scalar:
4461 check_objs.append(check_objs[0][0])
4462 for arr in check_objs:
4463 arr_method = getattr(arr, f"__{op}__")
4464
4465 def first_out_arg(result):
4466 if op == "divmod":
4467 assert_(isinstance(result, tuple))
4468 return result[0]
4469 else:
4470 return result
4471
4472 # arr __op__ obj
4473 if binop_override_expected:
4474 assert_equal(arr_method(obj), NotImplemented, err_msg)
4475 elif ufunc_override_expected:
4476 assert_equal(arr_method(obj)[0], "__array_ufunc__",
4477 err_msg)
4478 elif (isinstance(obj, np.ndarray) and
4479 (type(obj).__array_ufunc__ is
4480 np.ndarray.__array_ufunc__)):
4481 # __array__ gets ignored
4482 res = first_out_arg(arr_method(obj))
4483 assert_(res.__class__ is obj.__class__, err_msg)
4484 else:
4485 assert_raises((TypeError, Coerced),
4486 arr_method, obj, err_msg=err_msg)
4487 # obj __op__ arr
4488 arr_rmethod = getattr(arr, f"__r{op}__")
4489 if ufunc_override_expected:
4490 res = arr_rmethod(obj)
4491 assert_equal(res[0], "__array_ufunc__",
4492 err_msg=err_msg)
4493 assert_equal(res[1], ufunc, err_msg=err_msg)
4494 elif (isinstance(obj, np.ndarray) and
4495 (type(obj).__array_ufunc__ is
4496 np.ndarray.__array_ufunc__)):
4497 # __array__ gets ignored
4498 res = first_out_arg(arr_rmethod(obj))
4499 assert_(res.__class__ is obj.__class__, err_msg)
4500 else:
4501 # __array_ufunc__ = "asdf" creates a TypeError
4502 assert_raises((TypeError, Coerced),
4503 arr_rmethod, obj, err_msg=err_msg)
4504
4505 # arr __iop__ obj
4506 # array scalars don't have in-place operators
4507 if has_inplace and isinstance(arr, np.ndarray):
4508 arr_imethod = getattr(arr, f"__i{op}__")
4509 if inplace_override_expected:
4510 assert_equal(arr_method(obj), NotImplemented,
4511 err_msg=err_msg)

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
assert_Function · 0.90
assert_raisesFunction · 0.90
itemsMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected