Check that contiguous and non-contiguous calls to ufuncs have the same results for values in range(9)
(ufunc)
| 2631 | if isinstance(getattr(np, x), np.ufunc)]) |
| 2632 | @np._no_nep50_warning() |
| 2633 | def test_ufunc_noncontiguous(ufunc): |
| 2634 | ''' |
| 2635 | Check that contiguous and non-contiguous calls to ufuncs |
| 2636 | have the same results for values in range(9) |
| 2637 | ''' |
| 2638 | for typ in ufunc.types: |
| 2639 | # types is a list of strings like ii->i |
| 2640 | if any(set('O?mM') & set(typ)): |
| 2641 | # bool, object, datetime are too irregular for this simple test |
| 2642 | continue |
| 2643 | inp, out = typ.split('->') |
| 2644 | args_c = [np.empty(6, t) for t in inp] |
| 2645 | args_n = [np.empty(18, t)[::3] for t in inp] |
| 2646 | for a in args_c: |
| 2647 | a.flat = range(1,7) |
| 2648 | for a in args_n: |
| 2649 | a.flat = range(1,7) |
| 2650 | with warnings.catch_warnings(record=True): |
| 2651 | warnings.filterwarnings("always") |
| 2652 | res_c = ufunc(*args_c) |
| 2653 | res_n = ufunc(*args_n) |
| 2654 | if len(out) == 1: |
| 2655 | res_c = (res_c,) |
| 2656 | res_n = (res_n,) |
| 2657 | for c_ar, n_ar in zip(res_c, res_n): |
| 2658 | dt = c_ar.dtype |
| 2659 | if np.issubdtype(dt, np.floating): |
| 2660 | # for floating point results allow a small fuss in comparisons |
| 2661 | # since different algorithms (libm vs. intrinsics) can be used |
| 2662 | # for different input strides |
| 2663 | res_eps = np.finfo(dt).eps |
| 2664 | tol = 2*res_eps |
| 2665 | assert_allclose(res_c, res_n, atol=tol, rtol=tol) |
| 2666 | else: |
| 2667 | assert_equal(c_ar, n_ar) |
| 2668 | |
| 2669 | |
| 2670 | @pytest.mark.parametrize('ufunc', [np.sign, np.equal]) |
nothing calls this directly
no test coverage detected