| 45 | |
| 46 | template<typename T, bool IsDilation> |
| 47 | void morph(Param<T> paddedOut, CParam<T> paddedIn, CParam<T> mask) { |
| 48 | MorphFilterOp<T, IsDilation> filterOp; |
| 49 | T init = IsDilation ? common::Binary<T, af_max_t>::init() |
| 50 | : common::Binary<T, af_min_t>::init(); |
| 51 | |
| 52 | const af::dim4 ostrides = paddedOut.strides(); |
| 53 | T* outData = paddedOut.get(); |
| 54 | const af::dim4 istrides = paddedIn.strides(); |
| 55 | const af::dim4 dims = paddedIn.dims(); |
| 56 | const T* inData = paddedIn.get(); |
| 57 | |
| 58 | std::vector<dim_t> offsets; |
| 59 | getOffsets(offsets, istrides, mask); |
| 60 | |
| 61 | const dim_t batchSize = dims[0] * dims[1]; |
| 62 | const int batchCount = dims[2] * dims[3]; |
| 63 | for (int b = 0; b < batchCount; ++b) { |
| 64 | for (dim_t n = 0; n < batchSize; ++n) { |
| 65 | T filterResult = init; |
| 66 | for (size_t oi = 0; oi < offsets.size(); ++oi) { |
| 67 | dim_t x = n + offsets[oi]; |
| 68 | if (x >= 0 && x < batchSize) |
| 69 | filterResult = filterOp(filterResult, inData[x]); |
| 70 | } |
| 71 | outData[n] = filterResult; |
| 72 | } |
| 73 | outData += ostrides[2]; |
| 74 | inData += istrides[2]; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | template<typename T, bool IsDilation> |
| 79 | void morph3d(Param<T> out, CParam<T> in, CParam<T> mask) { |
nothing calls this directly
no test coverage detected