feat(tests): enhance tests with GBM for noise generation and improve tolerance for MAMA validation

feat(trends): implement IDisposable in Bessel and Conv classes to manage event subscriptions
fix(trends): add validation for period and parameters in Kama and MGDI calculations
fix(trends): clamp logarithmic calculations in JMA to avoid -Infinity
This commit is contained in:
Miha Kralj
2025-12-25 20:18:14 -08:00
parent df598c810d
commit ac8b2dbb3f
20 changed files with 281 additions and 187 deletions
+31
View File
@@ -28,6 +28,12 @@ public sealed class RingBuffer : IEnumerable<double>
private int _count;
private double _sum;
// Snapshot state
private int _savedHead;
private int _savedCount;
private double _savedSum;
private double _savedValue;
/// <summary>
/// Creates a new RingBuffer with the specified capacity.
/// Uses pinned memory for SIMD compatibility.
@@ -435,6 +441,31 @@ public sealed class RingBuffer : IEnumerable<double>
_sum = source._sum;
}
/// <summary>
/// Captures the current state of the buffer.
/// Must be called BEFORE adding a new value if you intend to Restore later.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Snapshot()
{
_savedHead = _head;
_savedCount = _count;
_savedSum = _sum;
_savedValue = _buffer[_head];
}
/// <summary>
/// Restores the buffer to the state captured by Snapshot.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Restore()
{
_head = _savedHead;
_count = _savedCount;
_sum = _savedSum;
_buffer[_head] = _savedValue;
}
/// <summary>
/// Returns an enumerator that iterates through the buffer in chronological order.
/// </summary>