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

Function diff1

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

Source from the content-addressed store, hash-verified

17
18template<typename T>
19void diff1(Param<T> out, CParam<T> in, int const dim) {
20 af::dim4 dims = out.dims();
21 // Bool for dimension
22 bool is_dim0 = dim == 0;
23 bool is_dim1 = dim == 1;
24 bool is_dim2 = dim == 2;
25 bool is_dim3 = dim == 3;
26
27 T const* const inPtr = in.get();
28 T* outPtr = out.get();
29
30 // TODO: Improve this
31 for (dim_t l = 0; l < dims[3]; l++) {
32 for (dim_t k = 0; k < dims[2]; k++) {
33 for (dim_t j = 0; j < dims[1]; j++) {
34 for (dim_t i = 0; i < dims[0]; i++) {
35 // Operation: out[index] = in[index + 1 * dim_size] -
36 // in[index]
37 int idx = getIdx(in.strides(), i, j, k, l);
38 int jdx = getIdx(in.strides(), i + is_dim0, j + is_dim1,
39 k + is_dim2, l + is_dim3);
40 int odx = getIdx(out.strides(), i, j, k, l);
41 outPtr[odx] = inPtr[jdx] - inPtr[idx];
42 }
43 }
44 }
45 }
46}
47
48template<typename T>
49void diff2(Param<T> out, CParam<T> in, int const dim) {

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