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
@@ -94,7 +94,7 @@ public class SlopeTests
// Output must be same length as source
Assert.Throws<ArgumentException>(() =>
Slope.Calculate(source.AsSpan(), wrongSizeOutput.AsSpan()));
Slope.Batch(source.AsSpan(), wrongSizeOutput.AsSpan()));
}
[Fact]
@@ -107,7 +107,7 @@ public class SlopeTests
// 1. Batch Mode (static span)
var tValues = series.Values.ToArray();
var batchOutput = new double[tValues.Length];
Slope.Calculate(tValues, batchOutput);
Slope.Batch(tValues, batchOutput);
double expected = batchOutput[^1];
// 2. Streaming Mode
@@ -119,7 +119,7 @@ public class SlopeTests
double streamingResult = streamingInd.Last.Value;
// 3. TSeries Batch Mode
var batchSeriesResult = Slope.Calculate(series);
var batchSeriesResult = Slope.Batch(series);
double tseriesResult = batchSeriesResult.Last.Value;
Assert.Equal(expected, streamingResult, precision: 9);
@@ -194,7 +194,7 @@ public class SlopeTests
// Batch
var batchResults = new double[count];
Slope.Calculate(data, batchResults);
Slope.Batch(data, batchResults);
// Compare
for (int i = 0; i < count; i++)
+1 -1
View File
@@ -104,7 +104,7 @@ public class SlopeValidationTests
double[] expected = [0, 2, 2, 2, 2, 2];
double[] output = new double[data.Length];
Slope.Calculate(data, output);
Slope.Batch(data, output);
for (int i = 0; i < data.Length; i++)
{
+11 -4
View File
@@ -114,7 +114,7 @@ public sealed class Slope : AbstractBase
var tSpan = CollectionsMarshal.AsSpan(t);
var vSpan = CollectionsMarshal.AsSpan(v);
Calculate(sourceValues, vSpan);
Batch(sourceValues, vSpan);
sourceTimes.CopyTo(tSpan);
// Prime state with last value
@@ -145,7 +145,7 @@ public sealed class Slope : AbstractBase
}
}
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var slope = new Slope();
return slope.Update(source);
@@ -155,7 +155,7 @@ public sealed class Slope : AbstractBase
/// Calculates first derivative (slope) for a span.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> source, Span<double> output)
public static void Batch(ReadOnlySpan<double> source, Span<double> output)
{
if (source.Length != output.Length)
{
@@ -290,4 +290,11 @@ public sealed class Slope : AbstractBase
output[i] = curr - prev;
}
}
}
public static (TSeries Results, Slope Indicator) Calculate(TSeries source)
{
var indicator = new Slope();
TSeries results = indicator.Update(source);
return (results, indicator);
}
}