-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathmoments.cpp
More file actions
88 lines (74 loc) · 2.53 KB
/
Copy pathmoments.cpp
File metadata and controls
88 lines (74 loc) · 2.53 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
/*******************************************************
* Copyright (c) 2016, 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/data.h>
#include <af/image.h>
#include <af/index.h>
#include <arith.hpp>
#include <backend.hpp>
#include <common/ArrayInfo.hpp>
#include <common/cast.hpp>
#include <common/err_common.hpp>
#include <common/graphics_common.hpp>
#include <handle.hpp>
#include <join.hpp>
#include <moments.hpp>
#include <reorder.hpp>
#include <tile.hpp>
#include <limits>
#include <vector>
using af::dim4;
using detail::Array;
using std::vector;
template<typename T>
static inline void moments(af_array* out, const af_array in,
af_moment_type moment) {
Array<float> temp = moments<T>(getArray<T>(in), moment);
*out = getHandle<float>(temp);
}
af_err af_moments(af_array* out, const af_array in,
const af_moment_type moment) {
try {
const ArrayInfo& in_info = getInfo(in);
af_dtype type = in_info.getType();
switch (type) {
case f32: moments<float>(out, in, moment); break;
case f64: moments<double>(out, in, moment); break;
case u32: moments<unsigned>(out, in, moment); break;
case s32: moments<int>(out, in, moment); break;
case u16: moments<unsigned short>(out, in, moment); break;
case s16: moments<short>(out, in, moment); break;
case b8: moments<char>(out, in, moment); break;
default: TYPE_ERROR(1, type);
}
}
CATCHALL;
return AF_SUCCESS;
}
template<typename T>
static inline void moment_copy(double* out, const af_array moments) {
const auto& info = getInfo(moments);
vector<T> h_moments(info.elements());
copyData(h_moments.data(), moments);
// convert to double
copy(begin(h_moments), end(h_moments), out);
}
af_err af_moments_all(double* out, const af_array in,
const af_moment_type moment) {
try {
const ArrayInfo& in_info = getInfo(in);
dim4 idims = in_info.dims();
DIM_ASSERT(1, idims[2] == 1 && idims[3] == 1);
af_array moments_arr;
AF_CHECK(af_moments(&moments_arr, in, moment));
moment_copy<float>(out, moments_arr);
AF_CHECK(af_release_array(moments_arr));
}
CATCHALL;
return AF_SUCCESS;
}