mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
style patterns
This commit is contained in:
@@ -142,7 +142,10 @@ public sealed class BilateralValidationTests : IDisposable
|
||||
_history.RemoveAt(0);
|
||||
}
|
||||
|
||||
if (_history.Count == 0) return double.NaN;
|
||||
if (_history.Count == 0)
|
||||
{
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
double sigmaS = Math.Max(_length * _sigmaSRatio, 1e-10);
|
||||
|
||||
@@ -178,7 +181,10 @@ public sealed class BilateralValidationTests : IDisposable
|
||||
|
||||
private static double CalculateStDev(List<double> values)
|
||||
{
|
||||
if (values.Count < 2) return 0;
|
||||
if (values.Count < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double avg = values.Average();
|
||||
double sumSqDiff = values.Sum(d => (d - avg) * (d - avg));
|
||||
|
||||
@@ -46,7 +46,9 @@ public sealed class Bilateral : AbstractBase
|
||||
public Bilateral(int period, double sigmaSRatio = 0.5, double sigmaRMult = 1.0)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_sigmaSRatio = sigmaSRatio;
|
||||
@@ -74,7 +76,10 @@ public sealed class Bilateral : AbstractBase
|
||||
|
||||
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
|
||||
{
|
||||
if (source.Length == 0) return;
|
||||
if (source.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_buffer.Clear();
|
||||
_state = default;
|
||||
@@ -128,7 +133,10 @@ public sealed class Bilateral : AbstractBase
|
||||
|
||||
public override TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return [];
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
int len = source.Count;
|
||||
var t = new System.Collections.Generic.List<long>(len);
|
||||
@@ -337,10 +345,14 @@ public sealed class Bilateral : AbstractBase
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> destination, int period, double sigmaSRatio = 0.5, double sigmaRMult = 1.0)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
if (destination.Length < source.Length)
|
||||
{
|
||||
throw new ArgumentException("Destination must have length >= source length", nameof(destination));
|
||||
}
|
||||
|
||||
// Rent arrays for large periods to avoid heap allocations
|
||||
double[]? rentedSpatialWeights = null;
|
||||
@@ -424,7 +436,10 @@ public sealed class Bilateral : AbstractBase
|
||||
|
||||
int currentNewestIdx = windowIdx;
|
||||
windowIdx = (windowIdx + 1) % period;
|
||||
if (count < period) count++;
|
||||
if (count < period)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
// Calculate StDev
|
||||
double invCount = 1.0 / count;
|
||||
@@ -480,9 +495,14 @@ public sealed class Bilateral : AbstractBase
|
||||
finally
|
||||
{
|
||||
if (rentedSpatialWeights != null)
|
||||
{
|
||||
ArrayPool<double>.Shared.Return(rentedSpatialWeights);
|
||||
}
|
||||
|
||||
if (rentedWindow != null)
|
||||
{
|
||||
ArrayPool<double>.Shared.Return(rentedWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,4 +534,4 @@ public sealed class Bilateral : AbstractBase
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user