| 34 | |
| 35 | template<typename T> |
| 36 | af_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 | |
| 61 | af_err af_anisotropic_diffusion(af_array* out, const af_array in, |
| 62 | const float dt, const float K, |
nothing calls this directly
no test coverage detected