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

Function morph

src/backend/cpu/kernel/morph.hpp:47–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46template<typename T, bool IsDilation>
47void 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
78template<typename T, bool IsDilation>
79void morph3d(Param<T> out, CParam<T> in, CParam<T> mask) {

Callers

nothing calls this directly

Calls 5

getOffsetsFunction · 0.85
initFunction · 0.50
stridesMethod · 0.45
getMethod · 0.45
dimsMethod · 0.45

Tested by

no test coverage detected