MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ normalize()

void MayaFlux::Kinesis::Discrete::normalize ( std::span< double >  data,
double  target_min = -1.0,
double  target_max = 1.0 
)
noexcept

Normalize to [target_min, target_max] in-place Single-pass min/max reduction followed by a single transform pass.

No-op when all values are equal.

Parameters
dataTarget span
target_minOutput minimum
target_maxOutput maximum

Definition at line 61 of file Transform.cpp.

62{
63 if (data.empty())
64 return;
65
66 double lo = data[0];
67 double hi = data[0];
68 for (double v : data) {
69 if (v < lo)
70 lo = v;
71 if (v > hi)
72 hi = v;
73 }
74
75 if (hi == lo)
76 return;
77
78 const double inv_src = 1.0 / (hi - lo);
79 const double dst_range = target_max - target_min;
80 std::ranges::transform(data, data.begin(),
81 [lo, inv_src, dst_range, target_min](double x) {
82 return (x - lo) * inv_src * dst_range + target_min;
83 });
84}

Referenced by cross_correlate().

+ Here is the caller graph for this function: