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

Method test_percentile_out

numpy/lib/tests/test_function_base.py:3605–3654  ·  view source on GitHub ↗
(self, percentile, with_weights)

Source from the content-addressed store, hash-verified

3603 ]
3604 )
3605 def test_percentile_out(self, percentile, with_weights):
3606 out_dtype = int if with_weights else float
3607 x = np.array([1, 2, 3])
3608 y = np.zeros((3,), dtype=out_dtype)
3609 p = (1, 2, 3)
3610 weights = np.ones_like(x) if with_weights else None
3611 r = percentile(x, p, out=y, weights=weights)
3612 assert r is y
3613 assert_equal(percentile(x, p, weights=weights), y)
3614
3615 x = np.array([[1, 2, 3],
3616 [4, 5, 6]])
3617 y = np.zeros((3, 3), dtype=out_dtype)
3618 weights = np.ones_like(x) if with_weights else None
3619 r = percentile(x, p, axis=0, out=y, weights=weights)
3620 assert r is y
3621 assert_equal(percentile(x, p, weights=weights, axis=0), y)
3622
3623 y = np.zeros((3, 2), dtype=out_dtype)
3624 percentile(x, p, axis=1, out=y, weights=weights)
3625 assert_equal(percentile(x, p, weights=weights, axis=1), y)
3626
3627 x = np.arange(12).reshape(3, 4)
3628 # q.dim > 1, float
3629 if with_weights:
3630 r0 = np.array([[0, 1, 2, 3], [4, 5, 6, 7]])
3631 else:
3632 r0 = np.array([[2., 3., 4., 5.], [4., 5., 6., 7.]])
3633 out = np.empty((2, 4), dtype=out_dtype)
3634 weights = np.ones_like(x) if with_weights else None
3635 assert_equal(
3636 percentile(x, (25, 50), axis=0, out=out, weights=weights), r0
3637 )
3638 assert_equal(out, r0)
3639 r1 = np.array([[0.75, 4.75, 8.75], [1.5, 5.5, 9.5]])
3640 out = np.empty((2, 3))
3641 assert_equal(np.percentile(x, (25, 50), axis=1, out=out), r1)
3642 assert_equal(out, r1)
3643
3644 # q.dim > 1, int
3645 r0 = np.array([[0, 1, 2, 3], [4, 5, 6, 7]])
3646 out = np.empty((2, 4), dtype=x.dtype)
3647 c = np.percentile(x, (25, 50), method='lower', axis=0, out=out)
3648 assert_equal(c, r0)
3649 assert_equal(out, r0)
3650 r1 = np.array([[0, 4, 8], [1, 5, 9]])
3651 out = np.empty((2, 3), dtype=x.dtype)
3652 c = np.percentile(x, (25, 50), method='lower', axis=1, out=out)
3653 assert_equal(c, r1)
3654 assert_equal(out, r1)
3655
3656 def test_percentile_empty_dim(self):
3657 # empty dims are preserved

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
percentileFunction · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected