@@ -878,7 +878,8 @@ def cumlogsumexp(
878
878
Parameters
879
879
----------
880
880
x : {dpnp.ndarray, usm_ndarray}
881
- Input array, expected to have a boolean or real-valued data type.
881
+ Input array, expected to have a boolean or real-valued floating-point
882
+ data type.
882
883
axis : {None, int}, optional
883
884
Axis or axes along which values must be computed. If a tuple of unique
884
885
integers, values are computed over multiple axes. If ``None``, the
@@ -924,15 +925,15 @@ def cumlogsumexp(
924
925
has the data type as described in the `dtype` parameter description
925
926
above.
926
927
927
- Note
928
- ----
929
- This function is equivalent of `numpy.logaddexp.accumulate`.
930
-
931
928
See Also
932
929
--------
933
930
:obj:`dpnp.logsumexp` : Logarithm of the sum of elements of the inputs,
934
931
element-wise.
935
932
933
+ Note
934
+ ----
935
+ This function is equivalent of `numpy.logaddexp.accumulate`.
936
+
936
937
Examples
937
938
--------
938
939
>>> import dpnp as np
@@ -1667,13 +1668,10 @@ def cumlogsumexp(
1667
1668
)
1668
1669
1669
1670
1670
- _LOGADDEXP_DOCSTRING = """
1671
- Calculates the natural logarithm of the sum of exponents for each element `x1_i`
1672
- of the input array `x1` with the respective element `x2_i` of the input
1673
- array `x2`.
1674
-
1675
- This function calculates `log(exp(x1) + exp(x2))` more accurately for small
1676
- values of `x`.
1671
+ _LOGADDEXP_DOCSTRING = r"""
1672
+ Calculates the natural logarithm of the sum of exponentiations
1673
+ :math:`\log(e^{x1} + e^{x2})` for each element :math:`x1_i` of the input array
1674
+ `x1` with the respective element :math:`x2_i` of the input array `x2`.
1677
1675
1678
1676
For full documentation refer to :obj:`numpy.logaddexp`.
1679
1677
@@ -1682,13 +1680,9 @@ def cumlogsumexp(
1682
1680
x1 : {dpnp.ndarray, usm_ndarray, scalar}
1683
1681
First input array, expected to have a real-valued floating-point
1684
1682
data type.
1685
- Both inputs `x1` and `x2` can not be scalars at the same time.
1686
1683
x2 : {dpnp.ndarray, usm_ndarray, scalar}
1687
- Second input array, also expected to have a real-valued
1688
- floating-point data type.
1689
- Both inputs `x1` and `x2` can not be scalars at the same time.
1690
- If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1691
- (which becomes the shape of the output).
1684
+ Second input array, also expected to have a real-valued floating-point data
1685
+ type.
1692
1686
out : {None, dpnp.ndarray, usm_ndarray}, optional
1693
1687
Output array to populate.
1694
1688
Array must have the correct shape and the expected data type.
@@ -1702,8 +1696,8 @@ def cumlogsumexp(
1702
1696
Returns
1703
1697
-------
1704
1698
out : dpnp.ndarray
1705
- An array containing the element-wise results. The data type
1706
- of the returned array is determined by the Type Promotion Rules.
1699
+ An array containing the element-wise results. The data type of the returned
1700
+ array is determined by the Type Promotion Rules.
1707
1701
1708
1702
Limitations
1709
1703
-----------
@@ -1713,12 +1707,23 @@ def cumlogsumexp(
1713
1707
1714
1708
See Also
1715
1709
--------
1716
- :obj:`dpnp.log` : Natural logarithm, element-wise.
1717
- :obj:`dpnp.exp` : Exponential, element-wise.
1718
- :obj:`dpnp.logaddexp2`: Logarithm of the sum of exponentiation of inputs in
1719
- base-2, element-wise.
1720
- :obj:`dpnp.logsumexp` : Logarithm of the sum of exponents of elements in the
1721
- input array.
1710
+ :obj:`dpnp.log` : Calculate :math:`\log(x)`, element-wise.
1711
+ :obj:`dpnp.exp` : Calculate :math:`e^x`, element-wise.
1712
+ :obj:`dpnp.logaddexp2`: Calculate :math:`\log_2(2^{x1} + 2^{x2})`, element-wise.
1713
+ :obj:`dpnp.logsumexp` : Logarithm of the sum of exponentials of elements in the
1714
+ input array.
1715
+
1716
+ Notes
1717
+ -----
1718
+ At least one of `x1` or `x2` must be an array.
1719
+
1720
+ If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1721
+ (which becomes the shape of the output).
1722
+
1723
+ This function is useful in statistics where the calculated probabilities of
1724
+ events may be so small as to exceed the range of normal floating-point numbers.
1725
+ In such cases the natural logarithm of the calculated probability is stored.
1726
+ This function allows adding probabilities stored in such a fashion.
1722
1727
1723
1728
Examples
1724
1729
--------
@@ -1741,16 +1746,10 @@ def cumlogsumexp(
1741
1746
)
1742
1747
1743
1748
1744
- _LOGADDEXP2_DOCSTRING = """
1745
- Calculates the logarithm of the sum of exponents in base-2 for each element
1746
- `x1_i` of the input array `x1` with the respective element `x2_i` of the input
1747
- array `x2`.
1748
-
1749
- This function calculates `log2(2**x1 + 2**x2)`. It is useful in machine
1750
- learning when the calculated probabilities of events may be so small as
1751
- to exceed the range of normal floating point numbers. In such cases the base-2
1752
- logarithm of the calculated probability can be used instead. This function
1753
- allows adding probabilities stored in such a fashion.
1749
+ _LOGADDEXP2_DOCSTRING = r"""
1750
+ Calculates the base-2 logarithm of the sum of exponentiations
1751
+ :math:`\log_2(2^{x1} + 2^{x2})` for each element :math:`x1_i` of the input
1752
+ array `x1` with the respective element :math:`x2_i` of the input array `x2`.
1754
1753
1755
1754
For full documentation refer to :obj:`numpy.logaddexp2`.
1756
1755
@@ -1759,13 +1758,9 @@ def cumlogsumexp(
1759
1758
x1 : {dpnp.ndarray, usm_ndarray, scalar}
1760
1759
First input array, expected to have a real-valued floating-point
1761
1760
data type.
1762
- Both inputs `x1` and `x2` can not be scalars at the same time.
1763
1761
x2 : {dpnp.ndarray, usm_ndarray, scalar}
1764
- Second input array, also expected to have a real-valued
1765
- floating-point data type.
1766
- Both inputs `x1` and `x2` can not be scalars at the same time.
1767
- If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1768
- (which becomes the shape of the output).
1762
+ Second input array, also expected to have a real-valued floating-point data
1763
+ type.
1769
1764
out : {None, dpnp.ndarray, usm_ndarray}, optional
1770
1765
Output array to populate.
1771
1766
Array must have the correct shape and the expected data type.
@@ -1790,9 +1785,22 @@ def cumlogsumexp(
1790
1785
1791
1786
See Also
1792
1787
--------
1793
- :obj:`dpnp.logaddexp`: Natural logarithm of the sum of exponentiation of
1794
- inputs, element-wise.
1795
- :obj:`dpnp.logsumexp` : Logarithm of the sum of exponentiation of the inputs.
1788
+ :obj:`dpnp.logaddexp`: Calculate :math:`\log(e^{x1} + e^{x2})`, element-wise.
1789
+ :obj:`dpnp.logsumexp` : Logarithm of the sum of exponentials of elements in the
1790
+ input array.
1791
+
1792
+ Notes
1793
+ -----
1794
+ At least one of `x1` or `x2` must be an array.
1795
+
1796
+ If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1797
+ (which becomes the shape of the output).
1798
+
1799
+ This function is useful in machine learning when the calculated probabilities
1800
+ of events may be so small as to exceed the range of normal floating-point
1801
+ numbers. In such cases the base-2 logarithm of the calculated probability can
1802
+ be used instead. This function allows adding probabilities stored in such a
1803
+ fashion.
1796
1804
1797
1805
Examples
1798
1806
--------
@@ -1816,14 +1824,15 @@ def cumlogsumexp(
1816
1824
1817
1825
1818
1826
def logsumexp (x , / , * , axis = None , dtype = None , keepdims = False , out = None ):
1819
- """
1820
- Calculates the logarithm of the sum of exponents of elements in
1827
+ r """
1828
+ Calculates the natural logarithm of the sum of exponentials of elements in
1821
1829
the input array.
1822
1830
1823
1831
Parameters
1824
1832
----------
1825
1833
x : {dpnp.ndarray, usm_ndarray}
1826
- Input array, expected to have a real-valued floating-point data type.
1834
+ Input array, expected to have a boolean or real-valued floating-point
1835
+ data type.
1827
1836
axis : {None, int or tuple of ints}, optional
1828
1837
Axis or axes along which values must be computed. If a tuple of unique
1829
1838
integers, values are computed over multiple axes. If ``None``, the
@@ -1868,19 +1877,21 @@ def logsumexp(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
1868
1877
has the data type as described in the `dtype` parameter description
1869
1878
above.
1870
1879
1880
+ See Also
1881
+ --------
1882
+ :obj:`dpnp.log` : Calculate :math:`\log(x)`, element-wise.
1883
+ :obj:`dpnp.exp` : Calculate :math:`e^x`, element-wise.
1884
+ :obj:`dpnp.logaddexp`: Calculate :math:`\log(e^{x1} + e^{x2})`,
1885
+ element-wise.
1886
+ :obj:`dpnp.logaddexp2`: Calculate :math:`\log_2(2^{x1} + 2^{x2})`,
1887
+ element-wise.
1888
+ :obj:`dpnp.cumlogsumexp` : Cumulative the natural logarithm of the sum of
1889
+ elements in the input array.
1890
+
1871
1891
Note
1872
1892
----
1873
1893
This function is equivalent of `numpy.logaddexp.reduce`.
1874
1894
1875
- See Also
1876
- --------
1877
- :obj:`dpnp.log` : Natural logarithm, element-wise.
1878
- :obj:`dpnp.exp` : Exponential, element-wise.
1879
- :obj:`dpnp.logaddexp` : Logarithm of the sum of exponents of
1880
- the inputs, element-wise.
1881
- :obj:`dpnp.logaddexp2` : Logarithm of the sum of exponents of
1882
- the inputs in base-2, element-wise.
1883
-
1884
1895
Examples
1885
1896
--------
1886
1897
>>> import dpnp as np
0 commit comments