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
+7 -7
View File
@@ -317,7 +317,7 @@ public class UsfTests
var tValues = series.Values.ToArray();
var spanInput = new ReadOnlySpan<double>(tValues);
var spanOutput = new double[tValues.Length];
Usf.Calculate(spanInput, spanOutput, period);
Usf.Batch(spanInput, spanOutput, period);
double spanResult = spanOutput[^1];
// 3. Streaming Mode
@@ -370,11 +370,11 @@ public class UsfTests
double[] wrongSizeOutput = new double[3];
// Period must be > 0
Assert.Throws<ArgumentException>(() => Usf.Calculate(source.AsSpan(), output.AsSpan(), 0));
Assert.Throws<ArgumentException>(() => Usf.Calculate(source.AsSpan(), output.AsSpan(), -1));
Assert.Throws<ArgumentException>(() => Usf.Batch(source.AsSpan(), output.AsSpan(), 0));
Assert.Throws<ArgumentException>(() => Usf.Batch(source.AsSpan(), output.AsSpan(), -1));
// Output must be same length as source
Assert.Throws<ArgumentException>(() => Usf.Calculate(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
Assert.Throws<ArgumentException>(() => Usf.Batch(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
}
[Fact]
@@ -396,7 +396,7 @@ public class UsfTests
var (tseriesResult, _) = Usf.Calculate(series, 10);
// Calculate with Span API
Usf.Calculate(source.AsSpan(), output.AsSpan(), 10);
Usf.Batch(source.AsSpan(), output.AsSpan(), 10);
// Compare results
for (int i = 0; i < 100; i++)
@@ -418,7 +418,7 @@ public class UsfTests
}
// Warm up
Usf.Calculate(source.AsSpan(), output.AsSpan(), 100);
Usf.Batch(source.AsSpan(), output.AsSpan(), 100);
// This test verifies the method runs without throwing
Assert.True(double.IsFinite(output[^1]));
@@ -430,7 +430,7 @@ public class UsfTests
double[] source = [100, 110, double.NaN, 120, 130];
double[] output = new double[5];
Usf.Calculate(source.AsSpan(), output.AsSpan(), 3);
Usf.Batch(source.AsSpan(), output.AsSpan(), 3);
// All outputs should be finite
foreach (var val in output)
+1 -1
View File
@@ -68,7 +68,7 @@ public sealed class UsfValidationTests : IDisposable
// 3. Span Mode
double[] sourceData = _testData.RawData.ToArray();
double[] spanOutput = new double[sourceData.Length];
Usf.Calculate(sourceData.AsSpan(), spanOutput.AsSpan(), period);
Usf.Batch(sourceData.AsSpan(), spanOutput.AsSpan(), period);
// Compare batch vs streaming
Assert.Equal(batchResult.Count, streamingResults.Count);
+9 -9
View File
@@ -315,15 +315,8 @@ public sealed class Usf : AbstractBase
}
}
public static (TSeries Results, Usf Indicator) Calculate(TSeries source, int period)
{
var usf = new Usf(period);
TSeries results = usf.Update(source);
return (results, usf);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period)
public static void Batch(ReadOnlySpan<double> source, Span<double> output, int period)
{
if (period <= 0)
{
@@ -353,6 +346,13 @@ public sealed class Usf : AbstractBase
CalculateCore(source, output, c1, c2, c3, period, ref state);
}
public static (TSeries Results, Usf Indicator) Calculate(TSeries source, int period)
{
var usf = new Usf(period);
TSeries results = usf.Update(source);
return (results, usf);
}
public override void Reset()
{
_state = State.New();
@@ -371,4 +371,4 @@ public sealed class Usf : AbstractBase
}
base.Dispose(disposing);
}
}
}