-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathmedian.cpp
More file actions
45 lines (38 loc) · 1.34 KB
/
median.cpp
File metadata and controls
45 lines (38 loc) · 1.34 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
/*******************************************************
* 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/statistics.h>
#include "common.hpp"
#include "error.hpp"
namespace af {
#define INSTANTIATE_MEDIAN(T) \
template<> \
AFAPI T median(const array& in) { \
double ret_val; \
AF_THROW(af_median_all(&ret_val, NULL, in.get())); \
return (T)ret_val; \
}
INSTANTIATE_MEDIAN(float);
INSTANTIATE_MEDIAN(double);
INSTANTIATE_MEDIAN(int);
INSTANTIATE_MEDIAN(unsigned int);
INSTANTIATE_MEDIAN(char);
INSTANTIATE_MEDIAN(signed char);
INSTANTIATE_MEDIAN(unsigned char);
INSTANTIATE_MEDIAN(long long);
INSTANTIATE_MEDIAN(unsigned long long);
INSTANTIATE_MEDIAN(short);
INSTANTIATE_MEDIAN(unsigned short);
#undef INSTANTIATE_MEDIAN
array median(const array& in, const dim_t dim) {
af_array temp = 0;
AF_THROW(af_median(&temp, in.get(), getFNSD(dim, in.dims())));
return array(temp);
}
} // namespace af