-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathalgorithm.cpp
More file actions
48 lines (44 loc) · 1.67 KB
/
algorithm.cpp
File metadata and controls
48 lines (44 loc) · 1.67 KB
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
#include <stdio.h>
#include "R_wrapper.h"
// Because I am lazy
#define af_accum_all(...) AF_SUCCESS
#define ALGO_DIM(fn) \
EXTERNC afr_##fn(SEXP A, SEXP _dim) \
{ \
af_array a = getPtr(A); \
double dim = *RealPtr(_dim, 0); \
af_array b = 0; \
AF_CHECK(af_##fn(&b, a, dim)); \
return getSEXP(b); \
} \
EXTERNC afr_##fn##_all(SEXP A) \
{ \
af_array a = getPtr(A); \
double real = 0, imag = 0; \
AF_CHECK(af_##fn##_all(&real, &imag, a)); \
if (imag == 0) { \
SEXP res = NEW_NUMERIC(1); \
*RealPtr(res, 0) = real; \
return res; \
} else { \
SEXP res = NEW_COMPLEX(1); \
(*CplxPtr(res, 0)).x = real; \
(*CplxPtr(res, 0)).x = imag; \
return res; \
} \
} \
ALGO_DIM(sum)
ALGO_DIM(any_true)
ALGO_DIM(all_true)
ALGO_DIM(max)
ALGO_DIM(min)
ALGO_DIM(count)
ALGO_DIM(accum)
#undef ALGO_DIM
EXTERNC afr_where(SEXP A)
{
af_array a = getPtr(A);
af_array b = 0;
AF_CHECK(af_where(&b, a));
return getSEXP(b);
}