:mod:`heat.rounding` ========================= .. py:module:: heat.core.rounding .. autoapi-nested-parse:: Rounding functions for DNDarrays Module Contents --------------- .. function:: abs(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None, dtype: Optional[Type[heat.core.types.datatype]] = None) -> heat.core.dndarray.DNDarray Returns :class:`~heat.core.dndarray.DNDarray` containing the elementwise abolute values of the input array ``x``. :param x: The array for which the compute the absolute value. :type x: DNDarray :param out: A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or ``None``, a freshly-allocated array is returned. :type out: DNDarray, optional :param dtype: Determines the data type of the output array. The values are cast to this type with potential loss of precision. :type dtype: datatype, optional :raises TypeError: If dtype is not a heat type. .. function:: absolute(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None, dtype: Optional[Type[heat.core.types.datatype]] = None) -> heat.core.dndarray.DNDarray Calculate the absolute value element-wise. :func:`abs` is a shorthand for this function. :param x: The array for which the compute the absolute value. :type x: DNDarray :param out: A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or ``None``, a freshly-allocated array is returned. :type out: DNDarray, optional :param dtype: Determines the data type of the output array. The values are cast to this type with potential loss of precision. :type dtype: datatype, optional .. function:: ceil(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Return the ceil of the input, element-wise. Result is a :class:`~heat.core.dndarray.DNDarray` of the same shape as ``x``. The ceil of the scalar ``x`` is the smallest integer i, such that ``i>=x``. It is often denoted as :math:`\lceil x \rceil`. :param x: The value for which to compute the ceiled values. :type x: DNDarray :param out: A location in which to store the results. If provided, it must have a broadcastable shape. If not provided or set to ``None``, a fresh array is allocated. :type out: DNDarray, optional .. rubric:: Examples >>> import heat as ht >>> ht.ceil(ht.arange(-2.0, 2.0, 0.4)) DNDarray([-2., -1., -1., -0., -0., 0., 1., 1., 2., 2.], dtype=ht.float32, device=cpu:0, split=None) .. function:: clip(x: heat.core.dndarray.DNDarray, min, max, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Returns a :class:`~heat.core.dndarray.DNDarray` with the elements of this array, but where values ``a_max`` with ``a_max``. :param x: Array containing elements to clip. :type x: DNDarray :param min: Minimum value. If ``None``, clipping is not performed on lower interval edge. Not more than one of ``a_min`` and ``a_max`` may be ``None``. :type min: scalar or None :param max: Maximum value. If ``None``, clipping is not performed on upper interval edge. Not more than one of ``a_min`` and ``a_max`` may be None. :type max: scalar or None :param out: The results will be placed in this array. It may be the input array for in-place clipping. ``out`` must be of the right shape to hold the output. Its type is preserved. :type out: DNDarray, optional :raises ValueError: if either min or max is not set .. function:: fabs(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Calculate the absolute value element-wise and return floating-point class:`~heat.core.dndarray.DNDarray`. This function exists besides ``abs==absolute`` since it will be needed in case complex numbers will be introduced in the future. :param x: The array for which the compute the absolute value. :type x: DNDarray :param out: A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or ``None``, a freshly-allocated array is returned. :type out: DNDarray, optional .. function:: floor(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Return the floor of the input, element-wise. The floor of the scalar ``x`` is the largest integer i, such that ``i<=x``. It is often denoted as :math:`\lfloor x \rfloor`. :param x: The array for which to compute the floored values. :type x: DNDarray :param out: A location in which to store the results. If provided, it must have a broadcastable shape. If not provided or set to ``None``, a fresh :class:`~heat.core.dndarray.DNDarray` is allocated. :type out: DNDarray, optional .. rubric:: Examples >>> import heat as ht >>> ht.floor(ht.arange(-2.0, 2.0, 0.4)) DNDarray([-2., -2., -2., -1., -1., 0., 0., 0., 1., 1.], dtype=ht.float32, device=cpu:0, split=None) .. function:: modf(x: heat.core.dndarray.DNDarray, out: Optional[Tuple[heat.core.dndarray.DNDarray, heat.core.dndarray.DNDarray]] = None) -> Tuple[heat.core.dndarray.DNDarray, heat.core.dndarray.DNDarray] Return the fractional and integral parts of a :class:`~heat.core.dndarray.DNDarray`, element-wise. The fractional and integral parts are negative if the given number is negative. :param x: Input array :type x: DNDarray :param out: A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or ``None``, a freshly-allocated array is returned. :type out: Tuple[DNDarray, DNDarray], optional :raises TypeError: if ``x`` is not a :class:`~heat.core.dndarray.DNDarray` :raises TypeError: if ``out`` is not None or a tuple of :class:`~heat.core.dndarray.DNDarray` :raises ValueError: if ``out`` is a tuple of length unqual 2 .. rubric:: Examples >>> import heat as ht >>> ht.modf(ht.arange(-2.0, 2.0, 0.4)) (DNDarray([ 0.0000, -0.6000, -0.2000, -0.8000, -0.4000, 0.0000, 0.4000, 0.8000, 0.2000, 0.6000], dtype=ht.float32, device=cpu:0, split=None), DNDarray([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.], dtype=ht.float32, device=cpu:0, split=None)) .. function:: round(x: heat.core.dndarray.DNDarray, decimals: int = 0, out: Optional[heat.core.dndarray.DNDarray] = None, dtype: Optional[Type[heat.core.types.datatype]] = None) -> heat.core.dndarray.DNDarray Calculate the rounded value element-wise. :param x: The array for which the compute the rounded value. :type x: DNDarray :param decimals: Number of decimal places to round to. If decimals is negative, it specifies the number of positions to the left of the decimal point. :type decimals: int, optional :param out: A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or ``None``, a freshly-allocated array is returned. :type out: DNDarray, optional :param dtype: Determines the data type of the output array. The values are cast to this type with potential loss of precision. :type dtype: datatype, optional :raises TypeError: if dtype is not a heat data type .. rubric:: Examples >>> import heat as ht >>> ht.round(ht.arange(-2.0, 2.0, 0.4)) DNDarray([-2., -2., -1., -1., -0., 0., 0., 1., 1., 2.], dtype=ht.float32, device=cpu:0, split=None) .. function:: sgn(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Returns an indication of the sign of a number, element-wise. The definition for complex values is equivalent to :math:`x / |x|`. :param x: Input array :type x: DNDarray :param out: A location in which to store the results. :type out: DNDarray, optional .. seealso:: :func:`sign` Equivalent function on non-complex arrays. The definition for complex values is equivalent to :math:`x / \sqrt{x \cdot x}` .. rubric:: Examples >>> a = ht.array([-1, -0.5, 0, 0.5, 1]) >>> ht.sign(a) DNDarray([-1., -1., 0., 1., 1.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.sgn(ht.array([5 - 2j, 3 + 4j])) DNDarray([(0.9284766912460327-0.3713906705379486j), (0.6000000238418579+0.800000011920929j)], dtype=ht.complex64, device=cpu:0, split=None) .. function:: sign(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Returns an indication of the sign of a number, element-wise. The definition for complex values is equivalent to :math:`x / \sqrt{x \cdot x}`. :param x: Input array :type x: DNDarray :param out: A location in which to store the results. :type out: DNDarray, optional .. seealso:: :func:`sgn` Equivalent function on non-complex arrays. The definition for complex values is equivalent to :math:`x / |x|`. .. rubric:: Examples >>> a = ht.array([-1, -0.5, 0, 0.5, 1]) >>> ht.sign(a) DNDarray([-1., -1., 0., 1., 1.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.sign(ht.array([5 - 2j, 3 + 4j])) DNDarray([(1+0j), (1+0j)], dtype=ht.complex64, device=cpu:0, split=None) .. function:: trunc(x: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Return the trunc of the input, element-wise. The truncated value of the scalar ``x`` is the nearest integer ``i`` which is closer to zero than ``x`` is. In short, the fractional part of the signed number ``x`` is discarded. :param x: The array for which to compute the trunced values. :type x: DNDarray :param out: A location in which to store the results. If provided, it must have a broadcastable shape. If not provided or set to ``None``, a fresh array is allocated. :type out: DNDarray, optional .. rubric:: Examples >>> import heat as ht >>> ht.trunc(ht.arange(-2.0, 2.0, 0.4)) DNDarray([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.], dtype=ht.float32, device=cpu:0, split=None)