mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
normalization of methods
This commit is contained in:
@@ -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++)
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user