-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathhistogram.cpp
More file actions
97 lines (90 loc) · 3.32 KB
/
histogram.cpp
File metadata and controls
97 lines (90 loc) · 3.32 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************
* 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 <backend.hpp>
#include <common/err_common.hpp>
#include <handle.hpp>
#include <histogram.hpp>
#include <af/dim4.hpp>
#include <af/image.h>
using detail::intl;
using detail::schar;
using detail::uchar;
using detail::uint;
using detail::uintl;
using detail::ushort;
template<typename T>
inline af_array histogram(const af_array in, const unsigned &nbins,
const double &minval, const double &maxval,
const bool islinear) {
return getHandle(
histogram<T>(getArray<T>(in), nbins, minval, maxval, islinear));
}
af_err af_histogram(af_array *out, const af_array in, const unsigned nbins,
const double minval, const double maxval) {
try {
const ArrayInfo &info = getInfo(in);
af_dtype type = info.getType();
if (info.ndims() == 0) { return af_retain_array(out, in); }
af_array output;
switch (type) {
case f32:
output = histogram<float>(in, nbins, minval, maxval,
info.isLinear());
break;
case f64:
output = histogram<double>(in, nbins, minval, maxval,
info.isLinear());
break;
case b8:
output =
histogram<char>(in, nbins, minval, maxval, info.isLinear());
break;
case s32:
output =
histogram<int>(in, nbins, minval, maxval, info.isLinear());
break;
case u32:
output =
histogram<uint>(in, nbins, minval, maxval, info.isLinear());
break;
case s16:
output = histogram<short>(in, nbins, minval, maxval,
info.isLinear());
break;
case u16:
output = histogram<ushort>(in, nbins, minval, maxval,
info.isLinear());
break;
case s64:
output =
histogram<intl>(in, nbins, minval, maxval, info.isLinear());
break;
case u64:
output = histogram<uintl>(in, nbins, minval, maxval,
info.isLinear());
break;
case s8:
output = histogram<schar>(in, nbins, minval, maxval,
info.isLinear());
break;
case u8:
output = histogram<uchar>(in, nbins, minval, maxval,
info.isLinear());
break;
case f16:
output = histogram<arrayfire::common::half>(
in, nbins, minval, maxval, info.isLinear());
break;
default: TYPE_ERROR(1, type);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}