A high-performance general-purpose compute library
arith.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2025, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#include <af/defines.h>
11
12#ifdef __cplusplus
13namespace af
14{
15 class array;
16
24 AFAPI array min (const array &lhs, const array &rhs);
25
34 AFAPI array min (const array &lhs, const double rhs);
35
44 AFAPI array min (const double lhs, const array &rhs);
45
53 AFAPI array max (const array &lhs, const array &rhs);
54
63 AFAPI array max (const array &lhs, const double rhs);
64
73 AFAPI array max (const double lhs, const array &rhs);
74
75#if AF_API_VERSION >= 34
85 AFAPI array clamp(const array &in, const array &lo, const array &hi);
86#endif
87
88#if AF_API_VERSION >= 34
90 AFAPI array clamp(const array &in, const array &lo, const double hi);
91#endif
92
93#if AF_API_VERSION >= 34
95 AFAPI array clamp(const array &in, const double lo, const array &hi);
96#endif
97
98#if AF_API_VERSION >= 34
100 AFAPI array clamp(const array &in, const double lo, const double hi);
101#endif
103
115 AFAPI array rem (const array &lhs, const array &rhs);
116
118 AFAPI array rem (const array &lhs, const double rhs);
119
121 AFAPI array rem (const double lhs, const array &rhs);
123
135 AFAPI array mod (const array &lhs, const array &rhs);
136
138 AFAPI array mod (const array &lhs, const double rhs);
139
141 AFAPI array mod (const double lhs, const array &rhs);
143
150 AFAPI array abs (const array &in);
151
159 AFAPI array arg (const array &in);
160
167 AFAPI array sign (const array &in);
168
175 AFAPI array round (const array &in);
176
183 AFAPI array trunc (const array &in);
184
191 AFAPI array floor (const array &in);
192
199 AFAPI array ceil (const array &in);
200
211 AFAPI array hypot (const array &lhs, const array &rhs);
212
214 AFAPI array hypot (const array &lhs, const double rhs);
215
217 AFAPI array hypot (const double lhs, const array &rhs);
219
226 AFAPI array sin (const array &in);
227
234 AFAPI array cos (const array &in);
235
242 AFAPI array tan (const array &in);
243
250 AFAPI array asin (const array &in);
251
258 AFAPI array acos (const array &in);
259
266 AFAPI array atan (const array &in);
267
275 AFAPI array atan2 (const array &lhs, const array &rhs);
276
278 AFAPI array atan2 (const array &lhs, const double rhs);
279
281 AFAPI array atan2 (const double lhs, const array &rhs);
283
290 AFAPI array sinh(const array& in);
291
298 AFAPI array cosh(const array& in);
299
306 AFAPI array tanh(const array& in);
307
314 AFAPI array asinh(const array& in);
315
322 AFAPI array acosh(const array& in);
323
330 AFAPI array atanh(const array& in);
331
339
347 AFAPI array complex(const array &real_, const array &imag_);
348
357 AFAPI array complex(const array &real_, const double imag_);
358
367 AFAPI array complex(const double real_, const array &imag_);
369
376 AFAPI array real (const array &in);
377
384 AFAPI array imag (const array &in);
385
392 AFAPI array conjg (const array &in);
393
401 AFAPI array root (const array &nth_root, const array &value);
402
410 AFAPI array root (const array &nth_root, const double value);
411
419 AFAPI array root (const double nth_root, const array &value);
420
431 AFAPI array pow (const array &base, const array &exponent);
432
434 AFAPI array pow (const array &base, const double exponent);
435
437 AFAPI array pow (const double base, const array &exponent);
438
443 AFAPI array pow2 (const array &in);
445
446#if AF_API_VERSION >= 31
456#endif
457
464 AFAPI array exp (const array &in);
465
475 AFAPI array expm1 (const array &in);
476
483 AFAPI array erf (const array &in);
484
491 AFAPI array erfc (const array &in);
492
499 AFAPI array log (const array &in);
500
510 AFAPI array log1p (const array &in);
511
518 AFAPI array log10 (const array &in);
519
526 AFAPI array log2 (const array &in);
527
534 AFAPI array sqrt (const array &in);
535
536#if AF_API_VERSION >= 37
543 AFAPI array rsqrt (const array &in);
544#endif
545
552 AFAPI array cbrt (const array &in);
553
561
568 AFAPI array tgamma (const array &in);
569
577 AFAPI array lgamma (const array &in);
578
585 AFAPI array iszero (const array &in);
586
594 AFAPI array isInf (const array &in);
595
602 AFAPI array isNaN (const array &in);
603}
604#endif
605
606#ifdef __cplusplus
607extern "C" {
608#endif
609
622 AFAPI af_err af_add (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
623
636 AFAPI af_err af_sub (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
637
650 AFAPI af_err af_mul (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
651
664 AFAPI af_err af_div (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
665
681 AFAPI af_err af_lt (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
682
698 AFAPI af_err af_gt (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
699
715 AFAPI af_err af_le (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
716
732 AFAPI af_err af_ge (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
733
748 AFAPI af_err af_eq (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
749
765 AFAPI af_err af_neq (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
766
781 AFAPI af_err af_and (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
782
797 AFAPI af_err af_or (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
798
812
813#if AF_API_VERSION >= 38
825#endif
826
839 AFAPI af_err af_bitand (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
840
853 AFAPI af_err af_bitor (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
854
867 AFAPI af_err af_bitxor (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
868
881 AFAPI af_err af_bitshiftl(af_array *out, const af_array lhs, const af_array rhs, const bool batch);
882
895 AFAPI af_err af_bitshiftr(af_array *out, const af_array lhs, const af_array rhs, const bool batch);
896
940 AFAPI af_err af_cast (af_array *out, const af_array in, const af_dtype type);
941
954 AFAPI af_err af_minof (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
955
969 AFAPI af_err af_maxof (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
970
971#if AF_API_VERSION >= 34
986 const af_array lo, const af_array hi, const bool batch);
987#endif
988
1004 AFAPI af_err af_rem (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
1005
1021 AFAPI af_err af_mod (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
1022
1034
1047
1059
1071
1083
1095
1107
1120 AFAPI af_err af_hypot (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
1121
1133
1145
1157
1169
1181
1193
1206 AFAPI af_err af_atan2 (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
1207
1219
1231
1243
1255
1267
1279
1291
1306 AFAPI af_err af_cplx2(af_array* out, const af_array real, const af_array imag, const bool batch);
1307
1319
1331
1343
1356 AFAPI af_err af_root (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
1357
1358
1371 AFAPI af_err af_pow (af_array *out, const af_array lhs, const af_array rhs, const bool batch);
1372
1384
1385#if AF_API_VERSION >= 31
1399#endif
1400
1412
1425
1437
1449
1461
1473
1485
1497
1509
1510#if AF_API_VERSION >= 37
1522#endif
1534
1546
1558
1571
1583
1596
1608
1609#ifdef __cplusplus
1610}
1611#endif
AFAPI af_err af_log2(af_array *out, const af_array in)
C Interface to evaluate the base 2 logarithm.
AFAPI af_err af_lt(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to perform a less-than comparison between corresponding elements of two arrays.
A multi dimensional data container.
Definition: array.h:37
af_dtype
Definition: defines.h:210
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:243
#define AFAPI
Definition: defines.h:38
AFAPI array abs(const array &in)
C++ Interface to calculate the absolute value.
AFAPI af_err af_abs(af_array *out, const af_array in)
C Interface to calculate the absolute value.
AFAPI af_err af_acos(af_array *out, const af_array in)
C Interface to evaluate the inverse cosine function.
AFAPI array acos(const array &in)
C++ Interface to evaluate the inverse cosine function.
AFAPI array acosh(const array &in)
C++ Interface to evaluate the inverse hyperbolic cosine function.
AFAPI af_err af_acosh(af_array *out, const af_array in)
C Interface to evaluate the inverse hyperbolic cosine function.
AFAPI af_err af_add(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to add two arrays.
AFAPI af_err af_and(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to evaluate the logical AND of two arrays.
AFAPI array arg(const array &in)
C++ Interface to calculate the phase angle (in radians) of a complex array.
AFAPI af_err af_arg(af_array *out, const af_array in)
C Interface to calculate the phase angle (in radians) of a complex array.
AFAPI af_err af_asin(af_array *out, const af_array in)
C Interface to evaluate the inverse sine function.
AFAPI array asin(const array &in)
C++ Interface to evaluate the inverse sine function.
AFAPI af_err af_asinh(af_array *out, const af_array in)
C Interface to evaluate the inverse hyperbolic sine function.
AFAPI array asinh(const array &in)
C++ Interface to evaluate the inverse hyperbolic sine function.
AFAPI af_err af_atan(af_array *out, const af_array in)
C Interface to evaluate the inverse tangent function.
AFAPI array atan2(const array &lhs, const array &rhs)
C++ Interface to evaluate the inverse tangent of two arrays.
AFAPI array atan(const array &in)
C++ Interface to evaluate the inverse tangent function.
AFAPI af_err af_atan2(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to evaluate the inverse tangent of two arrays.
AFAPI af_err af_atanh(af_array *out, const af_array in)
C Interface to evaluate the inverse hyperbolic tangent function.
AFAPI array atanh(const array &in)
C++ Interface to evaluate the inverse hyperbolic tangent function.
AFAPI af_err af_bitand(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to evaluate the bitwise AND of two arrays.
AFAPI af_err af_bitnot(af_array *out, const af_array in)
C Interface to evaluate the bitwise NOT of an array.
AFAPI af_err af_bitor(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to evaluate the bitwise OR of two arrays.
AFAPI af_err af_bitxor(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to evaluate the bitwise XOR of two arrays.
AFAPI af_err af_cast(af_array *out, const af_array in, const af_dtype type)
C Interface to cast an array from one type to another.
AFAPI af_err af_cbrt(af_array *out, const af_array in)
C Interface to evaluate the cube root.
AFAPI array cbrt(const array &in)
C++ Interface to evaluate the cube root.
AFAPI array ceil(const array &in)
C++ Interface to ceil numbers.
AFAPI af_err af_ceil(af_array *out, const af_array in)
C Interface to ceil numbers.
AFAPI array clamp(const array &in, const array &lo, const array &hi)
AFAPI af_err af_clamp(af_array *out, const af_array in, const af_array lo, const af_array hi, const bool batch)
C Interface to clamp an array between an upper and a lower limit.
AFAPI array conjg(const array &in)
C++ Interface to calculate the complex conjugate of an input array.
AFAPI af_err af_conjg(af_array *out, const af_array in)
C Interface to evaluate the complex conjugate of an input array.
AFAPI array cos(const array &in)
C++ Interface to evaluate the cosine function.
AFAPI af_err af_cos(af_array *out, const af_array in)
C Interface to evaluate the cosine function.
AFAPI array cosh(const array &in)
C++ Interface to evaluate the hyperbolic cosine function.
AFAPI af_err af_cosh(af_array *out, const af_array in)
C Interface to evaluate the hyperbolic cosine function.
AFAPI array complex(const array &in)
C++ Interface to create a complex array from a single real array.
AFAPI af_err af_cplx(af_array *out, const af_array in)
C Interface to create a complex array from a single real array.
AFAPI af_err af_cplx2(af_array *out, const af_array real, const af_array imag, const bool batch)
C Interface to create a complex array from two real arrays.
AFAPI af_err af_div(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to divide one array by another array.
AFAPI af_err af_eq(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to check if corresponding elements of two arrays are equal.
AFAPI array erf(const array &in)
C++ Interface to evaluate the error function.
AFAPI af_err af_erf(af_array *out, const af_array in)
C Interface to evaluate the error function.
AFAPI af_err af_erfc(af_array *out, const af_array in)
C Interface to evaluate the complementary error function.
AFAPI array erfc(const array &in)
C++ Interface to evaluate the complementary error function.
AFAPI af_err af_exp(af_array *out, const af_array in)
C Interface to evaluate the exponential.
AFAPI array exp(const array &in)
C++ Interface to evaluate the exponential.
AFAPI af_err af_expm1(af_array *out, const af_array in)
C Interface to evaluate the exponential of an array minus 1, exp(in) - 1.
AFAPI array expm1(const array &in)
C++ Interface to evaluate the exponential of an array minus 1, exp(in) - 1.
AFAPI array factorial(const array &in)
C++ Interface to calculate the factorial.
AFAPI af_err af_factorial(af_array *out, const af_array in)
C Interface to calculate the factorial.
AFAPI af_err af_hypot(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to calculate the length of the hypotenuse of two inputs.
AFAPI af_err af_floor(af_array *out, const af_array in)
C Interface to floor numbers.
AFAPI array floor(const array &in)
C++ Interface to floor numbers.
AFAPI af_err af_ge(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to perform a greater-than-or-equal comparison between corresponding elements of two array...
AFAPI af_err af_gt(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to perform a greater-than comparison between corresponding elements of two arrays.
AFAPI array hypot(const array &lhs, const array &rhs)
C++ Interface to calculate the length of the hypotenuse of two inputs.
AFAPI af_err af_imag(af_array *out, const af_array in)
C Interface to return the imaginary part of a complex array.
AFAPI array imag(const array &in)
C++ Interface to return the imaginary part of a complex array.
AFAPI array isInf(const array &in)
C++ Interface to check if values are infinite.
AFAPI af_err af_isinf(af_array *out, const af_array in)
C Interface to check if values are infinite.
AFAPI af_err af_isnan(af_array *out, const af_array in)
C Interface to check if values are NaN.
AFAPI array isNaN(const array &in)
C++ Interface to check if values are NaN.
AFAPI array iszero(const array &in)
C++ Interface to check which values are zero.
AFAPI af_err af_iszero(af_array *out, const af_array in)
C Interface to check if values are zero.
AFAPI af_err af_le(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to perform a less-than-or-equal comparison between corresponding elements of two arrays.
AFAPI array lgamma(const array &in)
C++ Interface to evaluate the logarithm of the absolute value of the gamma function.
AFAPI af_err af_lgamma(af_array *out, const af_array in)
C Interface to evaluate the logarithm of the absolute value of the gamma function.
AFAPI af_err af_log10(af_array *out, const af_array in)
C Interface to evaluate the base 10 logarithm.
AFAPI array log10(const array &in)
C++ Interface to evaluate the base 10 logarithm.
AFAPI af_err af_log1p(af_array *out, const af_array in)
C Interface to evaluate the natural logarithm of 1 + input, ln(1+in).
AFAPI array log1p(const array &in)
C++ Interface to evaluate the natural logarithm of 1 + input, ln(1+in).
AFAPI af_err af_log(af_array *out, const af_array in)
C Interface to evaluate the natural logarithm.
AFAPI array log(const array &in)
C++ Interface to evaluate the natural logarithm.
AFAPI af_err af_maxof(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to find the elementwise minimum between an array and a scalar value.
AFAPI af_err af_minof(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to find the elementwise minimum between two arrays.
AFAPI af_err af_mod(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to calculate the modulus.
AFAPI array mod(const array &lhs, const array &rhs)
AFAPI af_err af_mul(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to multiply two arrays.
AFAPI af_err af_neq(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to check if corresponding elements of two arrays are not equal.
AFAPI af_err af_not(af_array *out, const af_array in)
C Interface to evaluate the logical NOT of an array.
AFAPI af_err af_or(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface the evaluate the logical OR of two arrays.
AFAPI af_err af_pow2(af_array *out, const af_array in)
C Interface to raise 2 to a power (or exponent).
AFAPI af_err af_pow(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to raise a base to a power (or exponent).
AFAPI array pow2(const array &in)
C++ Interface to raise 2 to a power (or exponent).
AFAPI array pow(const array &base, const array &exponent)
C++ Interface to raise a base to a power (or exponent).
AFAPI af_err af_real(af_array *out, const af_array in)
C Interface to return the real part of a complex array.
AFAPI array real(const array &in)
C++ Interface to return the real part of a complex array.
AFAPI array rem(const array &lhs, const array &rhs)
AFAPI af_err af_rem(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to calculate the remainder.
AFAPI af_err af_root(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to evaluate the nth root.
AFAPI array root(const array &nth_root, const array &value)
C++ Interface to evaluate the nth root.
AFAPI af_err af_round(af_array *out, const af_array in)
C Interface to round numbers.
AFAPI array round(const array &in)
C++ Interface to round numbers.
AFAPI af_err af_rsqrt(af_array *out, const af_array in)
C Interface to evaluate the reciprocal square root.
AFAPI array rsqrt(const array &in)
C++ Interface to evaluate the reciprocal square root.
AFAPI af_err af_bitshiftl(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to shift the bits of integer arrays left.
AFAPI af_err af_bitshiftr(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to shift the bits of integer arrays right.
AFAPI array sigmoid(const array &in)
C++ Interface to evaluate the logistical sigmoid function.
AFAPI af_err af_sigmoid(af_array *out, const af_array in)
C Interface to evaluate the logistical sigmoid function.
AFAPI af_err af_sign(af_array *out, const af_array in)
C Interface to calculate the sign of elements in an array.
AFAPI array sign(const array &in)
C++ Interface to return the sign of elements in an array.
AFAPI af_err af_sin(af_array *out, const af_array in)
C Interface to evaluate the sine function.
AFAPI array sin(const array &in)
C++ Interface to evaluate the sine function.
AFAPI array sinh(const array &in)
C++ Interface to evaluate the hyperbolic sine function.
AFAPI af_err af_sinh(af_array *out, const af_array in)
C Interface to evaluate the hyperbolic sine function.
AFAPI af_err af_sqrt(af_array *out, const af_array in)
C Interface to evaluate the square root.
AFAPI array sqrt(const array &in)
C++ Interface to evaluate the square root.
AFAPI af_err af_sub(af_array *out, const af_array lhs, const af_array rhs, const bool batch)
C Interface to subtract one array from another array.
AFAPI array tan(const array &in)
C++ Interface to evaluate the tangent function.
AFAPI af_err af_tan(af_array *out, const af_array in)
C Interface to evaluate the tangent function.
AFAPI af_err af_tanh(af_array *out, const af_array in)
C Interface to evaluate the hyperbolic tangent function.
AFAPI array tanh(const array &in)
C++ Interface to evaluate the hyperbolic tangent function.
AFAPI af_err af_tgamma(af_array *out, const af_array in)
C Interface to evaluate the gamma function.
AFAPI array tgamma(const array &in)
C++ Interface to evaluate the gamma function.
AFAPI array trunc(const array &in)
C++ Interface to truncate numbers.
AFAPI af_err af_trunc(af_array *out, const af_array in)
C Interface to truncate numbers.
AFAPI array max(const array &in, const int dim=-1)
C++ Interface to return the maximum along a given dimension.
AFAPI array min(const array &in, const int dim=-1)
C++ Interface to return the minimum along a given dimension.
Definition: algorithm.h:15
AFAPI array log2(const array &in)
C++ Interface to evaluate the base 2 logarithm.