Skip to content

Commit cb60a03

Browse files
author
Peter Andreas Entschev
committed
Added log2() support
1 parent 8b7ff98 commit cb60a03

9 files changed

Lines changed: 31 additions & 1 deletion

File tree

include/af/arith.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,16 @@ namespace af
555555
*/
556556
AFAPI array log10 (const array &in);
557557

558+
/**
559+
C++ Interface for logarithm base 2
560+
561+
\param[in] in is input
562+
\return the logarithm of input in base 2
563+
564+
\ingroup explog_func_log2
565+
*/
566+
AFAPI array log2 (const array &in);
567+
558568
/**
559569
C++ Interface for square root of input
560570
@@ -1278,6 +1288,17 @@ extern "C" {
12781288
*/
12791289
AFAPI af_err af_log10 (af_array *out, const af_array in);
12801290

1291+
/**
1292+
C Interface for logarithm base 2
1293+
1294+
\param[out] out will contain the base 2 logarithm of \p in
1295+
\param[in] in is input
1296+
\return \ref AF_SUCCESS if the execution completes properly
1297+
1298+
\ingroup explog_func_log2
1299+
*/
1300+
AFAPI af_err af_log2 (af_array *out, const af_array in);
1301+
12811302
/**
12821303
C Interface for square root
12831304

src/api/c/optypes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef enum {
5959
af_log_t,
6060
af_log10_t,
6161
af_log1p_t,
62+
af_log2_t,
6263

6364
af_sqrt_t,
6465
af_cbrt_t,

src/api/c/unary.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ UNARY(erfc)
9191
UNARY(log)
9292
UNARY(log10)
9393
UNARY(log1p)
94+
UNARY(log2)
9495

9596
UNARY(sqrt)
9697
UNARY(cbrt)

src/api/cpp/unary.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace af
5959
INSTANTIATE(log )
6060
INSTANTIATE(log1p )
6161
INSTANTIATE(log10 )
62+
INSTANTIATE(log2 )
6263

6364
INSTANTIATE(sqrt )
6465
INSTANTIATE(cbrt )

src/backend/cpu/unary.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ UNARY_FN(erfc)
5454
UNARY_FN(log)
5555
UNARY_FN(log10)
5656
UNARY_FN(log1p)
57+
UNARY_FN(log2)
5758

5859
UNARY_FN(sqrt)
5960
UNARY_FN(cbrt)

src/backend/cuda/JIT/exp.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ MATH(erfc)
2727
MATH(log)
2828
MATH(log10)
2929
MATH(log1p)
30+
MATH(log2)
3031

3132
MATH(sqrt)
3233
MATH(cbrt)

src/backend/cuda/unary.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ UNARY_FN(lgamma)
6767
UNARY_FN(log)
6868
UNARY_FN(log1p)
6969
UNARY_FN(log10)
70+
UNARY_FN(log2)
7071

7172
UNARY_FN(sqrt)
7273
UNARY_FN(cbrt)

src/backend/opencl/unary.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ UNARY_FN(lgamma)
5454
UNARY_FN(log)
5555
UNARY_FN(log1p)
5656
UNARY_FN(log10)
57+
UNARY_FN(log2)
5758

5859
UNARY_FN(sqrt)
5960
UNARY_FN(cbrt)

test/math.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const double dbl_err = 1e-10;
3131
To *h_b = b.host<To>(); \
3232
\
3333
for (int i = 0; i < num; i++) \
34-
ASSERT_NEAR(h_b[i], std::func(h_a[i]), err) << \
34+
ASSERT_NEAR(h_b[i], func(h_a[i]), err) << \
3535
"for value: " << h_a[i] << std::endl; \
3636
delete[] h_a; \
3737
delete[] h_b; \
@@ -57,6 +57,7 @@ MATH_TESTS_FLOAT(sqrt)
5757
MATH_TESTS_FLOAT(exp)
5858
MATH_TESTS_FLOAT(log)
5959
MATH_TESTS_FLOAT(log10)
60+
MATH_TESTS_FLOAT(log2)
6061

6162
MATH_TESTS_LIMITS(float, float, abs, flt_err, -10, 10)
6263
MATH_TESTS_LIMITS(float, float, ceil, flt_err, -10, 10)
@@ -99,6 +100,7 @@ MATH_TESTS_DOUBLE(sqrt)
99100
MATH_TESTS_DOUBLE(exp)
100101
MATH_TESTS_DOUBLE(log)
101102
MATH_TESTS_DOUBLE(log10)
103+
MATH_TESTS_DOUBLE(log2)
102104

103105
MATH_TESTS_LIMITS(double, double, abs, dbl_err, -10, 10)
104106
MATH_TESTS_LIMITS(double, double, ceil, dbl_err, -10, 10)

0 commit comments

Comments
 (0)