コード例 #1
0
ファイル: dpnp_iface_linalg.py プロジェクト: densmirn/dpnp
def cond(input, p=None):
    """
    Compute the condition number of a matrix.
    For full documentation refer to :obj:`numpy.linalg.cond`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Parameter p=[None, 1, -1, 2, -2, numpy.inf, -numpy.inf, 'fro'] is supported.

    See Also
    --------
    :obj:`dpnp.norm` : Matrix or vector norm.
    """

    if (not use_origin_backend(input)):
        if p in [None, 1, -1, 2, -2, numpy.inf, -numpy.inf, 'fro']:
            result_obj = dpnp_cond(input, p)
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result
        else:
            pass

    return call_origin(numpy.linalg.cond, input, p)
コード例 #2
0
def count_nonzero(x1, axis=None, *, keepdims=False):
    """
    Counts the number of non-zero values in the array ``in_array1``.

    For full documentation refer to :obj:`numpy.count_nonzero`.

    Limitations
    -----------
        Parameter ``x1`` is supported as :obj:`dpnp.ndarray`.
        Otherwise the function will be executed sequentially on CPU.
        Parameter ``axis`` is supported only with default value `None`.
        Parameter ``keepdims`` is supported only with default value `False`.

    Examples
    --------
    >>> import dpnp as np
    >>> np.count_nonzero(np.array([1, 0, 3, 0, 5])
    3
    >>> np.count_nonzero(np.array([[1, 0, 3, 0, 5],[0, 9, 0, 7, 0]]))
    5

    """
    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if axis is not None:
            pass
        elif keepdims is not False:
            pass
        else:
            result_obj = dpnp_count_nonzero(x1_desc).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.count_nonzero, x1, axis, keepdims=keepdims)
コード例 #3
0
def ptp(arr, axis=None, out=None, keepdims=numpy._NoValue):
    """
    Range of values (maximum - minimum) along an axis.

    For full documentation refer to :obj:`numpy.ptp`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Parameters ``out`` and ``keepdims`` are supported only with default values.
    """
    arr_desc = dpnp.get_dpnp_descriptor(arr)
    if not arr_desc:
        pass
    elif axis is not None and not isinstance(axis, int):
        pass
    elif out is not None:
        pass
    elif keepdims is not numpy._NoValue:
        pass
    else:
        result_obj = dpnp_ptp(arr_desc, axis=axis).get_pyobj()
        result = dpnp.convert_single_elem_array_to_scalar(result_obj)

        return result

    return call_origin(numpy.ptp, arr, axis, out, keepdims)
コード例 #4
0
def var(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    """
    Compute the variance along the specified axis.

    For full documentation refer to :obj:`numpy.var`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Size of input array is limited by ``a.size > 0``.
    Prameters ``axis`` is supported only with default value ``None``.
    Prameters ``dtype`` is supported only with default value ``None``.
    Prameters ``out`` is supported only with default value ``None``.
    Prameters ``keepdims`` is supported only with default value ``numpy._NoValue``.
    Otherwise the function will be executed sequentially on CPU.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    See Also
    --------
    :obj:`dpnp.std` : Compute the standard deviation along the specified axis.
    :obj:`dpnp.mean` : Compute the arithmetic mean along the specified axis.
    :obj:`dpnp.nanmean` : Compute the arithmetic mean along the specified axis,
                          ignoring NaNs.
    :obj:`dpnp.nanstd` : Compute the standard deviation along
                         the specified axis, while ignoring NaNs.
    :obj:`dpnp.nanvar` : Compute the variance along the specified axis,
                         while ignoring NaNs.

    Examples
    --------
    >>> import dpnp as np
    >>> a = np.array([[1, 2], [3, 4]])
    >>> np.var(a)
    1.25

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if x1_desc.size == 0:
            pass
        elif axis is not None:
            pass
        elif dtype is not None:
            pass
        elif out is not None:
            pass
        elif keepdims:
            pass
        else:
            result_obj = dpnp_var(x1_desc, ddof).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.var, x1, axis, dtype, out, ddof, keepdims)
コード例 #5
0
ファイル: dpnp_iface_logic.py プロジェクト: densmirn/dpnp
def all(x1, axis=None, out=None, keepdims=False):
    """
    Test whether all array elements along a given axis evaluate to True.

    For full documentation refer to :obj:`numpy.all`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Otherwise the function will be executed sequentially on CPU.
    Input array data types are limited by supported DPNP :ref:`Data types`.
    Parameter ``axis`` is supported only with default value ``None``.
    Parameter ``out`` is supported only with default value ``None``.
    Parameter ``keepdims`` is supported only with default value ``False``.

    See Also
    --------
    :obj:`dpnp.any` : Test whether any element along a given axis evaluates to True.

    Notes
    -----
    Not a Number (NaN), positive infinity and negative infinity
    evaluate to `True` because these are not equal to zero.

    Examples
    --------
    >>> import dpnp as np
    >>> x = np.array([[True, False], [True, True]])
    >>> np.all(x)
    False
    >>> x2 = np.array([-1, 4, 5])
    >>> np.all(x2)
    True
    >>> x3 = np.array([1.0, np.nan])
    >>> np.all(x3)
    True

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if axis is not None:
            pass
        elif out is not None:
            pass
        elif keepdims is not False:
            pass
        else:
            result_obj = dpnp_all(x1_desc).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.all, x1, axis, out, keepdims)
