StockSharp/StockSharp · error · ArgumentOutOfRangeException

Specified argument was out of the range of valid values. (Pa

Error message

Specified argument was out of the range of valid values. (Parameter 'parameters')

What it means

GpuPassThroughCalculator.Calculate throws ArgumentOutOfRangeException when parameters is empty. The guard at line 52-53 requires at least one GpuPassThroughParams entry since kernel extents and output sizing depend on parameters.Length.

Source

Thrown at Algo.Gpu/Indicators/GpuPassThroughCalculator.cs:53

	/// <param name="context">ILGPU context.</param>
	/// <param name="accelerator">ILGPU accelerator.</param>
	public GpuPassThroughCalculator(Context context, Accelerator accelerator)
		: base(context, accelerator)
	{
		_kernel = Accelerator.LoadAutoGroupedStreamKernel<Index3D, ArrayView<GpuCandle>, ArrayView<GpuIndicatorResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuPassThroughParams>>(PassThroughParamsSeriesKernel);
	}

	/// <inheritdoc />
	public override GpuIndicatorResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuPassThroughParams[] parameters)
	{
		ArgumentNullException.ThrowIfNull(candlesSeries);
		ArgumentNullException.ThrowIfNull(parameters);

		if (candlesSeries.Length == 0)
			throw new ArgumentOutOfRangeException(nameof(candlesSeries));

		if (parameters.Length == 0)
			throw new ArgumentOutOfRangeException(nameof(parameters));

		var seriesCount = candlesSeries.Length;

		var totalSize = 0;
		var seriesOffsets = new int[seriesCount];
		var seriesLengths = new int[seriesCount];

		for (var s = 0; s < seriesCount; s++)
		{
			seriesOffsets[s] = totalSize;
			var len = candlesSeries[s]?.Length ?? 0;
			seriesLengths[s] = len;
			totalSize += len;
		}

		var flatCandles = new GpuCandle[totalSize];
		var maxLen = 0;
		var offset = 0;

View on GitHub (pinned to 601a191de6)

Solutions

  1. Check parameters.Length > 0 before the call and short-circuit with an empty result if no variants are needed.
  2. Ensure the upstream param builder always yields at least a default entry.
  3. Catch ArgumentOutOfRangeException only as a last resort; validation-first is the contract this class enforces.

Example fix

// before
calc.Calculate(candles, params);

// after
if (params.Length == 0)
    return Array.Empty<GpuIndicatorResult[][]>();
calc.Calculate(candles, params);
Defensive patterns

Strategy: validation

Validate before calling

if (parameters is null || parameters.Length == 0)
    return Array.Empty<GpuIndicatorResult[][]>();
var results = calculator.Calculate(candlesSeries, parameters);

Type guard

static bool HasParams<T>(T[] parameters) => parameters is { Length: > 0 };

Prevention

When it happens

Trigger: Calling GpuPassThroughCalculator.Calculate(candles, Array.Empty<GpuPassThroughParams>()). A params builder returns an empty array because no variants matched a config range.

Common situations: A pass-through diagnostic harness where the params list is built from a filter that can be empty. Config reloads that drop all param entries. Param sweeps whose min/step/range resolve to zero iterations.

Related errors


AI-assisted analysis of StockSharp/StockSharp@601a191de6 (2026-08-13). Data as JSON: /api/errors/ed0c865a1920dfd1. Report an issue: GitHub.