Table of Contents

Class EmathModule

Namespace
NumSharp
Assembly
NumSharp.dll

The numpy.emath (numpy.lib.scimath) module surface, reachable as emath. Holds the nine automatic-domain functions (sqrt(NDArray), log(NDArray), log2(NDArray), log10(NDArray), logn(NDArray, NDArray), power(NDArray, NDArray), arccos(NDArray), arcsin(NDArray), arctanh(NDArray)).

Each function's body is its engine member (EmathSqrt(NDArray) and its siblings in TensorEngine.Scimath.cs), which DefaultEngine implements as a PURE COMPOSITION over the existing np.* ufuncs — a domain scan (np.any of a comparison), an optional cast to complex128, then the standard real/complex ufunc — a line-for-line port of NumPy 2.4.2 numpy/lib/_scimath_impl.py. The methods here keep the signatures, the class-boundary statements and one call. Because the numerics ARE the already-validated np.sqrt/np.log/np.arccos/… kernels, emath introduces no divergence of its own — every difference from NumPy traces to a documented property of the underlying ufunc (validated by an 897-case layout-aware differential, 775 bit-exact + 122 accounted). Results are bit-identical to NumPy on every REAL path and on the bit-exact COMPLEX paths (complex sqrt/log/ log10/log2); the remaining complex paths inherit the underlying complex ufunc's precision: arccos(NDArray)/arcsin(NDArray)/arctanh(NDArray) ride the complex-unary ≤~1-ULP envelope (a property of np.arccos etc. itself — e.g. plain np.arccos(-0.5+0j) is already 1 ULP from NumPy — not something emath adds), and power(NDArray, NDArray) with a non-integer exponent is allclose (the F5 complex-power divergence, see that method).