コード例 #6
0
ファイル: dpnp_iface_searching.py プロジェクト: densmirn/dpnp
def argmax(x1, axis=None, out=None):
    """
    Returns the indices of the maximum values along an axis.

    For full documentation refer to :obj:`numpy.argmax`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Otherwise the function will be executed sequentially on CPU.
    Parameter ``axis`` is supported only with default value ``None``.
    Parameter ``out`` is supported only with default value ``None``.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    See Also
    --------
    :obj:`dpnp.argmin` : Returns the indices of the minimum values along an axis.
    :obj:`dpnp.amax` : The maximum value along a given axis.
    :obj:`dpnp.unravel_index` : Convert a flat index into an index tuple.
    :obj:`dpnp.take_along_axis` : Apply ``np.expand_dims(index_array, axis)``
                                  from argmax to an array as if by calling max.

    Notes
    -----
    In case of multiple occurrences of the maximum values, the indices
    corresponding to the first occurrence are returned.

    Examples
    --------
    >>> import dpnp as np
    >>> a = np.arange(6).reshape((2, 3)) + 10
    >>> a.shape
    (2, 3)
    >>> [i for i in a]
    [10, 11, 12, 13, 14, 15]
    >>> np.argmax(a)
    5

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if axis is not None:
            pass
        elif out is not None:
            pass
        else:
            result_obj = dpnp_argmax(x1_desc).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.argmax, x1, axis, out)
コード例 #7
0
ファイル: dpnp_iface_linalg.py プロジェクト: densmirn/dpnp
def norm(x1, ord=None, axis=None, keepdims=False):
    """
    Matrix or vector norm.
    This function is able to return one of eight different matrix norms,
    or one of an infinite number of vector norms (described below), depending
    on the value of the ``ord`` parameter.

    Parameters
    ----------
    input : array_like
        Input array.  If `axis` is None, `x` must be 1-D or 2-D, unless `ord`
        is None. If both `axis` and `ord` are None, the 2-norm of
        ``x.ravel`` will be returned.
    ord : optional
        Order of the norm (see table under ``Notes``). inf means numpy's
        `inf` object. The default is None.
    axis : optional.
        If `axis` is an integer, it specifies the axis of `x` along which to
        compute the vector norms.  If `axis` is a 2-tuple, it specifies the
        axes that hold 2-D matrices, and the matrix norms of these matrices
        are computed.  If `axis` is None then either a vector norm (when `x`
        is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default
        is None.
    keepdims : bool, optional
        If this is set to True, the axes which are normed over are left in the
        result as dimensions with size one.  With this option the result will
        broadcast correctly against the original `x`.

    Returns
    -------
    n : float or ndarray
        Norm of the matrix or vector(s).
    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if not isinstance(axis, int) and not isinstance(
                axis, tuple) and axis is not None:
            pass
        elif keepdims is not False:
            pass
        elif ord not in [None, 0, 3, 'fro', 'f']:
            pass
        else:
            result_obj = dpnp_norm(x1, ord=ord, axis=axis)
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.linalg.norm, x1, ord, axis, keepdims)
コード例 #8
0
def mean(x1, axis=None, **kwargs):
    """
    Compute the arithmetic mean along the specified axis.

    For full documentation refer to :obj:`numpy.mean`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Prameters ``axis`` is supported only with default value ``None``.
    Keyword arguments ``kwargs`` are currently unsupported.
    Size of input array is limited by ``x1.size > 0``.
    Otherwise the function will be executed sequentially on CPU.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    See Also
    --------
    :obj:`dpnp.average` : Weighted average.
    :obj:`dpnp.std` : Compute the standard deviation along the specified axis.
    :obj:`dpnp.var` : Compute the variance along the specified axis.
    :obj:`dpnp.nanmean` : Compute the arithmetic mean along the specified axis,
                          ignoring NaNs.
    :obj:`dpnp.nanstd` : Compute the standard deviation along
                         the specified axis, while ignoring NaNs.
    :obj:`dpnp.nanvar` : Compute the variance along the specified axis,
                         while ignoring NaNs.

    Examples
    --------
    >>> import dpnp as np
    >>> a = np.array([[1, 2], [3, 4]])
    >>> np.mean(a)
    2.5

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc and not kwargs:
        if x1_desc.size == 0:
            pass
        elif axis is not None:
            pass
        else:
            result_obj = dpnp_mean(x1_desc, axis)
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.mean, x1, axis=axis, **kwargs)
コード例 #9
0
def median(x1, axis=None, out=None, overwrite_input=False, keepdims=False):
    """
    Compute the median along the specified axis.

    For full documentation refer to :obj:`numpy.median`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Prameters ``axis`` is supported only with default value ``None``.
    Prameters ``out`` is supported only with default value ``None``.
    Prameters ``overwrite_input`` is supported only with default value ``False``.
    Prameters ``keepdims`` is supported only with default value ``False``.
    Otherwise the function will be executed sequentially on CPU.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    See Also
    --------
    :obj:`dpnp.mean` : Compute the arithmetic mean along the specified axis.
    :obj:`dpnp.percentile` : Compute the q-th percentile of the data
                             along the specified axis.

    Examples
    --------
    >>> import dpnp as np
    >>> a = np.array([[10, 7, 4], [3, 2, 1]])
    >>> np.median(a)
    3.5

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if axis is not None:
            pass
        elif out is not None:
            pass
        elif overwrite_input:
            pass
        elif keepdims:
            pass
        else:
            result_obj = dpnp_median(x1_desc).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.median, x1, axis, out, overwrite_input, keepdims)
