Table of Contents

Enum NDExprReduceKind

Namespace
NumSharp.Backends.Iteration
Assembly
NumSharp.dll

Reduction kinds supported by ReduceNode.

public enum NDExprReduceKind : byte

Fields

Sum = 0
Prod = 1
Min = 2
Max = 3
Mean = 4
Any = 5

logical_or.reduce of the nonzero-test of the child (identity False; bool result).

All = 6

logical_and.reduce of the nonzero-test of the child (identity True; bool result).

Ptp = 7

np.ptp — peak-to-peak (max - min) of the child. Result dtype is the child's (integer/unsigned overflow WRAPS exactly as NumPy's, since it is a plain subtract of two same-dtype reductions), a NaN in the child propagates to the result, and there is NO empty identity (a zero-size input raises, like Max/Min). Unlike the fold-driven kinds above it is host-delegated: ptp(NDArray, NDAxis?, NDArray, bool) runs over the materialized child — see the host divert in DefaultEngine.EvaluateReduce.

NanMin = 8

np.nanmin — minimum ignoring NaN. Result dtype is the child's; a float/complex child has its NaNs skipped (an ALL-NaN input yields NaN, matching NumPy's all-NaN-slice contract), while an integer/bool child carries no NaN and folds as a plain minimum. Host-delegated to np.nanmin(NDArray,int?,NDArray,bool,object,NDArray) over the materialized child, which is why it is TYPE-AWARE for free (the ±inf NaN-replacement sentinel that would promote an int child to float64 lives inside the engine reduction, not in an NDExpr rewrite).

NanMax = 9

np.nanmax — maximum ignoring NaN (the NanMin twin, all-NaN → NaN). Host-delegated to np.nanmax(NDArray,int?,NDArray,bool,object,NDArray) over the materialized child.

ArgMax = 10

np.argmax — the index of the maximum. Unlike every value reduction above, the result dtype is int64 (NumPy's intp), NOT the child dtype. It is host-delegated to np.argmax(NDArray,int,bool) (flat: argmax(NDArray)) over the materialized child. This is bit-exact for the same reason the M4-tail value kinds are — but the property in play is subtler than order-independence: argmax's index DOES depend on visiting order at a tie (the FIRST maximum wins, and a NaN is treated as the largest so the FIRST NaN wins), yet the materialized child is a fresh C-CONTIGUOUS buffer holding exactly NumPy's own C-order intermediate, and np.argmax walks it in that same C-order — so the tie/NaN index is deterministic and identical to np.argmax(child). There is NO empty identity (a zero-size input raises, like Max). See EvaluateDelegatingReduce.

ArgMin = 11

np.argmin — the index of the minimum (the ArgMax twin: int64 result, first-tie / first-NaN wins over the C-order materialized child). Host-delegated to np.argmin(NDArray,int,bool) / argmin(NDArray).

NanMean = 12

np.nanmean — the arithmetic mean with NaNs skipped (the Mean twin over the finite elements). Result dtype follows Mean (float16→float16 via a float32 intermediate, float32→float32, float64→float64, complex128→complex128, int/bool→float64), an ALL-NaN input yields NaN and an integer/bool child — carrying no NaN — is exactly Mean. Unlike Sum/Mean it is NOT a fold kind and NOT a factory rewrite (its per-element NaN skip changes the divisor per slab): the host materializes the child once and computes nansum(child) / count_of_non_NaN with the SAME NumPy-exact pairwise sum the M1/M2 diverts use — see DefaultEngine.EvaluateStatReduce. Bit-exact vs NumPy 2.4.2, so it carries NO MisalignedRegistry excuse.

Var = 13

np.var — the variance Σ(x−mean)² / (N−ddof) (population variance at the default ddof=0). Result dtype: float16→float16 (computed in float32), float32→float32, float64→float64, int/bool→float64, and — like NumPy — a complex128 child yields a real float64 variance (the deviations are reduced as |x−mean|²). A NaN anywhere PROPAGATES (var uses every element, unlike NanMean); ddof ≥ N divides by a clamped zero → +inf (or NaN when the numerator is zero), and an empty input yields NaN. The host materializes the child once, then runs NumPy's own two-pass _var op for op over the exact pairwise sum (mean, then Σ(x−mean)²) — see DefaultEngine.EvaluateStatReduce. The degrees-of-freedom offset is carried on the node (NumSharp.Backends.Iteration.ReduceNode.Ddof) and is part of the program identity. Bit-exact vs NumPy 2.4.2, NO excuse.

Std = 14

np.std — the standard deviation sqrt(var) (the Var twin, same result dtypes / ddof / NaN-propagation / empty→NaN semantics), applied as a final elementwise square root over the variance so it is bit-exact wherever Var is.

Remarks

Any / All are their OWN kinds, not Max / Min over a boolean child: logical_or / logical_and carry the identities False / True, so a reduction over an EMPTY input is False / True — where maximum.reduce / minimum.reduce raise "zero-size array … which has no identity". They also return bool where a bool Sum would widen to int64. The value fold is a bitwise OR / AND on a bool accumulator, which is associative AND idempotent — so the 4-accumulator unroll reorders it freely and stays bit-exact (unlike float Sum / Prod, whose order matters — the M1/M2 divert).