Ejemplo n.º 1
0
def percentile(a, q, axis=None, out=None, interpolation='linear',
               keepdims=False):
    """Computes the q-th percentile of the data along the specified axis.

    Args:
        a (cupy.ndarray): Array for which to compute percentiles.
        q (float, tuple of floats or cupy.ndarray): Percentiles to compute
            in the range between 0 and 100 inclusive.
        axis (int or tuple of ints): Along which axis or axes to compute the
            percentiles. The flattened array is used by default.
        out (cupy.ndarray): Output array.
        interpolation (str): Interpolation method when a quantile lies between
            two data points. ``linear`` interpolation is used by default.
            Supported interpolations are``lower``, ``higher``, ``midpoint``,
            ``nearest`` and ``linear``.
        keepdims (bool): If ``True``, the axis is remained as an axis of
            size one.

    Returns:
        cupy.ndarray: The percentiles of ``a``, along the axis if specified.

    .. seealso:: :func:`numpy.percentile`
    """
    if not isinstance(q, cupy.ndarray):
        q = cupy.asarray(q, dtype='d')
    q = cupy.true_divide(q, 100)
    if not _quantile_is_valid(q):  # synchronize
        raise ValueError('Percentiles must be in the range [0, 100]')
    return _quantile_unchecked(a, q, axis=axis, out=out,
                               interpolation=interpolation, keepdims=keepdims)
Ejemplo n.º 2
0
def percentile(a,
               q,
               axis=None,
               out=None,
               overwrite_input=False,
               method='linear',
               keepdims=False,
               *,
               interpolation=None):
    """Computes the q-th percentile of the data along the specified axis.

    Args:
        a (cupy.ndarray): Array for which to compute percentiles.
        q (float, tuple of floats or cupy.ndarray): Percentiles to compute
            in the range between 0 and 100 inclusive.
        axis (int or tuple of ints): Along which axis or axes to compute the
            percentiles. The flattened array is used by default.
        out (cupy.ndarray): Output array.
        overwrite_input (bool): If True, then allow the input array `a`
            to be modified by the intermediate calculations, to save
            memory. In this case, the contents of the input `a` after this
            function completes is undefined.
        method (str): Interpolation method when a quantile lies between
            two data points. ``linear`` interpolation is used by default.
            Supported interpolations are``lower``, ``higher``, ``midpoint``,
            ``nearest`` and ``linear``.
        keepdims (bool): If ``True``, the axis is remained as an axis of
            size one.
        interpolation (str): Deprecated name for the method keyword argument.

    Returns:
        cupy.ndarray: The percentiles of ``a``, along the axis if specified.

    .. seealso:: :func:`numpy.percentile`
    """
    if interpolation is not None:
        method = _check_interpolation_as_method(method, interpolation,
                                                'percentile')
    if not isinstance(q, cupy.ndarray):
        q = cupy.asarray(q, dtype='d')
    q = cupy.true_divide(q, 100)
    if not _quantile_is_valid(q):  # synchronize
        raise ValueError('Percentiles must be in the range [0, 100]')
    return _quantile_unchecked(a,
                               q,
                               axis=axis,
                               out=out,
                               overwrite_input=overwrite_input,
                               method=method,
                               keepdims=keepdims)
def cupy_background_correction(data,
                               dark,
                               flat,
                               clip_min=MINIMUM_PIXEL_VALUE,
                               clip_max=MAXIMUM_PIXEL_VALUE):
    """
    Carry out something akin to background correction in Mantid Imaging using cupy.
    :param data: The fake data array.
    :param dark: The fake dark array.
    :param flat: The fake flat array.
    :param clip_min: Minimum clipping value.
    :param clip_max: Maximum clipping value.
    """
    flat = cp.subtract(flat, dark)
    flat[flat == 0] = MINIMUM_PIXEL_VALUE
    data = cp.subtract(data, dark)
    data = cp.true_divide(data, flat)
    data = cp.clip(
        data, clip_min,
        clip_max)  # For some reason using the 'out' parameter doesn't work
Ejemplo n.º 4
0
 def __rtruediv__(self, other):
     return cupy.true_divide(other, self)
Ejemplo n.º 5
0
 def __truediv__(self, other):
     return cupy.true_divide(self, other)
Ejemplo n.º 6
0
 def _cov_pairwise(x1, x2, factor):
     return cupy.nansum(x1 * x2, axis=1, keepdims=True) * cupy.true_divide(
         1, factor)