-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathdiff.cpp
More file actions
65 lines (53 loc) · 1.61 KB
/
diff.cpp
File metadata and controls
65 lines (53 loc) · 1.61 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
/*******************************************************
* 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 <Array.hpp>
#include <diff.hpp>
#include <err_cuda.hpp>
#include <kernel/diff.hpp>
#include <stdexcept>
namespace arrayfire {
namespace cuda {
template<typename T>
Array<T> diff(const Array<T> &in, const int dim, const bool isDiff2) {
const af::dim4 &iDims = in.dims();
af::dim4 oDims = iDims;
oDims[dim] -= (isDiff2 + 1);
if (iDims.elements() == 0 || oDims.elements() == 0) {
AF_ERROR("Elements are 0", AF_ERR_SIZE);
}
Array<T> out = createEmptyArray<T>(oDims);
kernel::diff<T>(out, in, in.ndims(), dim, isDiff2);
return out;
}
template<typename T>
Array<T> diff1(const Array<T> &in, const int dim) {
return diff<T>(in, dim, false);
}
template<typename T>
Array<T> diff2(const Array<T> &in, const int dim) {
return diff<T>(in, dim, true);
}
#define INSTANTIATE(T) \
template Array<T> diff1<T>(const Array<T> &in, const int dim); \
template Array<T> diff2<T>(const Array<T> &in, const int dim);
INSTANTIATE(float)
INSTANTIATE(double)
INSTANTIATE(cfloat)
INSTANTIATE(cdouble)
INSTANTIATE(int)
INSTANTIATE(uint)
INSTANTIATE(intl)
INSTANTIATE(uintl)
INSTANTIATE(schar)
INSTANTIATE(uchar)
INSTANTIATE(char)
INSTANTIATE(short)
INSTANTIATE(ushort)
} // namespace cuda
} // namespace arrayfire