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
@@ -134,4 +134,4 @@ public class LineartransIndicatorTests
// Identity transform: 1.0 * 42.5 + 0.0 = 42.5
Assert.Equal(42.5, indicator.LinesSeries[0].GetValue(0), 1e-10);
}
}
}
@@ -46,7 +46,10 @@ public class LineartransIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
if (_lineartrans == null || _selector == null) return;
if (_lineartrans == null || _selector == null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
double value = _selector(item);
@@ -59,4 +62,4 @@ public class LineartransIndicator : Indicator, IWatchlistIndicator
LinesSeries[0].SetValue(_lineartrans.Last.Value, isHot, ShowColdValues);
}
}
}
@@ -172,7 +172,9 @@ public class LineartransTests
var time = DateTime.UtcNow;
for (int i = 0; i < 5; i++)
{
series.Add(new TValue(time.AddSeconds(i), i * 10.0), true);
}
var result = linear.Update(series);
@@ -191,7 +193,9 @@ public class LineartransTests
var time = DateTime.UtcNow;
for (int i = 0; i < 3; i++)
{
series.Add(new TValue(time.AddSeconds(i), 10.0 * (i + 1)), true);
}
var result = Lineartrans.Calculate(series, slope: 0.5, intercept: 5.0);
@@ -257,7 +261,9 @@ public class LineartransTests
var streamIndicator = new Lineartrans(slope, intercept);
var streamResult = new TSeries();
for (int i = 0; i < series.Count; i++)
{
streamResult.Add(streamIndicator.Update(series[i], true), true);
}
// Span
var spanOutput = new double[series.Count];
@@ -270,4 +276,4 @@ public class LineartransTests
Assert.Equal(batchResult[i].Value, spanOutput[i], 1e-10);
}
}
}
}
@@ -153,7 +153,9 @@ public class LineartransValidationTests
// Create shifted series
var shifted = new TSeries();
for (int i = 0; i < series.Count; i++)
{
shifted.Add(new TValue(series[i].Time, series[i].Value + offset), true);
}
// a * (x + offset) should equal a*x + a*offset
var scaledSum = Lineartrans.Calculate(shifted, a, 0.0);
@@ -264,4 +266,4 @@ public class LineartransValidationTests
Assert.Equal(expected, result[i].Value, 1e-5);
}
}
}
}
+20
View File
@@ -38,9 +38,14 @@ public sealed class Lineartrans : AbstractBase
public Lineartrans(double slope = 1.0, double intercept = 0.0)
{
if (!double.IsFinite(slope))
{
throw new ArgumentException("Slope must be a finite number", nameof(slope));
}
if (!double.IsFinite(intercept))
{
throw new ArgumentException("Intercept must be a finite number", nameof(intercept));
}
_slope = slope;
_intercept = intercept;
@@ -67,9 +72,13 @@ public sealed class Lineartrans : AbstractBase
public override TValue Update(TValue input, bool isNew = true)
{
if (isNew)
{
_p_state = _state;
}
else
{
_state = _p_state;
}
double value = input.Value;
double result;
@@ -129,13 +138,24 @@ public sealed class Lineartrans : AbstractBase
double slope = 1.0, double intercept = 0.0)
{
if (source.Length == 0)
{
throw new ArgumentException("Source cannot be empty", nameof(source));
}
if (output.Length < source.Length)
{
throw new ArgumentException("Output length must be >= source length", nameof(output));
}
if (!double.IsFinite(slope))
{
throw new ArgumentException("Slope must be a finite number", nameof(slope));
}
if (!double.IsFinite(intercept))
{
throw new ArgumentException("Intercept must be a finite number", nameof(intercept));
}
// Check for non-finite values - if any exist, use scalar path only
// Note: For very large arrays, SIMD-based NaN detection could be faster,