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

Function diffusion

src/api/c/anisotropic_diffusion.cpp:36–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35template<typename T>
36af_array diffusion(const Array<float>& in, const float dt, const float K,
37 const unsigned iterations, const af_flux_function fftype,
38 const af::diffusionEq eq) {
39 auto out = copyArray(in);
40 auto dims = out.dims();
41 auto g0 = createEmptyArray<float>(dims);
42 auto g1 = createEmptyArray<float>(dims);
43 float cnst =
44 -2.0f * K * K / dims.elements(); // NOLINT(readability-magic-numbers)
45
46 for (unsigned i = 0; i < iterations; ++i) {
47 gradient<float>(g0, g1, out);
48
49 auto g0Sqr = arithOp<float, af_mul_t>(g0, g0, dims);
50 auto g1Sqr = arithOp<float, af_mul_t>(g1, g1, dims);
51 auto sumd = arithOp<float, af_add_t>(g0Sqr, g1Sqr, dims);
52 float avg =
53 getScalar<float>(reduce_all<af_add_t, float, float>(sumd, true, 0));
54
55 anisotropicDiffusion(out, dt, 1.0f / (cnst * avg), fftype, eq);
56 }
57
58 return getHandle(cast<T, float>(out));
59}
60
61af_err af_anisotropic_diffusion(af_array* out, const af_array in,
62 const float dt, const float K,

Callers

nothing calls this directly

Calls 5

copyArrayFunction · 0.70
getHandleFunction · 0.70
anisotropicDiffusionFunction · 0.50
dimsMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected