Enum UnaryOp
Unary operations supported by kernel providers.
public enum UnaryOp
Fields
Negate = 0Abs = 1Fabs = 2np.fabs — the float-only absolute value. The KERNEL is identical to Abs on the float loops (clear the IEEE sign bit), so every emit site aliases Fabs to Abs; it is a DISTINCT op only so it reports the ufunc name "fabs" (not "absolute") in errors and carries its own float-tier dtype resolution (see
DefaultEngine.Fabs). Never has complex/int input at the kernel —Fabsrejects complex and promotes int→float before dispatch.Sqrt = 3Exp = 4Log = 5Sin = 6Cos = 7Tan = 8Exp2 = 9Expm1 = 10Log2 = 11Log10 = 12Log1p = 13Sinh = 14Cosh = 15Tanh = 16ASin = 17ACos = 18ATan = 19Asinh = 20Acosh = 21Atanh = 22Sign = 23Ceil = 24Floor = 25Round = 26Truncate = 27Reciprocal = 28Square = 29Cbrt = 30Deg2Rad = 31Rad2Deg = 32BitwiseNot = 33LogicalNot = 34Logical NOT for boolean arrays (! operator, not ~ bitwise)
Positive = 35Identity at every dtype (NumPy 'positive'; also the masked-copy vehicle for out=/where= compositions)
IsFinite = 36Test element-wise for finiteness (not infinity and not NaN)
IsNan = 37Test element-wise for NaN
IsInf = 38Test element-wise for positive or negative infinity
IsPosInf = 39Test element-wise for positive infinity (np.isposinf). x == +inf.
IsNegInf = 40Test element-wise for negative infinity (np.isneginf). x == -inf.
SignBit = 41Test element-wise whether the IEEE sign bit is set (np.signbit). Returns bool. This is NOT
x < 0: it is defined on the raw bit pattern, so-0.0and a negative NaN are True while+0.0,+infand a positive NaN are False. For signed integers it coincides withx < 0(the two's-complement MSB); for unsigned integers / bool it is always False; complex has no loop (rejected at the np.* layer).Conjugate = 42Complex conjugate (np.conjugate / np.conj). Identity at every real dtype (bool/int/char/half/single/double/decimal) — the loaded value IS the result — and flips the sign of the imaginary part for Complex (via
System.Numerics.Complex.Conjugate). Dtype is preserved (never promoted), matching NumPy's per-dtype conjugate loops.Spacing = 43Distance to the adjacent representable value away from zero — one ULP (np.spacing). Float-only ufunc (ee/ff/dd loops + NumSharp's decimal extension; complex has NO loop). float32/float64 are SIGNED (carry the sign of x, +minsubnormal at ±0) via the raw bit-increment
reinterpret(bits(x)+1) - x; float16 is NumPy's separate always-positivenpy_half_spacing. See NumSharp.Utilities.NDSpacingMath.BitwiseCount = 44Population count of the absolute value — the number of set bits in
|x|(np.bitwise_count), NumPy'snpy_popcount(a < 0 ? -a : a). INTEGER/BOOL ONLY: every supported dtype (bool/byte/sbyte/int16/uint16/int32/uint32/int64/uint64/char) maps to a uint8 result, float/complex/decimal/half raise the no-loop TypeError at the np.* boundary. Two consequences that make it behave like the float classification predicates (IsNan etc.) rather than an ordinary math op: it CONSUMES the input dtype and the emitter itself yields the (byte) result — the scalar/strided loops must NOT convert input→output first (which would truncate a wide value to 8 bits before counting) — and the output dtype is fixed regardless of input width. Signed negatives count the magnitude (bitwise_count(-1)==1, not 8; the min value's two's-complement negation wraps to itself, sobitwise_count(int8 -128)==1), computed via a branchless abs ((x^(x>>w-1))-(x>>w-1)) beforeBitOperations.PopCount.Rint = 45Round to the nearest integer, half-to-even (np.rint) — the TRUE ufunc form of round-half-to-even. The VALUE computation is IDENTICAL to Round (both are
Math.Round's default banker's rounding), so every emit site ALIASES Rint to Round (the Fabs/Abs pattern); it is a DISTINCT op only because its DTYPE rule differs — unlike Round (which preserves the input dtype: an integer array stays that integer type),rintPROMOTES to a float tier (bool/int8/uint8→float16, int16/uint16→float32, int32+→float64; float/complex/decimal preserved), so it never has an integertypeat the kernel. NumSharp's enginenp.rintreaches Round's kernel through Round with a float return type; this separate op exists for the fused expression engine (NDExpr), whose one-op-per-node model needs a distinct node to carry rint's float-tier typing while sharing Round's kernel.Real = 46Real part (np.real). complex128 → float64 (extract the real lane); every REAL dtype is the IDENTITY with its dtype PRESERVED (the real part of a real number is itself). NOT a ufunc, so there is NO engine kernel for this op — it exists ONLY for the fused expression engine (NDExpr), which handles it entirely in
UnaryNode.EmitScalar(a complex child calls RealPart(Complex); a real child is emitted unchanged) and never reachesDirectILKernelGenerator.EmitUnaryScalarOperation.Imag = 47Imaginary part (np.imag). complex128 → float64 (extract the imaginary lane); every REAL dtype yields ZERO with its dtype PRESERVED (the imaginary part of a real number is zero). Like Real it is NOT a ufunc and has NO engine kernel — the fused expression engine handles it in
UnaryNode.EmitScalar(a complex child calls ImagPart(Complex); a real child pushes a zero of the preserved dtype, the input VALUE unread — matching np.imag'szeros_like).Angle = 48Phase angle in radians (np.angle, radians only — no
deg=in the fused primitive). complex128 → float64 asatan2(imag, real); a REAL input isatan2(0, x)(0 for x ≥ 0, pi for x < 0, NaN → NaN) at NumPy's per-dtype float tier (DefaultEngine.AngleRealTier: bool/int32+/f64 → f64, int8/uint8/f16 → f16, int16/uint16/char/f32 → f32). NOT a ufunc / no engine kernel — the fused expression engine handles it inUnaryNode.EmitScalar(Angle(Complex) for a complex child,Math.Atan2(0, x)for a real one). Host-libm (atan2), so bit-exact only within the host-pinned evaluate tier.