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
@@ -397,7 +397,7 @@ public class JvoltyTests
// Span calculation
var output = new double[series.Count];
Jvolty.Calculate(series.Values, output, 10);
Jvolty.Batch(series.Values, output, 10);
// Compare last value (after warmup)
Assert.Equal(streamingLast, output[series.Count - 1], 1e-6);
@@ -435,7 +435,7 @@ public class JvoltyTests
var source = new double[10];
var output = new double[5]; // Wrong size
var ex = Assert.Throws<ArgumentException>(() => Jvolty.Calculate(source, output, 10));
var ex = Assert.Throws<ArgumentException>(() => Jvolty.Batch(source, output, 10));
Assert.Equal("output", ex.ParamName);
}
@@ -445,7 +445,7 @@ public class JvoltyTests
var source = Array.Empty<double>();
var output = Array.Empty<double>();
var exception = Record.Exception(() => Jvolty.Calculate(source, output, 10));
var exception = Record.Exception(() => Jvolty.Batch(source, output, 10));
Assert.Null(exception);
}
@@ -455,7 +455,7 @@ public class JvoltyTests
var source = new double[10];
var output = new double[10];
Assert.Throws<ArgumentOutOfRangeException>(() => Jvolty.Calculate(source, output, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => Jvolty.Batch(source, output, 0));
}
// ============== Edge Cases ==============
+15 -3
View File
@@ -37,6 +37,7 @@ public sealed class Jvolty : AbstractBase
private readonly RingBuffer _volBuffer;
private readonly TValuePublishedHandler _handler;
private readonly ITValuePublisher? _source;
private bool _disposed;
// Streaming state (current + previous snapshot for isNew=false)
private State _s;
@@ -293,9 +294,13 @@ public sealed class Jvolty : AbstractBase
protected override void Dispose(bool disposing)
{
if (disposing && _source != null)
if (!_disposed)
{
_source.Pub -= _handler;
if (disposing && _source != null)
{
_source.Pub -= _handler;
}
_disposed = true;
}
base.Dispose(disposing);
}
@@ -320,7 +325,7 @@ public sealed class Jvolty : AbstractBase
/// <summary>
/// Static helper for span-based calculation.
/// </summary>
public static void Calculate(ReadOnlySpan<double> source,
public static void Batch(ReadOnlySpan<double> source,
Span<double> output,
int period)
{
@@ -341,6 +346,13 @@ public sealed class Jvolty : AbstractBase
}
}
public static (TSeries Results, Jvolty Indicator) Calculate(TSeries source, int period)
{
var indicator = new Jvolty(period);
TSeries results = indicator.Update(source);
return (results, indicator);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private double CalculateTrimmedMean(double fallback)
{