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

Function convRange

src/api/c/imgproc_common.hpp:47–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46template<typename To, typename Ti>
47detail::Array<To> convRange(const detail::Array<Ti>& in,
48 const To newLow = To(0), const To newHigh = To(1)) {
49 auto dims = in.dims();
50 auto input = common::cast<To, Ti>(in);
51 To high =
52 detail::getScalar<To>(detail::reduce_all<af_max_t, To, To>(input));
53 To low = detail::getScalar<To>(detail::reduce_all<af_min_t, To, To>(input));
54 To range = high - low;
55
56 if (std::abs(range) < 1.0e-6) {
57 if (low == To(0) && newLow == To(0)) {
58 return input;
59 } else {
60 // Input is constant, use high as constant in converted range
61 return detail::createValueArray(dims, newHigh);
62 }
63 }
64
65 auto minArray = detail::createValueArray(dims, low);
66 auto invDen = detail::createValueArray(dims, To(1.0 / range));
67 auto numer = detail::arithOp<To, af_sub_t>(input, minArray, dims);
68 auto result = detail::arithOp<To, af_mul_t>(numer, invDen, dims);
69
70 if (newLow != To(0) || newHigh != To(1)) {
71 To newRange = newHigh - newLow;
72 auto newRngArr = detail::createValueArray(dims, newRange);
73 auto newMinArr = detail::createValueArray(dims, newLow);
74 auto scaledArr = detail::arithOp<To, af_mul_t>(result, newRngArr, dims);
75
76 result = detail::arithOp<To, af_add_t>(newMinArr, scaledArr, dims);
77 }
78 return result;
79}
80
81} // namespace common
82} // namespace arrayfire

Callers

nothing calls this directly

Calls 3

absFunction · 0.50
createValueArrayFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected