"vscode:/vscode.git/clone" did not exist on "d3832368d74c4e10ded1bf0cd62ec90509ba57b0"
ufunc.rst 3.12 KB
Newer Older
root's avatar
root committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Universal functions (:class:`cupy.ufunc`)
=========================================

.. Hint:: `NumPy API Reference: Universal functions (numpy.ufunc) <https://numpy.org/doc/stable/reference/ufuncs.html>`_

.. currentmodule:: cupy

CuPy provides universal functions (a.k.a. ufuncs) to support various elementwise operations.
CuPy's ufunc supports following features of NumPy's one:

- Broadcasting
- Output type determination
- Casting rules


ufunc
-----

.. autosummary::
   :toctree: generated/

   ufunc

Methods
~~~~~~~

These methods are only available for selected ufuncs.

* :meth:`ufunc.reduce <cupy.ufunc.reduce>`: :func:`~cupy.add`, :func:`~cupy.multiply`
* :meth:`ufunc.accumulate <cupy.ufunc.accumulate>`: :func:`~cupy.add`, :func:`~cupy.multiply`
* :meth:`ufunc.reduceat <ufunc.reduceat>`: :func:`~cupy.add`
* :meth:`ufunc.outer <cupy.ufunc.outer>`: All ufuncs
* :meth:`ufunc.at <cupy.ufunc.at>`: :func:`~cupy.add`, :func:`~cupy.subtract`, :func:`~cupy.maximum`, :func:`~cupy.minimum`, :func:`~cupy.bitwise_and`, :func:`~cupy.bitwise_or`, :func:`~cupy.bitwise_xor`

.. hint::

   In case you need support for other ufuncs, submit a feature request along with your use-case in `the tracker issue <https://github.com/cupy/cupy/issues/7082>`_.


Available ufuncs
----------------

Math operations
~~~~~~~~~~~~~~~

.. autosummary::
   :toctree: generated/

   add
   subtract
   multiply
   matmul
   divide
   logaddexp
   logaddexp2
   true_divide
   floor_divide
   negative
   positive
   power
   float_power
   remainder
   mod
   fmod
   divmod
   absolute
   fabs
   rint
   sign
   heaviside
   conj
   conjugate
   exp
   exp2
   log
   log2
   log10
   expm1
   log1p
   sqrt
   square
   cbrt
   reciprocal
   gcd
   lcm


Trigonometric functions
~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
   :toctree: generated/

   sin
   cos
   tan
   arcsin
   arccos
   arctan
   arctan2
   hypot
   sinh
   cosh
   tanh
   arcsinh
   arccosh
   arctanh
   degrees
   radians
   deg2rad
   rad2deg


Bit-twiddling functions
~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
   :toctree: generated/

   bitwise_and
   bitwise_or
   bitwise_xor
   invert
   left_shift
   right_shift


Comparison functions
~~~~~~~~~~~~~~~~~~~~

.. autosummary::
   :toctree: generated/

   greater
   greater_equal
   less
   less_equal
   not_equal
   equal
   logical_and
   logical_or
   logical_xor
   logical_not
   maximum
   minimum
   fmax
   fmin


Floating functions
~~~~~~~~~~~~~~~~~~

.. autosummary::
   :toctree: generated/

   isfinite
   isinf
   isnan
   fabs
   signbit
   copysign
   nextafter
   modf
   ldexp
   frexp
   fmod
   floor
   ceil
   trunc


Generalized Universal Functions
-------------------------------

.. currentmodule:: cupyx

In addition to regular ufuncs, CuPy also provides a wrapper class to convert
regular cupy functions into Generalized Universal Functions as in NumPy `<https://numpy.org/doc/stable/reference/c-api/generalized-ufuncs.html>`_.
This allows to automatically use keyword arguments such as ``axes``, ``order``, ``dtype``
without needing to explicitly implement them in the wrapped function.


.. autosummary::
   :toctree: generated/

   GeneralizedUFunc