Table of Contents

Enum UnaryOp

Namespace
NumSharp.Backends.Kernels
Assembly
NumSharp.dll

Unary operations supported by kernel providers.

public enum UnaryOp

Fields

Negate = 0
Abs = 1
Fabs = 2

np.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 — Fabs rejects complex and promotes int→float before dispatch.

Sqrt = 3
Exp = 4
Log = 5
Sin = 6
Cos = 7
Tan = 8
Exp2 = 9
Expm1 = 10
Log2 = 11
Log10 = 12
Log1p = 13
Sinh = 14
Cosh = 15
Tanh = 16
ASin = 17
ACos = 18
ATan = 19
Asinh = 20
Acosh = 21
Atanh = 22
Sign = 23
Ceil = 24
Floor = 25
Round = 26
Truncate = 27
Reciprocal = 28
Square = 29
Cbrt = 30
Deg2Rad = 31
Rad2Deg = 32
BitwiseNot = 33
LogicalNot = 34

Logical NOT for boolean arrays (! operator, not ~ bitwise)

Positive = 35

Identity at every dtype (NumPy 'positive'; also the masked-copy vehicle for out=/where= compositions)

IsFinite = 36

Test element-wise for finiteness (not infinity and not NaN)

IsNan = 37

Test element-wise for NaN

IsInf = 38

Test element-wise for positive or negative infinity

IsPosInf = 39

Test element-wise for positive infinity (np.isposinf). x == +inf.

IsNegInf = 40

Test element-wise for negative infinity (np.isneginf). x == -inf.

SignBit = 41

Test 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.0 and a negative NaN are True while +0.0, +inf and a positive NaN are False. For signed integers it coincides with x < 0 (the two's-complement MSB); for unsigned integers / bool it is always False; complex has no loop (rejected at the np.* layer).

Conjugate = 42

Complex 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 = 43

Distance 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-positive npy_half_spacing. See NumSharp.Utilities.NDSpacingMath.

BitwiseCount = 44

Population count of the absolute value — the number of set bits in |x| (np.bitwise_count), NumPy's npy_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, so bitwise_count(int8 -128)==1), computed via a branchless abs ((x^(x>>w-1))-(x>>w-1)) before BitOperations.PopCount.

Rint = 45

Round 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), rint PROMOTES to a float tier (bool/int8/uint8→float16, int16/uint16→float32, int32+→float64; float/complex/decimal preserved), so it never has an integer type at the kernel. NumSharp's engine np.rint reaches 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 = 46

Real 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 reaches DirectILKernelGenerator.EmitUnaryScalarOperation.

Imag = 47

Imaginary 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's zeros_like).

Angle = 48

Phase angle in radians (np.angle, radians only — no deg= in the fused primitive). complex128 → float64 as atan2(imag, real); a REAL input is atan2(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 in UnaryNode.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.