コード例 #10
0
def average(x1, axis=None, weights=None, returned=False):
    """
    Compute the weighted average along the specified axis.

    For full documentation refer to :obj:`numpy.average`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Prameters ``axis`` is supported only with default value ``None``.
    Prameters ``weights`` is supported only with default value ``None``.
    Prameters ``returned`` is supported only with default value ``False``.
    Otherwise the function will be executed sequentially on CPU.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    See Also
    --------
    :obj:`dpnp.mean` : Compute the arithmetic mean along the specified axis.

    Examples
    --------
    >>> import dpnp as np
    >>> data = np.arange(1, 5)
    >>> [i for i in data]
    [1, 2, 3, 4]
    >>> np.average(data)
    2.5

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if axis is not None:
            pass
        elif weights is not None:
            pass
        elif returned:
            pass
        else:
            result_obj = dpnp_average(x1_desc)
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.average, x1, axis, weights, returned)
コード例 #11
0
def nanvar(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    """
    Compute the variance along the specified axis, while ignoring NaNs.

    For full documentation refer to :obj:`numpy.nanvar`.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Prameters ``axis`` is supported only with default value ``None``.
    Prameters ``dtype`` is supported only with default value ``None``.
    Prameters ``out`` is supported only with default value ``None``.
    Prameters ``keepdims`` is supported only with default value ``numpy._NoValue``.
    Otherwise the function will be executed sequentially on CPU.
    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if x1.size == 0:
            pass
        elif axis is not None:
            pass
        elif dtype is not None:
            pass
        elif out is not None:
            pass
        elif keepdims:
            pass
        else:
            result_obj = dpnp_nanvar(x1_desc, ddof).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.nanvar,
                       x1,
                       axis=axis,
                       dtype=dtype,
                       out=out,
                       ddof=ddof,
                       keepdims=keepdims)
