-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathstdev.cpp
More file actions
78 lines (66 loc) · 2.42 KB
/
stdev.cpp
File metadata and controls
78 lines (66 loc) · 2.42 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
69
70
71
72
73
74
75
76
77
78
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <af/array.h>
#include <af/dim4.hpp>
#include <af/statistics.h>
#include "common.hpp"
#include "error.hpp"
namespace af {
#define INSTANTIATE_STDEV(T) \
template<> \
AFAPI T stdev(const array& in, const af_var_bias bias) { \
double ret_val; \
AF_THROW(af_stdev_all_v2(&ret_val, NULL, in.get(), bias)); \
return (T)ret_val; \
} \
template<> \
AFAPI T stdev(const array& in) { \
return stdev<T>(in, AF_VARIANCE_POPULATION); \
}
template<>
AFAPI af_cfloat stdev(const array& in, const af_var_bias bias) {
double real, imag;
AF_THROW(af_stdev_all_v2(&real, &imag, in.get(), bias));
return {static_cast<float>(real), static_cast<float>(imag)};
}
template<>
AFAPI af_cdouble stdev(const array& in, const af_var_bias bias) {
double real, imag;
AF_THROW(af_stdev_all_v2(&real, &imag, in.get(), bias));
return {real, imag};
}
template<>
AFAPI af_cfloat stdev(const array& in) {
return stdev<af_cfloat>(in, AF_VARIANCE_POPULATION);
}
template<>
AFAPI af_cdouble stdev(const array& in) {
return stdev<af_cdouble>(in, AF_VARIANCE_POPULATION);
}
INSTANTIATE_STDEV(float);
INSTANTIATE_STDEV(double);
INSTANTIATE_STDEV(int);
INSTANTIATE_STDEV(unsigned int);
INSTANTIATE_STDEV(long long);
INSTANTIATE_STDEV(unsigned long long);
INSTANTIATE_STDEV(short);
INSTANTIATE_STDEV(unsigned short);
INSTANTIATE_STDEV(char);
INSTANTIATE_STDEV(signed char);
INSTANTIATE_STDEV(unsigned char);
#undef INSTANTIATE_STDEV
array stdev(const array& in, const af_var_bias bias, const dim_t dim) {
af_array temp = 0;
AF_THROW(af_stdev_v2(&temp, in.get(), bias, getFNSD(dim, in.dims())));
return array(temp);
}
array stdev(const array& in, const dim_t dim) {
return stdev(in, AF_VARIANCE_POPULATION, dim);
}
} // namespace af