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
+10 -3
View File
@@ -296,8 +296,15 @@ public class MraeTests
var actual = new TSeries();
var predicted = new TSeries();
for (int i = 1; i <= 10; i++) actual.Add(DateTime.UtcNow, i * 10);
for (int i = 1; i <= 5; i++) predicted.Add(DateTime.UtcNow, i * 10);
for (int i = 1; i <= 10; i++)
{
actual.Add(DateTime.UtcNow, i * 10);
}
for (int i = 1; i <= 5; i++)
{
predicted.Add(DateTime.UtcNow, i * 10);
}
Assert.Throws<ArgumentException>(() => Mrae.Calculate(actual, predicted, 3));
}
@@ -330,4 +337,4 @@ public class MraeTests
Assert.Equal(0.1, mrae.Last.Value, 10);
}
}
}
+20 -2
View File
@@ -52,7 +52,9 @@ public sealed class Mrae : BiInputIndicatorBase
public static TSeries Calculate(TSeries actual, TSeries predicted, int period)
{
if (actual.Count != predicted.Count)
{
throw new ArgumentException("Actual and predicted series must have the same length", nameof(predicted));
}
int len = actual.Count;
var t = new List<long>(len);
@@ -75,12 +77,20 @@ public sealed class Mrae : BiInputIndicatorBase
public static void Batch(ReadOnlySpan<double> actual, ReadOnlySpan<double> predicted, Span<double> output, int period)
{
if (actual.Length != predicted.Length || actual.Length != output.Length)
{
throw new ArgumentException("All spans must have the same length", nameof(output));
}
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
int len = actual.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
// Pre-compute relative errors (same as percentage errors but without *100)
const int StackAllocThreshold = 256;
@@ -130,14 +140,22 @@ public sealed class Mrae : BiInputIndicatorBase
double pred = predicted[i];
if (double.IsFinite(act) && Math.Abs(act) >= Epsilon)
{
lastValidActual = act;
}
else
{
act = lastValidActual;
}
if (double.IsFinite(pred))
{
lastValidPredicted = pred;
}
else
{
pred = lastValidPredicted;
}
double absActual = Math.Abs(act);
output[i] = absActual > Epsilon
@@ -145,4 +163,4 @@ public sealed class Mrae : BiInputIndicatorBase
: 0.0;
}
}
}
}