torch.CumShape
export type CumShape<S extends Shape, Dim extends number> = number extends Dim
? S // Dynamic dim, can't check
: number extends S['length']
? S // Dynamic shape
: LessThan<Dim, S['length']> extends true
? S // Valid! Return unchanged shape
: dimension_error_out_of_range<Dim, S['length']>;Sextends ShapeDimextends numberCompute output shape of cumulative operations (cumsum, cumprod) with bounds checking. Cumulative ops preserve shape but require dim < rank.
Examples
type R1 = CumShape<readonly [2, 3, 4], 1>; // readonly [2, 3, 4] ✓
type R2 = CumShape<readonly [2, 3], 5>; // dimension_error_out_of_range<5, 2>