-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstatistics.cpp
More file actions
68 lines (63 loc) · 2.17 KB
/
statistics.cpp
File metadata and controls
68 lines (63 loc) · 2.17 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include "R_wrapper.h"
#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(stdev)
ALGO_DIM(median)
ALGO_DIM(mean)
#undef ALGO_DIM
EXTERNC afr_var(SEXP A, SEXP _dim)
{
af_array a = getPtr(A);
af_array b = 0;
double dim = *RealPtr(_dim, 0);
AF_CHECK(af_var(&b, a, false, dim));
return getSEXP(b);
}
EXTERNC afr_var_all(SEXP A)
{
af_array a = getPtr(A);
double real = 0, imag = 0;
AF_CHECK(af_var_all(&real, &imag, a, false));
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;
}
}
EXTERNC afr_cov(SEXP A, SEXP B)
{
af_array a = getPtr(A);
af_array b = getPtr(B);
af_array c = 0;
AF_CHECK(af_cov(&c, a, b, false));
return getSEXP(c);
}