ONE dtype-only divergence (F1): NumSharp has a single complex type (complex128) and no complex64, so a triggering float32/float16/small-int input returns complex128 where NumPy returns complex64. The VALUES are bit-identical; only the dtype width differs (the library-wide "no complex64" divergence, issue #569).

[ModuleName("np.emath")]
public class EmathModule
Inheritance
EmathModule
Inherited Members

Remarks

Methods

arccos(NDArray)

Compute the inverse cosine of x, returning the complex principal value for real inputs with |x| > 1 (unlike arccos(NDArray, NDArray, NDArray, DType), which returns nan there). Port of NumPy 2.4.2 numpy.emath.arccos.

public NDArray arccos(NDArray x)

Parameters

x NDArray

The value(s) whose arccos is required. A scalar or C# array converts implicitly.

Returns

NDArray

arccos(x). For |x| <= 1 a real result in [0, pi]; any real element with |x| > 1 (or an infinite element, whose |x| > 1) promotes the whole array to complex128. A nan element does NOT trigger the promotion (|nan| > 1 is false). A 0-D array for a scalar input. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

arcsin(NDArray)

Compute the inverse sine of x, returning the complex principal value for real inputs with |x| > 1. Port of NumPy 2.4.2 numpy.emath.arcsin.

public NDArray arcsin(NDArray x)

Parameters

x NDArray

The value(s) whose arcsin is required. A scalar or C# array converts implicitly.

Returns

NDArray

arcsin(x). For |x| <= 1 a real result in [-pi/2, pi/2]; any real element with |x| > 1 promotes the whole array to complex128. A 0-D array for a scalar input. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

arctanh(NDArray)

Compute the inverse hyperbolic tangent of x, returning the complex principal value for real inputs with |x| > 1. Port of NumPy 2.4.2 numpy.emath.arctanh.

public NDArray arctanh(NDArray x)

Parameters

x NDArray

The value(s) whose arctanh is required. A scalar or C# array converts implicitly.

Returns

NDArray

arctanh(x). For |x| < 1 a real result; any real element with |x| > 1 promotes the whole array to complex128. The boundary |x| == 1 stays REAL and yields ±inf (the promotion is strictly |x| > 1, matching NumPy). A 0-D array for a scalar input. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

log(NDArray)

Compute the natural logarithm of x, returning the complex principal value for negative real inputs (unlike log(NDArray, NDArray, NDArray, DType), which returns nan). Port of NumPy 2.4.2 numpy.emath.log.

public NDArray log(NDArray x)

Parameters

x NDArray

The value(s) whose natural log is required. A scalar or C# array converts implicitly.

Returns

NDArray

log(x). log(0) is -inf and log(inf) is inf (both stay real); a negative real element promotes the whole array to complex128 (log(-e) == 1 + pi·i). A 0-D array for a scalar input. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

log10(NDArray)

Compute the base-10 logarithm of x, returning the complex principal value for negative real inputs. Port of NumPy 2.4.2 numpy.emath.log10.

public NDArray log10(NDArray x)

Parameters

x NDArray

The value(s) whose base-10 log is required. A scalar or C# array converts implicitly.

Returns

NDArray

log10(x). log10(0) is -inf; a negative real element promotes the whole array to complex128. A 0-D array for a scalar input. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

log2(NDArray)

Compute the base-2 logarithm of x, returning the complex principal value for negative real inputs. Port of NumPy 2.4.2 numpy.emath.log2.

public NDArray log2(NDArray x)

Parameters

x NDArray

The value(s) whose base-2 log is required. A scalar or C# array converts implicitly.

Returns

NDArray

log2(x). log2(0) is -inf; a negative real element promotes the whole array to complex128. A 0-D array for a scalar input. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

logn(NDArray, NDArray)

Take the log base n of x, computed and returned in the complex domain when either argument has a negative real element. Port of NumPy 2.4.2 numpy.emath.logn — literally log(x) / log(n) after both are domain-fixed.

public NDArray logn(NDArray n, NDArray x)

Parameters

n NDArray

The base(s) of the logarithm. A scalar or C# array converts implicitly.

x NDArray

The value(s) whose log base n is required.

Returns

NDArray

log(x) / log(n). A negative real element in EITHER operand promotes that operand to complex128 (so the quotient is complex); otherwise the result is real (float64). n and x broadcast against each other via the division. Note the argument order is (n, x), matching NumPy. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

power(NDArray, NDArray)

Return x raised to the power p (x**p), promoting to the complex domain when x has a negative real element. Port of NumPy 2.4.2 numpy.emath.power.

public NDArray power(NDArray x, NDArray p)

Parameters

x NDArray

The base value(s). A scalar or C# array converts implicitly.

p NDArray

The exponent(s). Conceptually integers, but a negative exponent is legal here: unlike np.power(NDArray, NDArray) (which raises "Integers to negative integer powers" for an integer base), a negative real element in p promotes p to a float first (NumPy's _fix_int_lt_zero = p * 1.0).

Returns

NDArray

power(x, p) with x and p broadcast together. A negative base promotes the result to complex128; a negative exponent promotes p to float (so power([2,4], -2) == [0.25, 0.0625]). Divergence (F5): a negative base with a NON-integer exponent takes the complex-power path, which is allclose to NumPy but not bit-exact (the documented Complex.Pow vs npy_cpow ULP divergence); an integer exponent is bit-exact. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks

sqrt(NDArray)

Compute the square root of x, returning a complex result for negative real inputs (unlike sqrt(NDArray, NDArray, NDArray, DType), which returns nan). Port of NumPy 2.4.2 numpy.emath.sqrt.

public NDArray sqrt(NDArray x)

Parameters

x NDArray

The input value(s). A scalar or C# array converts implicitly.

Returns

NDArray

sqrt(x). If any real element is < 0 (or the input is already complex) the result is complex128; otherwise it is the ordinary real result (integer/bool promote to a float per sqrt(NDArray, NDArray, NDArray, DType)). A scalar input yields a 0-D array. -0.0 does NOT trigger the complex promotion (-0.0 < 0 is false), matching NumPy. A numpy.char.chararray operand gives a plain array: NumPy converts it with asarray (or ends with np.concatenate), which drops the class.

Remarks