normalization of methods

This commit is contained in:
Miha Kralj
2026-02-10 21:33:16 -08:00
parent 915d7a007b
commit 6d6259a47d
527 changed files with 10525 additions and 2123 deletions
+4 -4
View File
@@ -120,11 +120,11 @@ public class LinRegTests
// Period must be > 0
Assert.Throws<ArgumentException>(() =>
LinReg.Calculate(source.AsSpan(), output.AsSpan(), 0));
LinReg.Batch(source.AsSpan(), output.AsSpan(), 0));
// Output must be same length as source
Assert.Throws<ArgumentException>(() =>
LinReg.Calculate(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
LinReg.Batch(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
}
[Fact]
@@ -145,7 +145,7 @@ public class LinRegTests
var tseriesResult = LinReg.Batch(series, period);
double[] output = new double[100];
LinReg.Calculate(source.AsSpan(), output.AsSpan(), period);
LinReg.Batch(source.AsSpan(), output.AsSpan(), period);
for (int i = 0; i < 100; i++)
{
@@ -213,7 +213,7 @@ public class LinRegTests
var tValues = series.Values.ToArray();
var spanInput = new ReadOnlySpan<double>(tValues);
var spanOutput = new double[tValues.Length];
LinReg.Calculate(spanInput, spanOutput, period);
LinReg.Batch(spanInput, spanOutput, period);
double spanResult = spanOutput[^1];
// 3. Streaming Mode
+10 -3
View File
@@ -279,7 +279,7 @@ public sealed class LinReg : AbstractBase
var vSpan = CollectionsMarshal.AsSpan(v);
double initialLastValid = _state.LastValidValue;
Calculate(source.Values, vSpan, _period, _offset, initialLastValid);
Batch(source.Values, vSpan, _period, _offset, initialLastValid);
source.Times.CopyTo(tSpan);
// Restore state
@@ -334,7 +334,7 @@ public sealed class LinReg : AbstractBase
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period, int offset = 0, double initialLastValid = 0)
public static void Batch(ReadOnlySpan<double> source, Span<double> output, int period, int offset = 0, double initialLastValid = 0)
{
if (source.Length != output.Length)
{
@@ -458,6 +458,13 @@ public sealed class LinReg : AbstractBase
}
}
public static (TSeries Results, LinReg Indicator) Calculate(TSeries source, int period, int offset = 0)
{
var indicator = new LinReg(period, offset);
TSeries results = indicator.Update(source);
return (results, indicator);
}
public override void Reset()
{
_buffer.Clear();
@@ -469,4 +476,4 @@ public sealed class LinReg : AbstractBase
Intercept = 0;
RSquared = 0;
}
}
}