From d079b656b4719739b2247dcd9d46e9bec793095a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 Feb 2023 17:11:34 +0100 Subject: Merging upstream version 1.38.0. Signed-off-by: Daniel Baumann --- ml/SamplesBuffer.cc | 63 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 15 deletions(-) (limited to 'ml/SamplesBuffer.cc') diff --git a/ml/SamplesBuffer.cc b/ml/SamplesBuffer.cc index d276c6e09..359b60c23 100644 --- a/ml/SamplesBuffer.cc +++ b/ml/SamplesBuffer.cc @@ -54,12 +54,12 @@ void SamplesBuffer::diffSamples() { void SamplesBuffer::smoothSamples() { // Holds the mean value of each window - CalculatedNumber *AccCNs = new CalculatedNumber[NumDimsPerSample](); - Sample Acc(AccCNs, NumDimsPerSample); + CalculatedNumber AccCNs[1] = { 0 }; + Sample Acc(AccCNs, 1); // Used to avoid clobbering the accumulator when moving the window - CalculatedNumber *TmpCNs = new CalculatedNumber[NumDimsPerSample](); - Sample Tmp(TmpCNs, NumDimsPerSample); + CalculatedNumber TmpCNs[1] = { 0 }; + Sample Tmp(TmpCNs, 1); CalculatedNumber Factor = (CalculatedNumber) 1 / SmoothN; @@ -88,9 +88,6 @@ void SamplesBuffer::smoothSamples() { Acc.copy(Tmp); Acc.scale(Factor); } - - delete[] AccCNs; - delete[] TmpCNs; } void SamplesBuffer::lagSamples() { @@ -103,31 +100,30 @@ void SamplesBuffer::lagSamples() { } } -std::vector SamplesBuffer::preprocess() { +void SamplesBuffer::preprocess(std::vector &Samples) { assert(Preprocessed == false); - std::vector DSamples; size_t OutN = NumSamples; // Diff if (DiffN >= OutN) - return DSamples; + return; OutN -= DiffN; diffSamples(); // Smooth if (SmoothN == 0 || SmoothN > OutN) - return DSamples; + return; OutN -= (SmoothN - 1); smoothSamples(); // Lag if (LagN >= OutN) - return DSamples; + return; OutN -= LagN; lagSamples(); - DSamples.reserve(OutN); + Samples.reserve(OutN); Preprocessed = true; uint32_t MaxMT = std::numeric_limits::max(); @@ -143,8 +139,45 @@ std::vector SamplesBuffer::preprocess() { const Sample PS = getPreprocessedSample(Idx); PS.initDSample(DS); - DSamples.push_back(DS); + Samples.push_back(std::move(DS)); } +} + +void SamplesBuffer::preprocess(DSample &Feature) { + assert(Preprocessed == false); + + size_t OutN = NumSamples; + + // Diff + if (DiffN >= OutN) + return; + OutN -= DiffN; + diffSamples(); - return DSamples; + // Smooth + if (SmoothN == 0 || SmoothN > OutN) + return; + OutN -= (SmoothN - 1); + smoothSamples(); + + // Lag + if (LagN >= OutN) + return; + OutN -= LagN; + lagSamples(); + + Preprocessed = true; + + uint32_t MaxMT = std::numeric_limits::max(); + uint32_t CutOff = static_cast(MaxMT) * SamplingRatio; + + for (size_t Idx = NumSamples - OutN; Idx != NumSamples; Idx++) { + if (RandNums[Idx] > CutOff) + continue; + + Feature.set_size(NumDimsPerSample * (LagN + 1)); + + const Sample PS = getPreprocessedSample(Idx); + PS.initDSample(Feature); + } } -- cgit v1.2.3