style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
@@ -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));
+24 -4
View File
@@ -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);
}
}
}