コード例 #12
0
def min(x1, axis=None, out=None, keepdims=False, initial=None, where=True):
    """
    Return the minimum along a given axis.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Otherwise the function will be executed sequentially on CPU.
    Prameters ``out`` is supported only with default value ``None``.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    Examples
    --------
    >>> import dpnp as np
    >>> a = np.arange(4).reshape((2,2))
    >>> a.shape
    (2, 2)
    >>> [i for i in a]
    [0, 1, 2, 3]
    >>> np.min(a)
    0

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        if out is not None:
            pass
        elif keepdims:
            pass
        elif initial is not None:
            pass
        elif where is not True:
            pass
        else:
            result_obj = dpnp_min(x1_desc, axis).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.min, x1, axis, out, keepdims, initial, where)
コード例 #13
0
ファイル: dpnp_iface_linalg.py プロジェクト: densmirn/dpnp
def matrix_rank(input, tol=None, hermitian=False):
    """
    Return matrix rank of array
    Rank of the array is the number of singular values of the array that are
    greater than `tol`.

    Parameters
    ----------
    M : {(M,), (..., M, N)} array_like
        Input vector or stack of matrices.
    tol : (...) array_like, float, optional
        Threshold below which SVD values are considered zero. If `tol` is
        None, and ``S`` is an array with singular values for `M`, and
        ``eps`` is the epsilon value for datatype of ``S``, then `tol` is
        set to ``S.max() * max(M.shape) * eps``.
    hermitian : bool, optional
        If True, `M` is assumed to be Hermitian (symmetric if real-valued),
        enabling a more efficient method for finding singular values.
        Defaults to False.

    Returns
    -------
    rank : (...) array_like
        Rank of M.

    """

    x1_desc = dpnp.get_dpnp_descriptor(input)
    if x1_desc:
        if tol is not None:
            pass
        elif hermitian:
            pass
        else:
            result_obj = dpnp_matrix_rank(x1_desc).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.linalg.matrix_rank, input, tol, hermitian)
コード例 #14
0
ファイル: dpnp_iface_logic.py プロジェクト: densmirn/dpnp
def allclose(x1, x2, rtol=1.e-5, atol=1.e-8, **kwargs):
    """
    Returns True if two arrays are element-wise equal within a tolerance.

    For full documentation refer to :obj:`numpy.allclose`.

    Limitations
    -----------
    Parameters ``x1`` and ``x2`` are supported as either :obj:`dpnp.ndarray` or scalar.
    Keyword arguments ``kwargs`` are currently unsupported.
    Otherwise the functions will be executed sequentially on CPU.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    Examples
    --------
    >>> import dpnp as np
    >>> np.allclose([1e10,1e-7], [1.00001e10,1e-8])
    >>> False

    """

    rtol_is_scalar = dpnp.isscalar(rtol)
    atol_is_scalar = dpnp.isscalar(atol)
    x1_desc = dpnp.get_dpnp_descriptor(x1)
    x2_desc = dpnp.get_dpnp_descriptor(x2)

    if x1_desc and x2_desc and not kwargs:
        if not rtol_is_scalar or not atol_is_scalar:
            pass
        else:
            result_obj = dpnp_allclose(x1_desc, x2_desc, rtol,
                                       atol).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.allclose, x1, x2, rtol=rtol, atol=atol, **kwargs)
コード例 #15
0
ファイル: dpnp_iface_linalg.py プロジェクト: densmirn/dpnp
def det(input):
    """
    Compute the determinant of an array.

    Parameters
    ----------
    input : (..., M, M) array_like
        Input array to compute determinants for.

    Returns
    -------
    det : (...) array_like
        Determinant of `input`.
    """

    x1_desc = dpnp.get_dpnp_descriptor(input)
    if x1_desc:
        if x1_desc.shape[-1] == x1_desc.shape[-2]:
            result_obj = dpnp_det(x1_desc).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.linalg.det, input)
コード例 #16
0
def max(x1, axis=None, out=None, keepdims=False, initial=None, where=True):
    """
    Return the maximum of an array or maximum along an axis.

    Limitations
    -----------
    Input array is supported as :obj:`dpnp.ndarray`.
    Otherwise the function will be executed sequentially on CPU.
    Prameters ``out`` is supported only with default value ``None``.
    Input array data types are limited by supported DPNP :ref:`Data types`.

    Examples
    --------
    >>> import dpnp as np
    >>> a = np.arange(4).reshape((2,2))
    >>> a.shape
    (2, 2)
    >>> [i for i in a]
    [0, 1, 2, 3]
    >>> np.max(a)
    3

    """

    x1_desc = dpnp.get_dpnp_descriptor(x1)
    if x1_desc:
        # Negative values in 'shape' are not allowed in input array
        # 306-322 check on negative and duplicate axis
        isaxis = True
        if axis is not None:
            if dpnp.isscalar(axis):
                if axis < 0:
                    isaxis = False
            else:
                for val in axis:
                    if val < 0:
                        isaxis = False
                        break
                if isaxis:
                    for i in range(len(axis)):
                        for j in range(len(axis)):
                            if i != j:
                                if axis[i] == axis[j]:
                                    isaxis = False
                                    break

        if not isaxis:
            pass
        elif out is not None:
            pass
        elif keepdims:
            pass
        elif initial is not None:
            pass
        elif where is not True:
            pass
        else:
            result_obj = dpnp_max(x1_desc, axis).get_pyobj()
            result = dpnp.convert_single_elem_array_to_scalar(result_obj)

            return result

    return call_origin(numpy.max, x1, axis, out, keepdims, initial, where)