blob: 12a565b166478672f13018c536f5dbe6a5abe815 [file] [log] [blame]
Austin Schuh189376f2018-12-20 22:11:15 +11001namespace Eigen {
2
3/** \eigenManualPage CoeffwiseMathFunctions Catalog of coefficient-wise math functions
4
5
6<!-- <span style="font-size:300%; color:red; font-weight: 900;">!WORK IN PROGRESS!</span> -->
7
8This table presents a catalog of the coefficient-wise math functions supported by %Eigen.
9In this table, \c a, \c b, refer to Array objects or expressions, and \c m refers to a linear algebra Matrix/Vector object. Standard scalar types are abbreviated as follows:
10 - \c int: \c i32
11 - \c float: \c f
12 - \c double: \c d
13 - \c std::complex<float>: \c cf
14 - \c std::complex<double>: \c cd
15
16For each row, the first column list the equivalent calls for arrays, and matrices when supported. Of course, all functions are available for matrices by first casting it as an array: \c m.array().
17
18The third column gives some hints in the underlying scalar implementation. In most cases, %Eigen does not implement itself the math function but relies on the STL for standard scalar types, or user-provided functions for custom scalar types.
19For instance, some simply calls the respective function of the STL while preserving <a href="http://en.cppreference.com/w/cpp/language/adl">argument-dependent lookup</a> for custom types.
20The following:
21\code
22using std::foo;
23foo(a[i]);
24\endcode
25means that the STL's function \c std::foo will be potentially called if it is compatible with the underlying scalar type. If not, then the user must ensure that an overload of the function foo is available for the given scalar type (usually defined in the same namespace as the given scalar type).
26This also means that, unless specified, if the function \c std::foo is available only in some recent c++ versions (e.g., c++11), then the respective %Eigen's function/method will be usable on standard types only if the compiler support the required c++ version.
27
28<table class="manual-hl">
29<tr>
30<th>API</th><th>Description</th><th>Default scalar implementation</th><th>SIMD</th>
31</tr>
32<tr><td colspan="4"></td></tr>
33<tr><th colspan="4">Basic operations</th></tr>
34<tr>
35 <td class="code">
36 \anchor cwisetable_abs
37 a.\link ArrayBase::abs abs\endlink(); \n
38 \link Eigen::abs abs\endlink(a); \n
39 m.\link MatrixBase::cwiseAbs cwiseAbs\endlink();
40 </td>
41 <td>absolute value (\f$ |a_i| \f$) </td>
42 <td class="code">
43 using <a href="http://en.cppreference.com/w/cpp/numeric/math/fabs">std::abs</a>; \n
44 abs(a[i]);
45 </td>
46 <td>SSE2, AVX (i32,f,d)</td>
47</tr>
48<tr>
49 <td class="code">
50 \anchor cwisetable_inverse
51 a.\link ArrayBase::inverse inverse\endlink(); \n
52 \link Eigen::inverse inverse\endlink(a); \n
53 m.\link MatrixBase::cwiseInverse cwiseInverse\endlink();
54 </td>
55 <td>inverse value (\f$ 1/a_i \f$) </td>
56 <td class="code">
57 1/a[i];
58 </td>
59 <td>All engines (f,d,fc,fd)</td>
60</tr>
61<tr>
62 <td class="code">
63 \anchor cwisetable_conj
64 a.\link ArrayBase::conjugate conjugate\endlink(); \n
65 \link Eigen::conj conj\endlink(a); \n
66 m.\link MatrixBase::conjugate conjugate\endlink();
67 </td>
68 <td><a href="https://en.wikipedia.org/wiki/Complex_conjugate">complex conjugate</a> (\f$ \bar{a_i} \f$),\n
69 no-op for real </td>
70 <td class="code">
71 using <a href="http://en.cppreference.com/w/cpp/numeric/complex/conj">std::conj</a>; \n
72 conj(a[i]);
73 </td>
74 <td>All engines (fc,fd)</td>
75</tr>
76<tr>
77<th colspan="4">Exponential functions</th>
78</tr>
79<tr>
80 <td class="code">
81 \anchor cwisetable_exp
82 a.\link ArrayBase::exp exp\endlink(); \n
83 \link Eigen::exp exp\endlink(a);
84 </td>
85 <td>\f$ e \f$ raised to the given power (\f$ e^{a_i} \f$) </td>
86 <td class="code">
87 using <a href="http://en.cppreference.com/w/cpp/numeric/math/exp">std::exp</a>; \n
88 exp(a[i]);
89 </td>
90 <td>SSE2, AVX (f,d)</td>
91</tr>
92<tr>
93 <td class="code">
94 \anchor cwisetable_log
95 a.\link ArrayBase::log log\endlink(); \n
96 \link Eigen::log log\endlink(a);
97 </td>
98 <td>natural (base \f$ e \f$) logarithm (\f$ \ln({a_i}) \f$)</td>
99 <td class="code">
100 using <a href="http://en.cppreference.com/w/cpp/numeric/math/log">std::log</a>; \n
101 log(a[i]);
102 </td>
103 <td>SSE2, AVX (f)</td>
104</tr>
105<tr>
106 <td class="code">
107 \anchor cwisetable_log1p
108 a.\link ArrayBase::log1p log1p\endlink(); \n
109 \link Eigen::log1p log1p\endlink(a);
110 </td>
111 <td>natural (base \f$ e \f$) logarithm of 1 plus \n the given number (\f$ \ln({1+a_i}) \f$)</td>
112 <td>built-in generic implementation based on \c log,\n
113 plus \c using <a href="http://en.cppreference.com/w/cpp/numeric/math/log1p">\c std::log1p </a>; \cpp11</td>
114 <td></td>
115</tr>
116<tr>
117 <td class="code">
118 \anchor cwisetable_log10
119 a.\link ArrayBase::log10 log10\endlink(); \n
120 \link Eigen::log10 log10\endlink(a);
121 </td>
122 <td>base 10 logarithm (\f$ \log_{10}({a_i}) \f$)</td>
123 <td class="code">
124 using <a href="http://en.cppreference.com/w/cpp/numeric/math/log10">std::log10</a>; \n
125 log10(a[i]);
126 </td>
127 <td></td>
128</tr>
129<tr>
130<th colspan="4">Power functions</th>
131</tr>
132<tr>
133 <td class="code">
134 \anchor cwisetable_pow
135 a.\link ArrayBase::pow pow\endlink(b); \n
136 \link ArrayBase::pow(const Eigen::ArrayBase< Derived > &x, const Eigen::ArrayBase< ExponentDerived > &exponents) pow\endlink(a,b);
137 </td>
138 <!-- For some reason Doxygen thinks that pow is in ArrayBase namespace -->
139 <td>raises a number to the given power (\f$ a_i ^ {b_i} \f$) \n \c a and \c b can be either an array or scalar.</td>
140 <td class="code">
141 using <a href="http://en.cppreference.com/w/cpp/numeric/math/pow">std::pow</a>; \n
142 pow(a[i],b[i]);\n
143 (plus builtin for integer types)</td>
144 <td></td>
145</tr>
146<tr>
147 <td class="code">
148 \anchor cwisetable_sqrt
149 a.\link ArrayBase::sqrt sqrt\endlink(); \n
150 \link Eigen::sqrt sqrt\endlink(a);\n
151 m.\link MatrixBase::cwiseSqrt cwiseSqrt\endlink();
152 </td>
153 <td>computes square root (\f$ \sqrt a_i \f$)</td>
154 <td class="code">
155 using <a href="http://en.cppreference.com/w/cpp/numeric/math/sqrt">std::sqrt</a>; \n
156 sqrt(a[i]);</td>
157 <td>SSE2, AVX (f,d)</td>
158</tr>
159<tr>
160 <td class="code">
161 \anchor cwisetable_rsqrt
162 a.\link ArrayBase::rsqrt rsqrt\endlink(); \n
163 \link Eigen::rsqrt rsqrt\endlink(a);
164 </td>
165 <td><a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">reciprocal square root</a> (\f$ 1/{\sqrt a_i} \f$)</td>
166 <td class="code">
167 using <a href="http://en.cppreference.com/w/cpp/numeric/math/sqrt">std::sqrt</a>; \n
168 1/sqrt(a[i]); \n
169 </td>
170 <td>SSE2, AVX, AltiVec, ZVector (f,d)\n
171 (approx + 1 Newton iteration)</td>
172</tr>
173<tr>
174 <td class="code">
175 \anchor cwisetable_square
176 a.\link ArrayBase::square square\endlink(); \n
177 \link Eigen::square square\endlink(a);
178 </td>
179 <td>computes square power (\f$ a_i^2 \f$)</td>
180 <td class="code">
181 a[i]*a[i]</td>
182 <td>All (i32,f,d,cf,cd)</td>
183</tr>
184<tr>
185 <td class="code">
186 \anchor cwisetable_cube
187 a.\link ArrayBase::cube cube\endlink(); \n
188 \link Eigen::cube cube\endlink(a);
189 </td>
190 <td>computes cubic power (\f$ a_i^3 \f$)</td>
191 <td class="code">
192 a[i]*a[i]*a[i]</td>
193 <td>All (i32,f,d,cf,cd)</td>
194</tr>
195<tr>
196 <td class="code">
197 \anchor cwisetable_abs2
198 a.\link ArrayBase::abs2 abs2\endlink(); \n
199 \link Eigen::abs2 abs2\endlink(a);\n
200 m.\link MatrixBase::cwiseAbs2 cwiseAbs2\endlink();
201 </td>
202 <td>computes the squared absolute value (\f$ |a_i|^2 \f$)</td>
203 <td class="code">
204 real: a[i]*a[i] \n
205 complex: real(a[i])*real(a[i]) \n
206 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + imag(a[i])*imag(a[i])</td>
207 <td>All (i32,f,d)</td>
208</tr>
209<tr>
210<th colspan="4">Trigonometric functions</th>
211</tr>
212<tr>
213 <td class="code">
214 \anchor cwisetable_sin
215 a.\link ArrayBase::sin sin\endlink(); \n
216 \link Eigen::sin sin\endlink(a);
217 </td>
218 <td>computes sine</td>
219 <td class="code">
220 using <a href="http://en.cppreference.com/w/cpp/numeric/math/sin">std::sin</a>; \n
221 sin(a[i]);</td>
222 <td>SSE2, AVX (f)</td>
223</tr>
224<tr>
225 <td class="code">
226 \anchor cwisetable_cos
227 a.\link ArrayBase::cos cos\endlink(); \n
228 \link Eigen::cos cos\endlink(a);
229 </td>
230 <td>computes cosine</td>
231 <td class="code">
232 using <a href="http://en.cppreference.com/w/cpp/numeric/math/cos">std::cos</a>; \n
233 cos(a[i]);</td>
234 <td>SSE2, AVX (f)</td>
235</tr>
236<tr>
237 <td class="code">
238 \anchor cwisetable_tan
239 a.\link ArrayBase::tan tan\endlink(); \n
240 \link Eigen::tan tan\endlink(a);
241 </td>
242 <td>computes tangent</td>
243 <td class="code">
244 using <a href="http://en.cppreference.com/w/cpp/numeric/math/tan">std::tan</a>; \n
245 tan(a[i]);</td>
246 <td></td>
247</tr>
248<tr>
249 <td class="code">
250 \anchor cwisetable_asin
251 a.\link ArrayBase::asin asin\endlink(); \n
252 \link Eigen::asin asin\endlink(a);
253 </td>
254 <td>computes arc sine (\f$ \sin^{-1} a_i \f$)</td>
255 <td class="code">
256 using <a href="http://en.cppreference.com/w/cpp/numeric/math/asin">std::asin</a>; \n
257 asin(a[i]);</td>
258 <td></td>
259</tr>
260<tr>
261 <td class="code">
262 \anchor cwisetable_acos
263 a.\link ArrayBase::acos acos\endlink(); \n
264 \link Eigen::acos acos\endlink(a);
265 </td>
266 <td>computes arc cosine (\f$ \cos^{-1} a_i \f$)</td>
267 <td class="code">
268 using <a href="http://en.cppreference.com/w/cpp/numeric/math/acos">std::acos</a>; \n
269 acos(a[i]);</td>
270 <td></td>
271</tr>
272<tr>
273 <td class="code">
274 \anchor cwisetable_atan
275 a.\link ArrayBase::atan atan\endlink(); \n
276 \link Eigen::atan atan\endlink(a);
277 </td>
278 <td>computes arc tangent (\f$ \tan^{-1} a_i \f$)</td>
279 <td class="code">
280 using <a href="http://en.cppreference.com/w/cpp/numeric/math/atan">std::atan</a>; \n
281 atan(a[i]);</td>
282 <td></td>
283</tr>
284<tr>
285<th colspan="4">Hyperbolic functions</th>
286</tr>
287<tr>
288 <td class="code">
289 \anchor cwisetable_sinh
290 a.\link ArrayBase::sinh sinh\endlink(); \n
291 \link Eigen::sinh sinh\endlink(a);
292 </td>
293 <td>computes hyperbolic sine</td>
294 <td class="code">
295 using <a href="http://en.cppreference.com/w/cpp/numeric/math/sinh">std::sinh</a>; \n
296 sinh(a[i]);</td>
297 <td></td>
298</tr>
299<tr>
300 <td class="code">
301 \anchor cwisetable_cosh
302 a.\link ArrayBase::cosh cohs\endlink(); \n
303 \link Eigen::cosh cosh\endlink(a);
304 </td>
305 <td>computes hyperbolic cosine</td>
306 <td class="code">
307 using <a href="http://en.cppreference.com/w/cpp/numeric/math/cosh">std::cosh</a>; \n
308 cosh(a[i]);</td>
309 <td></td>
310</tr>
311<tr>
312 <td class="code">
313 \anchor cwisetable_tanh
314 a.\link ArrayBase::tanh tanh\endlink(); \n
315 \link Eigen::tanh tanh\endlink(a);
316 </td>
317 <td>computes hyperbolic tangent</td>
318 <td class="code">
319 using <a href="http://en.cppreference.com/w/cpp/numeric/math/tanh">std::tanh</a>; \n
320 tanh(a[i]);</td>
321 <td></td>
322</tr>
323<tr>
324<th colspan="4">Nearest integer floating point operations</th>
325</tr>
326<tr>
327 <td class="code">
328 \anchor cwisetable_ceil
329 a.\link ArrayBase::ceil ceil\endlink(); \n
330 \link Eigen::ceil ceil\endlink(a);
331 </td>
332 <td>nearest integer not less than the given value</td>
333 <td class="code">
334 using <a href="http://en.cppreference.com/w/cpp/numeric/math/ceil">std::ceil</a>; \n
335 ceil(a[i]);</td>
336 <td>SSE4,AVX,ZVector (f,d)</td>
337</tr>
338<tr>
339 <td class="code">
340 \anchor cwisetable_floor
341 a.\link ArrayBase::floor floor\endlink(); \n
342 \link Eigen::floor floor\endlink(a);
343 </td>
344 <td>nearest integer not greater than the given value</td>
345 <td class="code">
346 using <a href="http://en.cppreference.com/w/cpp/numeric/math/floor">std::floor</a>; \n
347 floor(a[i]);</td>
348 <td>SSE4,AVX,ZVector (f,d)</td>
349</tr>
350<tr>
351 <td class="code">
352 \anchor cwisetable_round
353 a.\link ArrayBase::round round\endlink(); \n
354 \link Eigen::round round\endlink(a);
355 </td>
356 <td>nearest integer, \n rounding away from zero in halfway cases</td>
357 <td>built-in generic implementation \n based on \c floor and \c ceil,\n
358 plus \c using <a href="http://en.cppreference.com/w/cpp/numeric/math/round">\c std::round </a>; \cpp11</td>
359 <td>SSE4,AVX,ZVector (f,d)</td>
360</tr>
361<tr>
362<th colspan="4">Floating point manipulation functions</th>
363</tr>
364<tr>
365<th colspan="4">Classification and comparison</th>
366</tr>
367<tr>
368 <td class="code">
369 \anchor cwisetable_isfinite
370 a.\link ArrayBase::isFinite isFinite\endlink(); \n
371 \link Eigen::isfinite isfinite\endlink(a);
372 </td>
373 <td>checks if the given number has finite value</td>
374 <td>built-in generic implementation,\n
375 plus \c using <a href="http://en.cppreference.com/w/cpp/numeric/math/isfinite">\c std::isfinite </a>; \cpp11</td>
376 <td></td>
377</tr>
378<tr>
379 <td class="code">
380 \anchor cwisetable_isinf
381 a.\link ArrayBase::isInf isInf\endlink(); \n
382 \link Eigen::isinf isinf\endlink(a);
383 </td>
384 <td>checks if the given number is infinite</td>
385 <td>built-in generic implementation,\n
386 plus \c using <a href="http://en.cppreference.com/w/cpp/numeric/math/isinf">\c std::isinf </a>; \cpp11</td>
387 <td></td>
388</tr>
389<tr>
390 <td class="code">
391 \anchor cwisetable_isnan
392 a.\link ArrayBase::isNaN isNaN\endlink(); \n
393 \link Eigen::isnan isnan\endlink(a);
394 </td>
395 <td>checks if the given number is not a number</td>
396 <td>built-in generic implementation,\n
397 plus \c using <a href="http://en.cppreference.com/w/cpp/numeric/math/isnan">\c std::isnan </a>; \cpp11</td>
398 <td></td>
399</tr>
400<tr>
401<th colspan="4">Error and gamma functions</th>
402</tr>
403<tr> <td colspan="4"> Require \c \#include \c <unsupported/Eigen/SpecialFunctions> </td></tr>
404<tr>
405 <td class="code">
406 \anchor cwisetable_erf
407 a.\link ArrayBase::erf erf\endlink(); \n
408 \link Eigen::erf erf\endlink(a);
409 </td>
410 <td>error function</td>
411 <td class="code">
412 using <a href="http://en.cppreference.com/w/cpp/numeric/math/erf">std::erf</a>; \cpp11 \n
413 erf(a[i]);
414 </td>
415 <td></td>
416</tr>
417<tr>
418 <td class="code">
419 \anchor cwisetable_erfc
420 a.\link ArrayBase::erfc erfc\endlink(); \n
421 \link Eigen::erfc erfc\endlink(a);
422 </td>
423 <td>complementary error function</td>
424 <td class="code">
425 using <a href="http://en.cppreference.com/w/cpp/numeric/math/erfc">std::erfc</a>; \cpp11 \n
426 erfc(a[i]);
427 </td>
428 <td></td>
429</tr>
430<tr>
431 <td class="code">
432 \anchor cwisetable_lgamma
433 a.\link ArrayBase::lgamma lgamma\endlink(); \n
434 \link Eigen::lgamma lgamma\endlink(a);
435 </td>
436 <td>natural logarithm of the gamma function</td>
437 <td class="code">
438 using <a href="http://en.cppreference.com/w/cpp/numeric/math/lgamma">std::lgamma</a>; \cpp11 \n
439 lgamma(a[i]);
440 </td>
441 <td></td>
442</tr>
443<tr>
444 <td class="code">
445 \anchor cwisetable_digamma
446 a.\link ArrayBase::digamma digamma\endlink(); \n
447 \link Eigen::digamma digamma\endlink(a);
448 </td>
449 <td><a href="https://en.wikipedia.org/wiki/Digamma_function">logarithmic derivative of the gamma function</a></td>
450 <td>
451 built-in for float and double
452 </td>
453 <td></td>
454</tr>
455<tr>
456 <td class="code">
457 \anchor cwisetable_igamma
458 \link Eigen::igamma igamma\endlink(a,x);
459 </td>
460 <td><a href="https://en.wikipedia.org/wiki/Incomplete_gamma_function">lower incomplete gamma integral</a>
461 \n \f$ \gamma(a_i,x_i)= \frac{1}{|a_i|} \int_{0}^{x_i}e^{\text{-}t} t^{a_i-1} \mathrm{d} t \f$</td>
462 <td>
463 built-in for float and double,\n but requires \cpp11
464 </td>
465 <td></td>
466</tr>
467<tr>
468 <td class="code">
469 \anchor cwisetable_igammac
470 \link Eigen::igammac igammac\endlink(a,x);
471 </td>
472 <td><a href="https://en.wikipedia.org/wiki/Incomplete_gamma_function">upper incomplete gamma integral</a>
473 \n \f$ \Gamma(a_i,x_i) = \frac{1}{|a_i|} \int_{x_i}^{\infty}e^{\text{-}t} t^{a_i-1} \mathrm{d} t \f$</td>
474 <td>
475 built-in for float and double,\n but requires \cpp11
476 </td>
477 <td></td>
478</tr>
479<tr>
480<th colspan="4">Special functions</th>
481</tr>
482<tr> <td colspan="4"> Require \c \#include \c <unsupported/Eigen/SpecialFunctions> </td></tr>
483<tr>
484 <td class="code">
485 \anchor cwisetable_polygamma
486 \link Eigen::polygamma polygamma\endlink(n,x);
487 </td>
488 <td><a href="https://en.wikipedia.org/wiki/Polygamma_function">n-th derivative of digamma at x</a></td>
489 <td>
490 built-in generic based on\n <a href="#cwisetable_lgamma">\c lgamma </a>,
491 <a href="#cwisetable_digamma"> \c digamma </a>
492 and <a href="#cwisetable_zeta">\c zeta </a>.
493 </td>
494 <td></td>
495</tr>
496<tr>
497 <td class="code">
498 \anchor cwisetable_betainc
499 \link Eigen::betainc betainc\endlink(a,b,x);
500 </td>
501 <td><a href="https://en.wikipedia.org/wiki/Beta_function#Incomplete_beta_function">Incomplete beta function</a></td>
502 <td>
503 built-in for float and double,\n but requires \cpp11
504 </td>
505 <td></td>
506</tr>
507<tr>
508 <td class="code">
509 \anchor cwisetable_zeta
510 \link Eigen::zeta zeta\endlink(a,b);
511 </td>
512 <td><a href="https://en.wikipedia.org/wiki/Hurwitz_zeta_function">Hurwitz zeta function</a>
513 \n \f$ \zeta(a_i,b_i)=\sum_{k=0}^{\infty}(b_i+k)^{\text{-}a_i} \f$</td>
514 <td>
515 built-in for float and double
516 </td>
517 <td></td>
518</tr>
519<tr><td colspan="4"></td></tr>
520</table>
521
522\n
523
524*/
525
526}