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

Function _nanquantile_ureduce_func

numpy/lib/_nanfunctions_impl.py:1605–1659  ·  view source on GitHub ↗

Private function that doesn't support extended axis or keepdims. These methods are extended to this function using _ureduce See nanpercentile for parameter usage

(
        a: np.ndarray,
        q: np.ndarray,
        weights: np.ndarray,
        axis: int | None = None,
        out=None,
        overwrite_input: bool = False,
        method="linear",
        weak_q=False,
)

Source from the content-addressed store, hash-verified

1603
1604
1605def _nanquantile_ureduce_func(
1606 a: np.ndarray,
1607 q: np.ndarray,
1608 weights: np.ndarray,
1609 axis: int | None = None,
1610 out=None,
1611 overwrite_input: bool = False,
1612 method="linear",
1613 weak_q=False,
1614):
1615 """
1616 Private function that doesn't support extended axis or keepdims.
1617 These methods are extended to this function using _ureduce
1618 See nanpercentile for parameter usage
1619 """
1620 if axis is None or a.ndim == 1:
1621 part = a.ravel()
1622 wgt = None if weights is None else weights.ravel()
1623 result = _nanquantile_1d(part, q, overwrite_input, method,
1624 weights=wgt, weak_q=weak_q)
1625 # Note that this code could try to fill in `out` right away
1626 elif weights is None:
1627 result = np.apply_along_axis(_nanquantile_1d, axis, a, q,
1628 overwrite_input, method, weights, weak_q)
1629 # apply_along_axis fills in collapsed axis with results.
1630 # Move those axes to the beginning to match percentile's
1631 # convention.
1632 if q.ndim != 0:
1633 from_ax = [axis + i for i in range(q.ndim)]
1634 result = np.moveaxis(result, from_ax, list(range(q.ndim)))
1635 else:
1636 # We need to apply along axis over 2 arrays, a and weights.
1637 # move operation axes to end for simplicity:
1638 a = np.moveaxis(a, axis, -1)
1639 if weights is not None:
1640 weights = np.moveaxis(weights, axis, -1)
1641 if out is not None:
1642 result = out
1643 else:
1644 # weights are limited to `inverted_cdf` so the result dtype
1645 # is known to be identical to that of `a` here:
1646 result = np.empty_like(a, shape=q.shape + a.shape[:-1])
1647
1648 for ii in np.ndindex(a.shape[:-1]):
1649 result[(...,) + ii] = _nanquantile_1d(
1650 a[ii], q, weights=weights[ii],
1651 overwrite_input=overwrite_input, method=method,
1652 weak_q=weak_q,
1653 )
1654 # This path dealt with `out` already...
1655 return result
1656
1657 if out is not None:
1658 out[...] = result
1659 return result
1660
1661
1662def _nanquantile_1d(

Callers

nothing calls this directly

Calls 2

_nanquantile_1dFunction · 0.85
ravelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…