MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / diff2

Function diff2

src/backend/cpu/kernel/diff.hpp:49–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48template<typename T>
49void diff2(Param<T> out, CParam<T> in, int const dim) {
50 af::dim4 dims = out.dims();
51 // Bool for dimension
52 bool is_dim0 = dim == 0;
53 bool is_dim1 = dim == 1;
54 bool is_dim2 = dim == 2;
55 bool is_dim3 = dim == 3;
56
57 T const* const inPtr = in.get();
58 T* outPtr = out.get();
59
60 // TODO: Improve this
61 for (dim_t l = 0; l < dims[3]; l++) {
62 for (dim_t k = 0; k < dims[2]; k++) {
63 for (dim_t j = 0; j < dims[1]; j++) {
64 for (dim_t i = 0; i < dims[0]; i++) {
65 // Operation: out[index] = in[index + 1 * dim_size] -
66 // in[index]
67 int idx = getIdx(in.strides(), i, j, k, l);
68 int jdx = getIdx(in.strides(), i + is_dim0, j + is_dim1,
69 k + is_dim2, l + is_dim3);
70 int kdx =
71 getIdx(in.strides(), i + 2 * is_dim0, j + 2 * is_dim1,
72 k + 2 * is_dim2, l + 2 * is_dim3);
73 int odx = getIdx(out.strides(), i, j, k, l);
74 outPtr[odx] =
75 inPtr[kdx] + inPtr[idx] - inPtr[jdx] - inPtr[jdx];
76 }
77 }
78 }
79 }
80}
81
82} // namespace kernel
83} // namespace cpu

Callers

nothing calls this directly

Calls 4

getIdxFunction · 0.85
dimsMethod · 0.45
getMethod · 0.45
stridesMethod · 0.45

Tested by

no test coverage detected