Class DefaultEngine
Default Tensor Engine implemented in pure micro-optimized C#.
public class DefaultEngine : TensorEngine
- Inheritance
-
DefaultEngine
- Inherited Members
- Extension Methods
Remarks
DefaultEngine is the pure C# implementation of TensorEngine. It uses ILKernelGenerator internally for SIMD-optimized kernels. All computation on NDArray should go through TensorEngine methods.
Methods
ACos(NDArray, NPTypeCode?)
Element-wise inverse cosine (arccos) using IL-generated kernels.
public override NDArray ACos(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
ACos(NDArray, Type)
public override NDArray ACos(NDArray nd, Type dtype)
Parameters
Returns
AMax(NDArray, int, Type, bool)
public override NDArray AMax(NDArray nd, int axis, Type dtype, bool keepdims = false)
Parameters
Returns
AMax(NDArray, int?, NPTypeCode?, bool)
public override NDArray AMax(NDArray nd, int? axis = null, NPTypeCode? typeCode = null, bool keepdims = false)
Parameters
ndNDArrayaxisint?typeCodeNPTypeCode?keepdimsbool
Returns
AMin(NDArray, int, Type, bool)
public override NDArray AMin(NDArray nd, int axis, Type dtype, bool keepdims = false)
Parameters
Returns
AMin(NDArray, int?, NPTypeCode?, bool)
public override NDArray AMin(NDArray nd, int? axis = null, NPTypeCode? typeCode = null, bool keepdims = false)
Parameters
ndNDArrayaxisint?typeCodeNPTypeCode?keepdimsbool
Returns
ASin(NDArray, NPTypeCode?)
Element-wise inverse sine (arcsin) using IL-generated kernels.
public override NDArray ASin(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
ASin(NDArray, Type)
public override NDArray ASin(NDArray nd, Type dtype)
Parameters
Returns
ATan(NDArray, NPTypeCode?)
Element-wise inverse tangent (arctan) using IL-generated kernels.
public override NDArray ATan(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
ATan(NDArray, Type)
public override NDArray ATan(NDArray nd, Type dtype)
Parameters
Returns
ATan2(NDArray, NDArray, NPTypeCode?)
Element-wise arc tangent of y/x choosing the quadrant correctly. NumPy: arctan2(y, x) returns the angle in radians between the positive x-axis and the point (x, y), with correct quadrant determination.
public override NDArray ATan2(NDArray y, NDArray x, NPTypeCode? typeCode = null)
Parameters
yNDArrayy-coordinates
xNDArrayx-coordinates. If y.shape != x.shape, they must be broadcastable.
typeCodeNPTypeCode?Output dtype (overrides type promotion). If null, uses NumPy rules.
Returns
- NDArray
Array of angles in radians, range [-pi, pi]
ATan2(NDArray, NDArray, Type)
Element-wise arc tangent of y/x choosing the quadrant correctly. NumPy: arctan2(y, x) returns the angle in radians between the positive x-axis and the point (x, y), with correct quadrant determination.
public override NDArray ATan2(NDArray y, NDArray x, Type dtype)
Parameters
yNDArrayy-coordinates
xNDArrayx-coordinates. If y.shape != x.shape, they must be broadcastable.
dtypeTypeOutput dtype (overrides type promotion)
Returns
- NDArray
Array of angles in radians, range [-pi, pi]
Abs(NDArray, NPTypeCode?)
Element-wise absolute value using IL-generated kernels. NumPy behavior: preserves input dtype (unlike sin/cos which promote to float).
public override NDArray Abs(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Abs(NDArray, Type)
public override NDArray Abs(NDArray nd, Type dtype)
Parameters
Returns
Add(NDArray, NDArray)
Element-wise addition using IL-generated kernels. Supports all 144 type combinations with automatic type promotion.
public override NDArray Add(NDArray lhs, NDArray rhs)
Parameters
Returns
All(NDArray)
Test whether all array elements evaluate to True (non-zero). Supports all 12 dtypes with SIMD optimization for contiguous arrays.
public override bool All(NDArray nd)
Parameters
ndNDArrayInput array
Returns
- bool
True if all elements are non-zero
All(NDArray, int)
Test whether all array elements along a given axis evaluate to True.
public override NDArray<bool> All(NDArray nd, int axis)
Parameters
Returns
AllClose(NDArray, NDArray, double, double, bool)
Returns True if two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers.The
relative difference (rtol * abs(b)) and the absolute difference
atol are added together to compare against the absolute difference
between a and b.
If either array contains one or more NaNs, False is returned.
Infs are treated as equal if they are in the same place and of the same
sign in both arrays.
public override bool AllClose(NDArray a, NDArray b, double rtol = 1E-05, double atol = 1E-08, bool equal_nan = false)
Parameters
aNDArraybNDArrayInput array to compare with a.
rtoldoubleThe relative tolerance parameter(see Notes)
atoldoubleThe absolute tolerance parameter(see Notes)
equal_nanboolWhether to compare NaN's as equal. If True, NaN's in
awill be considered equal to NaN's inbin the output array.
Returns
Any(NDArray)
Test whether any array element evaluates to True (non-zero). Supports all 12 dtypes with SIMD optimization for contiguous arrays.
public override bool Any(NDArray nd)
Parameters
ndNDArrayInput array
Returns
- bool
True if any element is non-zero
Any(NDArray, int)
Test whether any array element along a given axis evaluates to True.
public override NDArray<bool> Any(NDArray nd, int axis)
Parameters
Returns
AreBroadcastable(params NDArray[])
Checks if the given arrays can be broadcast together.
public static bool AreBroadcastable(params NDArray[] arrays)
Parameters
arraysNDArray[]
Returns
Remarks
Extracts shapes and delegates to Shape.AreBroadcastable
AreBroadcastable(params Shape[])
Checks if the given shapes can be broadcast together.
public static bool AreBroadcastable(params Shape[] shapes)
Parameters
shapesShape[]
Returns
Remarks
Delegates to Shape.AreBroadcastable
AreBroadcastable(params int[][])
Checks if the given dimension arrays can be broadcast together.
public static bool AreBroadcastable(params int[][] shapes)
Parameters
shapesint[][]
Returns
Remarks
Delegates to Shape.AreBroadcastable
ArgMax(NDArray)
public override NDArray ArgMax(NDArray a)
Parameters
aNDArray
Returns
ArgMax(NDArray, int, bool)
public override NDArray ArgMax(NDArray a, int axis, bool keepdims = false)
Parameters
Returns
ArgMin(NDArray)
public override NDArray ArgMin(NDArray a)
Parameters
aNDArray
Returns
ArgMin(NDArray, int, bool)
public override NDArray ArgMin(NDArray a, int axis, bool keepdims = false)
Parameters
Returns
BitwiseAnd(NDArray, NDArray)
Execute bitwise AND operation.
public override NDArray BitwiseAnd(NDArray lhs, NDArray rhs)
Parameters
Returns
BitwiseOr(NDArray, NDArray)
Execute bitwise OR operation.
public override NDArray BitwiseOr(NDArray lhs, NDArray rhs)
Parameters
Returns
BitwiseXor(NDArray, NDArray)
Execute bitwise XOR operation.
public override NDArray BitwiseXor(NDArray lhs, NDArray rhs)
Parameters
Returns
BooleanMask(NDArray, NDArray)
Apply a boolean mask to select elements from an array.
public override NDArray BooleanMask(NDArray arr, NDArray mask)
Parameters
Returns
- NDArray
1D array containing elements where mask is true.
Broadcast(params NDArray[])
Broadcasts multiple arrays and returns new NDArrays with broadcasted shapes.
public static NDArray[] Broadcast(params NDArray[] arrays)
Parameters
arraysNDArray[]
Returns
- NDArray[]
Remarks
Extracts shapes, delegates to Shape.Broadcast, wraps results in NDArray
Broadcast(Shape, Shape)
Broadcasts two shapes and returns the broadcasted shapes with computed strides.
public static (Shape LeftShape, Shape RightShape) Broadcast(Shape leftShape, Shape rightShape)
Parameters
Returns
Remarks
Delegates to Shape.Broadcast
Broadcast(params Shape[])
Broadcasts multiple shapes and returns the broadcasted shapes with computed strides.
public static Shape[] Broadcast(params Shape[] shapes)
Parameters
shapesShape[]
Returns
- Shape[]
Remarks
Delegates to Shape.Broadcast
Cast(NDArray, NPTypeCode, bool)
public override NDArray Cast(NDArray nd, NPTypeCode dtype, bool copy)
Parameters
ndNDArraydtypeNPTypeCodecopybool
Returns
Cast(NDArray, Type, bool)
public override NDArray Cast(NDArray nd, Type dtype, bool copy)
Parameters
Returns
Cbrt(NDArray, NPTypeCode?)
Element-wise cube root using IL-generated kernels. Computes the cube root of each element.
public override NDArray Cbrt(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Cbrt(NDArray, Type)
public override NDArray Cbrt(NDArray nd, Type dtype)
Parameters
Returns
Ceil(NDArray, NPTypeCode?)
Element-wise ceiling using IL-generated kernels.
public override NDArray Ceil(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Ceil(NDArray, Type)
public override NDArray Ceil(NDArray nd, Type dtype)
Parameters
Returns
Clip(NDArray, ValueType, ValueType, NPTypeCode?)
Clips array values to a specified range [min, max]. NumPy behavior:
- NaN in data propagates through (result is NaN)
- NaN in scalar min/max: entire array becomes NaN (for floating-point)
public override NDArray Clip(NDArray lhs, ValueType min, ValueType max, NPTypeCode? typeCode = null)
Parameters
lhsNDArrayminValueTypemaxValueTypetypeCodeNPTypeCode?
Returns
Remarks
Implementation uses IL kernels with:
- SIMD for contiguous arrays (Vector256/Vector128)
- Scalar iteration for strided arrays (via TransformOffset)
The Cast(copy: true) call ensures we have a contiguous output array, so the SIMD path is always taken for supported types.
Clip(NDArray, ValueType, ValueType, Type)
public override NDArray Clip(NDArray lhs, ValueType min, ValueType max, Type dtype)
Parameters
Returns
ClipNDArray(NDArray, NDArray, NDArray, NPTypeCode?, NDArray)
public override NDArray ClipNDArray(NDArray lhs, NDArray min, NDArray max, NPTypeCode? typeCode = null, NDArray @out = null)
Parameters
lhsNDArrayminNDArraymaxNDArraytypeCodeNPTypeCode?outNDArray
Returns
ClipNDArray(NDArray, NDArray, NDArray, Type, NDArray)
public override NDArray ClipNDArray(NDArray lhs, NDArray min, NDArray max, Type dtype, NDArray @out = null)
Parameters
Returns
Compare(NDArray, NDArray)
Element-wise equal comparison (==). Overrides TensorEngine.Compare - used by the == operator.
public override NDArray<bool> Compare(NDArray lhs, NDArray rhs)
Parameters
Returns
Cos(NDArray, NPTypeCode?)
Element-wise cosine using IL-generated kernels.
public override NDArray Cos(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Cos(NDArray, Type)
public override NDArray Cos(NDArray nd, Type dtype)
Parameters
Returns
Cosh(NDArray, NPTypeCode?)
Element-wise hyperbolic cosine using IL-generated kernels.
public override NDArray Cosh(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Cosh(NDArray, Type)
public override NDArray Cosh(NDArray nd, Type dtype)
Parameters
Returns
CountNonZero(NDArray)
Count the number of non-zero elements in the array.
public override int CountNonZero(NDArray nd)
Parameters
ndNDArray
Returns
Remarks
NumPy-aligned: np.count_nonzero([0, 1, 0, 2]) = 2
CountNonZero(NDArray, int, bool)
Count non-zero elements along a specific axis.
public override NDArray CountNonZero(NDArray nd, int axis, bool keepdims = false)
Parameters
Returns
CreateNDArray(Shape, Type, IArraySlice, char)
public override NDArray CreateNDArray(Shape shape, Type dtype = null, IArraySlice buffer = null, char order = 'C')
Parameters
shapeShapedtypeTypebufferIArraySliceorderchar
Returns
CreateNDArray(Shape, Type, Array, char)
public override NDArray CreateNDArray(Shape shape, Type dtype = null, Array buffer = null, char order = 'C')
Parameters
Returns
CumSumElementwise<T>(NDArray, NPTypeCode?)
public NDArray CumSumElementwise<T>(NDArray arr, NPTypeCode? typeCode) where T : unmanaged
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
Type Parameters
T
Deg2Rad(NDArray, NPTypeCode?)
Element-wise degrees to radians conversion using IL-generated kernels. Computes x * (Ï€/180).
public override NDArray Deg2Rad(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Deg2Rad(NDArray, Type)
public override NDArray Deg2Rad(NDArray nd, Type dtype)
Parameters
Returns
Divide(NDArray, NDArray)
Element-wise division using IL-generated kernels. Supports all 144 type combinations with automatic type promotion.
public override NDArray Divide(NDArray lhs, NDArray rhs)
Parameters
Returns
Dot(NDArray, NDArray)
public override NDArray Dot(NDArray left, NDArray right)
Parameters
Returns
Remarks
DotNDMD(NDArray, NDArray)
N-D x M-D dot product: sum product over last axis of lhs and second-to-last axis of rhs. dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
public static NDArray DotNDMD(NDArray lhs, NDArray rhs)
Parameters
Returns
Remarks
This replaces the original ~15,880 line implementation that used nested switch statements for every combination of dimension counts. The new implementation uses dynamic iteration with optional SIMD optimization for contiguous float/double arrays.
Exp(NDArray, NPTypeCode?)
Element-wise exponential using IL-generated kernels.
public override NDArray Exp(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Exp(NDArray, Type)
public override NDArray Exp(NDArray nd, Type dtype)
Parameters
Returns
Exp2(NDArray, NPTypeCode?)
Element-wise 2^x using IL-generated kernels.
public override NDArray Exp2(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Exp2(NDArray, Type)
public override NDArray Exp2(NDArray nd, Type dtype)
Parameters
Returns
Expm1(NDArray, NPTypeCode?)
Element-wise exp(x) - 1 using IL-generated kernels.
public override NDArray Expm1(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Expm1(NDArray, Type)
public override NDArray Expm1(NDArray nd, Type dtype)
Parameters
Returns
Floor(NDArray, NPTypeCode?)
Element-wise floor using IL-generated kernels.
public override NDArray Floor(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Floor(NDArray, Type)
public override NDArray Floor(NDArray nd, Type dtype)
Parameters
Returns
FloorDivide(NDArray, NDArray, NPTypeCode?)
public override NDArray FloorDivide(NDArray lhs, NDArray rhs, NPTypeCode? typeCode = null)
Parameters
lhsNDArrayrhsNDArraytypeCodeNPTypeCode?
Returns
FloorDivide(NDArray, NDArray, Type)
public override NDArray FloorDivide(NDArray lhs, NDArray rhs, Type dtype)
Parameters
Returns
FloorDivide(NDArray, ValueType, NPTypeCode?)
public override NDArray FloorDivide(NDArray lhs, ValueType rhs, NPTypeCode? typeCode = null)
Parameters
lhsNDArrayrhsValueTypetypeCodeNPTypeCode?
Returns
FloorDivide(NDArray, ValueType, Type)
public override NDArray FloorDivide(NDArray lhs, ValueType rhs, Type dtype)
Parameters
Returns
GetStorage(NPTypeCode)
Get storage for given typeCode.
public override UnmanagedStorage GetStorage(NPTypeCode typeCode)
Parameters
typeCodeNPTypeCode
Returns
GetStorage(Type)
Get storage for given dtype.
public override UnmanagedStorage GetStorage(Type dtype)
Parameters
dtypeType
Returns
Greater(NDArray, NDArray)
Element-wise greater-than comparison (>).
public override NDArray<bool> Greater(NDArray lhs, NDArray rhs)
Parameters
Returns
GreaterEqual(NDArray, NDArray)
Element-wise greater-than-or-equal comparison (>=).
public override NDArray<bool> GreaterEqual(NDArray lhs, NDArray rhs)
Parameters
Returns
Invert(NDArray, NPTypeCode?)
Element-wise bitwise NOT using IL-generated kernels. For integers: computes ~x (ones complement). For booleans: computes logical NOT (NumPy behavior).
public override NDArray Invert(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Invert(NDArray, Type)
public override NDArray Invert(NDArray nd, Type dtype)
Parameters
Returns
IsClose(NDArray, NDArray, double, double, bool)
Returns a boolean array where two arrays are element-wise equal within a
tolerance.
The tolerance values are positive, typically very small numbers.The
relative difference (rtol * abs(b)) and the absolute difference
atol are added together to compare against the absolute difference
between a and b.
Warning: The default atol is not appropriate for comparing numbers
that are much smaller than one(see Notes).
See also allclose
Notes: For finite values, isclose uses the following equation to test whether two floating point values are equivalent.
absolute(`a` - `b`) less than or equal to (`atol` + `rtol` * absolute(`b`))
Unlike the built-in math.isclose, the above equation is not symmetric
in a and b -- it assumes b is the reference value -- so that
isclose(a, b) might be different from isclose(b, a). Furthermore,
the default value of atol is not zero, and is used to determine what
small values should be considered close to zero.The default value is
appropriate for expected values of order unity: if the expected values
are significantly smaller than one, it can result in false positives.
atol should be carefully selected for the use case at hand. A zero value
for atol will result in False if either a or b is zero.
public override NDArray<bool> IsClose(NDArray a, NDArray b, double rtol = 1E-05, double atol = 1E-08, bool equal_nan = false)
Parameters
aNDArrayInput array to compare with b
bNDArrayInput array to compare with a.
rtoldoubleThe relative tolerance parameter(see Notes)
atoldoubleThe absolute tolerance parameter(see Notes)
equal_nanboolWhether to compare NaN's as equal. If True, NaN's in
awill be considered equal to NaN's inbin the output array.
Returns
- NDArray<bool>
Returns a boolean array of where
aandbare equal within the given tolerance.If bothaandbare scalars, returns a single boolean value.
IsFinite(NDArray)
Test element-wise for finiteness (not infinity and not NaN). Returns True for all integer types (always finite), and checks float/double values.
public override NDArray<bool> IsFinite(NDArray a)
Parameters
aNDArrayInput array
Returns
Remarks
NumPy behavior:
- Float/Double: True if not infinity and not NaN
- Integer types: Always True (integers cannot be Inf or NaN)
- Empty arrays: Returns empty bool array
IsInf(NDArray)
Test element-wise for positive or negative infinity. Returns False for all integer types (cannot be Inf), and checks float/double values.
public override NDArray<bool> IsInf(NDArray a)
Parameters
aNDArrayInput array
Returns
Remarks
NumPy behavior:
- Float/Double: True if value is +Inf or -Inf
- Integer types: Always False (integers cannot be Inf)
- NaN: Returns False (NaN is not infinity)
- Empty arrays: Returns empty bool array
IsNan(NDArray)
Test element-wise for NaN (Not a Number). Returns False for all integer types (cannot be NaN), and checks float/double values.
public override NDArray<bool> IsNan(NDArray a)
Parameters
aNDArrayInput array
Returns
Remarks
NumPy behavior:
- Float/Double: True if value is NaN
- Integer types: Always False (integers cannot be NaN)
- Infinity: Returns False (Inf is not NaN)
- Empty arrays: Returns empty bool array
LeftShift(NDArray, NDArray)
Bitwise left shift (x1 << x2).
public override NDArray LeftShift(NDArray lhs, NDArray rhs)
Parameters
Returns
LeftShift(NDArray, ValueType)
Bitwise left shift (x1 << scalar). SIMD optimized for contiguous arrays.
public override NDArray LeftShift(NDArray lhs, ValueType rhs)
Parameters
Returns
Less(NDArray, NDArray)
Element-wise less-than comparison (<).
public override NDArray<bool> Less(NDArray lhs, NDArray rhs)
Parameters
Returns
LessEqual(NDArray, NDArray)
Element-wise less-than-or-equal comparison (<=).
public override NDArray<bool> LessEqual(NDArray lhs, NDArray rhs)
Parameters
Returns
Log(NDArray, NPTypeCode?)
Element-wise natural logarithm using IL-generated kernels.
public override NDArray Log(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Log(NDArray, Type)
public override NDArray Log(NDArray nd, Type dtype)
Parameters
Returns
Log10(NDArray, NPTypeCode?)
Element-wise log base 10 using IL-generated kernels.
public override NDArray Log10(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Log10(NDArray, Type)
public override NDArray Log10(NDArray nd, Type dtype)
Parameters
Returns
Log1p(NDArray, NPTypeCode?)
Element-wise log(1 + x) using IL-generated kernels.
public override NDArray Log1p(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Log1p(NDArray, Type)
public override NDArray Log1p(NDArray nd, Type dtype)
Parameters
Returns
Log2(NDArray, NPTypeCode?)
Element-wise log base 2 using IL-generated kernels.
public override NDArray Log2(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Log2(NDArray, Type)
public override NDArray Log2(NDArray nd, Type dtype)
Parameters
Returns
Matmul(NDArray, NDArray)
public override NDArray Matmul(NDArray lhs, NDArray rhs)
Parameters
Returns
Remarks
Mean(NDArray, int, Type, bool)
public override NDArray Mean(NDArray nd, int axis, Type dtype, bool keepdims = false)
Parameters
Returns
Mean(NDArray, int?, NPTypeCode?, bool)
public override NDArray Mean(NDArray nd, int? axis = null, NPTypeCode? typeCode = null, bool keepdims = false)
Parameters
ndNDArrayaxisint?typeCodeNPTypeCode?keepdimsbool
Returns
MeanElementwise<T>(NDArray, NPTypeCode?)
Element-wise mean for typed result. Compatibility method for Std/Var.
public T MeanElementwise<T>(NDArray arr, NPTypeCode? typeCode) where T : unmanaged
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
- T
Type Parameters
T
Mod(NDArray, NDArray)
Element-wise modulo using IL-generated kernels. Supports all 144 type combinations with automatic type promotion.
public override NDArray Mod(NDArray lhs, NDArray rhs)
Parameters
Returns
ModF(NDArray, NPTypeCode?)
Return the fractional and integral parts of an array, element-wise.
NumPy behavior (C standard modf):
- modf(1.5) = (0.5, 1.0)
- modf(-2.7) = (-0.7, -2.0) -- sign of fractional matches input
- modf(inf) = (0.0, inf)
- modf(-inf) = (-0.0, -inf)
- modf(nan) = (nan, nan)
Decimal is a NumSharp extension (NumPy doesn't have decimal type).
public override (NDArray Fractional, NDArray Intergral) ModF(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
ModF(NDArray, Type)
public override (NDArray Fractional, NDArray Intergral) ModF(NDArray nd, Type dtype)
Parameters
Returns
MoveAxis(NDArray, int[], int[])
public override NDArray MoveAxis(NDArray nd, int[] source, int[] destinition)
Parameters
Returns
Multiply(NDArray, NDArray)
Element-wise multiplication using IL-generated kernels. Supports all 144 type combinations with automatic type promotion.
public override NDArray Multiply(NDArray lhs, NDArray rhs)
Parameters
Returns
MultiplyMatrix(NDArray, NDArray, NDArray)
Matrix multiplication for 2D arrays: C = A @ B A is [M x K], B is [K x N], result is [M x N]
[SuppressMessage("ReSharper", "JoinDeclarationAndInitializer")]
protected static NDArray MultiplyMatrix(NDArray left, NDArray right, NDArray @out = null)
Parameters
Returns
Remarks
Implementation strategy:
- SIMD fast path for contiguous float/double (40-100x faster)
- Generic fallback using Unsafe pointer arithmetic for all types
NanMax(NDArray, int?, bool)
Return maximum of an array or maximum along an axis, ignoring NaNs.
public override NDArray NanMax(NDArray a, int? axis = null, bool keepdims = false)
Parameters
Returns
NanMin(NDArray, int?, bool)
Return minimum of an array or minimum along an axis, ignoring NaNs.
public override NDArray NanMin(NDArray a, int? axis = null, bool keepdims = false)
Parameters
Returns
NanProd(NDArray, int?, bool)
Return the product of array elements over a given axis treating NaNs as ones.
public override NDArray NanProd(NDArray a, int? axis = null, bool keepdims = false)
Parameters
Returns
NanSum(NDArray, int?, bool)
Return the sum of array elements over a given axis treating NaNs as zero.
public override NDArray NanSum(NDArray a, int? axis = null, bool keepdims = false)
Parameters
Returns
Negate(NDArray)
Element-wise negation using IL-generated kernels.
public override NDArray Negate(NDArray nd)
Parameters
ndNDArray
Returns
NonZero(NDArray)
Return the indices of non-zero elements.
public override NDArray<int>[] NonZero(NDArray nd)
Parameters
ndNDArrayInput array
Returns
Remarks
NumPy-aligned behavior:
- Returns tuple of arrays, one per dimension
- For empty arrays, returns empty arrays with correct dtype (int)
- Iterates in C-order (row-major)
- Handles contiguous and strided arrays efficiently
NotEqual(NDArray, NDArray)
Element-wise not-equal comparison (!=).
public override NDArray<bool> NotEqual(NDArray lhs, NDArray rhs)
Parameters
Returns
Power(NDArray, NDArray, NPTypeCode?)
Element-wise power with array exponents: x1 ** x2 Uses ExecuteBinaryOp with BinaryOp.Power for broadcasting support.
public override NDArray Power(NDArray lhs, NDArray rhs, NPTypeCode? typeCode = null)
Parameters
lhsNDArrayrhsNDArraytypeCodeNPTypeCode?
Returns
Power(NDArray, NDArray, Type)
Element-wise power with array exponents: x1 ** x2
public override NDArray Power(NDArray lhs, NDArray rhs, Type dtype)
Parameters
Returns
Power(NDArray, ValueType, NPTypeCode?)
public override NDArray Power(NDArray lhs, ValueType rhs, NPTypeCode? typeCode = null)
Parameters
lhsNDArrayrhsValueTypetypeCodeNPTypeCode?
Returns
Power(NDArray, ValueType, Type)
public override NDArray Power(NDArray lhs, ValueType rhs, Type dtype)
Parameters
Returns
Rad2Deg(NDArray, NPTypeCode?)
Element-wise radians to degrees conversion using IL-generated kernels. Computes x * (180/Ï€).
public override NDArray Rad2Deg(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Rad2Deg(NDArray, Type)
public override NDArray Rad2Deg(NDArray nd, Type dtype)
Parameters
Returns
Reciprocal(NDArray, NPTypeCode?)
Element-wise reciprocal (1/x) using IL-generated kernels.
public override NDArray Reciprocal(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Reciprocal(NDArray, Type)
public override NDArray Reciprocal(NDArray nd, Type dtype)
Parameters
Returns
ReduceAMax(NDArray, int?, bool, NPTypeCode?)
public override NDArray ReduceAMax(NDArray arr, int? axis_, bool keepdims = false, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?keepdimsbooltypeCodeNPTypeCode?
Returns
ReduceAMin(NDArray, int?, bool, NPTypeCode?)
public override NDArray ReduceAMin(NDArray arr, int? axis_, bool keepdims = false, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?keepdimsbooltypeCodeNPTypeCode?
Returns
ReduceAdd(NDArray, int?, bool, NPTypeCode?, NDArray)
public override NDArray ReduceAdd(NDArray arr, int? axis_, bool keepdims = false, NPTypeCode? typeCode = null, NDArray @out = null)
Parameters
arrNDArrayaxis_int?keepdimsbooltypeCodeNPTypeCode?outNDArray
Returns
ReduceArgMax(NDArray, int?, bool)
public override NDArray ReduceArgMax(NDArray arr, int? axis_, bool keepdims = false)
Parameters
Returns
ReduceArgMin(NDArray, int?, bool)
public override NDArray ReduceArgMin(NDArray arr, int? axis_, bool keepdims = false)
Parameters
Returns
ReduceCumAdd(NDArray, int?, NPTypeCode?)
public override NDArray ReduceCumAdd(NDArray arr, int? axis_, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?typeCodeNPTypeCode?
Returns
ReduceCumMul(NDArray, int?, NPTypeCode?)
public override NDArray ReduceCumMul(NDArray arr, int? axis_, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?typeCodeNPTypeCode?
Returns
ReduceMean(NDArray, int?, bool, NPTypeCode?)
public override NDArray ReduceMean(NDArray arr, int? axis_, bool keepdims = false, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?keepdimsbooltypeCodeNPTypeCode?
Returns
ReduceProduct(NDArray, int?, bool, NPTypeCode?)
public override NDArray ReduceProduct(NDArray arr, int? axis_, bool keepdims = false, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?keepdimsbooltypeCodeNPTypeCode?
Returns
ReduceStd(NDArray, int?, bool, int?, NPTypeCode?)
public override NDArray ReduceStd(NDArray arr, int? axis_, bool keepdims = false, int? ddof = null, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?keepdimsboolddofint?typeCodeNPTypeCode?
Returns
ReduceVar(NDArray, int?, bool, int?, NPTypeCode?)
public override NDArray ReduceVar(NDArray arr, int? axis_, bool keepdims = false, int? ddof = null, NPTypeCode? typeCode = null)
Parameters
arrNDArrayaxis_int?keepdimsboolddofint?typeCodeNPTypeCode?
Returns
ResolveReturnShape(params NDArray[])
Resolves the output shape when broadcasting multiple arrays together.
public static Shape ResolveReturnShape(params NDArray[] arrays)
Parameters
arraysNDArray[]
Returns
Remarks
Extracts shapes and delegates to Shape.ResolveReturnShape
ResolveReturnShape(Shape, Shape)
Resolves the output shape when broadcasting two shapes together.
public static Shape ResolveReturnShape(Shape leftShape, Shape rightShape)
Parameters
Returns
Remarks
Delegates to Shape.ResolveReturnShape
ResolveReturnShape(params Shape[])
Resolves the output shape when broadcasting multiple shapes together.
public static Shape ResolveReturnShape(params Shape[] shapes)
Parameters
shapesShape[]
Returns
Remarks
Delegates to Shape.ResolveReturnShape
ResolveUnaryReturnType(NDArray, NPTypeCode?)
public NPTypeCode ResolveUnaryReturnType(NDArray nd, NPTypeCode? @override)
Parameters
ndNDArrayoverrideNPTypeCode?
Returns
ResolveUnaryReturnType(NDArray, Type)
public NPTypeCode ResolveUnaryReturnType(NDArray nd, Type @override)
Parameters
Returns
RightShift(NDArray, NDArray)
Bitwise right shift (x1 >> x2). Uses arithmetic shift for signed types (sign bit extended). Uses logical shift for unsigned types (zeros filled).
public override NDArray RightShift(NDArray lhs, NDArray rhs)
Parameters
Returns
RightShift(NDArray, ValueType)
Bitwise right shift (x1 >> scalar). SIMD optimized for contiguous arrays.
public override NDArray RightShift(NDArray lhs, ValueType rhs)
Parameters
Returns
RollAxis(NDArray, int, int)
public override NDArray RollAxis(NDArray nd, int axis, int start = 0)
Parameters
Returns
Round(NDArray, int, NPTypeCode?)
Element-wise round with specified decimal places. Note: This overload uses traditional loop implementation for precision control.
public override NDArray Round(NDArray nd, int decimals, NPTypeCode? typeCode = null)
Parameters
ndNDArraydecimalsinttypeCodeNPTypeCode?
Returns
Round(NDArray, int, Type)
public override NDArray Round(NDArray nd, int decimals, Type dtype)
Parameters
Returns
Round(NDArray, NPTypeCode?)
Element-wise round using IL-generated kernels.
public override NDArray Round(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Round(NDArray, Type)
public override NDArray Round(NDArray nd, Type dtype)
Parameters
Returns
Sign(NDArray, NPTypeCode?)
Element-wise sign function using IL-generated kernels. Returns -1, 0, or 1 based on input sign. NumPy behavior: preserves input dtype.
public override NDArray Sign(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Sign(NDArray, Type)
public override NDArray Sign(NDArray nd, Type dtype)
Parameters
Returns
Sin(NDArray, NPTypeCode?)
Element-wise sine using IL-generated kernels.
public override NDArray Sin(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Sin(NDArray, Type)
public override NDArray Sin(NDArray nd, Type dtype)
Parameters
Returns
Sinh(NDArray, NPTypeCode?)
Element-wise hyperbolic sine using IL-generated kernels.
public override NDArray Sinh(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Sinh(NDArray, Type)
public override NDArray Sinh(NDArray nd, Type dtype)
Parameters
Returns
Sqrt(NDArray, NPTypeCode?)
Element-wise square root using IL-generated kernels.
public override NDArray Sqrt(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Sqrt(NDArray, Type)
public override NDArray Sqrt(NDArray nd, Type dtype)
Parameters
Returns
Square(NDArray, NPTypeCode?)
Element-wise square (x*x) using IL-generated kernels. NumPy behavior: preserves input dtype (unlike trig functions which promote to float).
public override NDArray Square(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Square(NDArray, Type)
public override NDArray Square(NDArray nd, Type dtype)
Parameters
Returns
StdElementwise<T>(NDArray, NPTypeCode?, int?)
public T StdElementwise<T>(NDArray arr, NPTypeCode? typeCode, int? ddof) where T : unmanaged
Parameters
arrNDArraytypeCodeNPTypeCode?ddofint?
Returns
- T
Type Parameters
T
Subtract(NDArray, NDArray)
Element-wise subtraction using IL-generated kernels. Supports all 144 type combinations with automatic type promotion.
public override NDArray Subtract(NDArray lhs, NDArray rhs)
Parameters
Returns
Sum(NDArray, int, Type, bool)
public override NDArray Sum(NDArray nd, int axis, Type dtype, bool keepdims = false)
Parameters
Returns
Sum(NDArray, int?, NPTypeCode?, bool)
public override NDArray Sum(NDArray nd, int? axis = null, NPTypeCode? typeCode = null, bool keepdims = false)
Parameters
ndNDArrayaxisint?typeCodeNPTypeCode?keepdimsbool
Returns
SwapAxes(NDArray, int, int)
public override NDArray SwapAxes(NDArray nd, int axis1, int axis2)
Parameters
Returns
Tan(NDArray, NPTypeCode?)
Element-wise tangent using IL-generated kernels.
public override NDArray Tan(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Tan(NDArray, Type)
public override NDArray Tan(NDArray nd, Type dtype)
Parameters
Returns
Tanh(NDArray, NPTypeCode?)
Element-wise hyperbolic tangent using IL-generated kernels.
public override NDArray Tanh(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Tanh(NDArray, Type)
public override NDArray Tanh(NDArray nd, Type dtype)
Parameters
Returns
Transpose(NDArray, int[])
public override NDArray Transpose(NDArray nd, int[] premute = null)
Parameters
Returns
Truncate(NDArray, NPTypeCode?)
Element-wise truncation (toward zero) using IL-generated kernels.
public override NDArray Truncate(NDArray nd, NPTypeCode? typeCode = null)
Parameters
ndNDArraytypeCodeNPTypeCode?
Returns
Truncate(NDArray, Type)
public override NDArray Truncate(NDArray nd, Type dtype)
Parameters
Returns
TryExecuteAxisReductionSimd(NDArray, int, ReductionOp, NPTypeCode)
Try to execute an axis reduction using SIMD kernel. Returns null if SIMD kernel is not available, allowing fallback to iterator-based approach.
protected NDArray TryExecuteAxisReductionSimd(NDArray arr, int axis, ReductionOp op, NPTypeCode outputTypeCode)
Parameters
arrNDArrayInput array
axisintAxis to reduce along (already normalized to positive)
opReductionOpReduction operation
outputTypeCodeNPTypeCodeOutput type code
Returns
- NDArray
Result array, or null if SIMD kernel not available
VarElementwise<T>(NDArray, NPTypeCode?, int?)
public T VarElementwise<T>(NDArray arr, NPTypeCode? typeCode, int? ddof) where T : unmanaged
Parameters
arrNDArraytypeCodeNPTypeCode?ddofint?
Returns
- T
Type Parameters
T
argmax_elementwise_il(NDArray)
Execute element-wise argmax reduction using IL kernels. Returns the index of the maximum value. All types including Boolean, Single, Double now use unified IL kernel path.
protected long argmax_elementwise_il(NDArray arr)
Parameters
arrNDArray
Returns
argmin_elementwise_il(NDArray)
Execute element-wise argmin reduction using IL kernels. Returns the index of the minimum value. All types including Boolean, Single, Double now use unified IL kernel path.
protected long argmin_elementwise_il(NDArray arr)
Parameters
arrNDArray
Returns
check_and_adjust_axis(NDArray, int)
public static int check_and_adjust_axis(NDArray nd, int axis)
Parameters
Returns
check_and_adjust_axis(int, int)
public static int check_and_adjust_axis(int ndims, int axis)
Parameters
Returns
cumprod_elementwise(NDArray, NPTypeCode?)
protected NDArray cumprod_elementwise(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
cumsum_elementwise(NDArray, NPTypeCode?)
protected NDArray cumsum_elementwise(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
max_axis_simd(NDArray, int, NPTypeCode)
Execute axis reduction for Max with SIMD optimization. Falls back to iterator-based approach if SIMD not available.
protected NDArray max_axis_simd(NDArray arr, int axis, NPTypeCode outputTypeCode)
Parameters
arrNDArrayaxisintoutputTypeCodeNPTypeCode
Returns
max_elementwise_il(NDArray, NPTypeCode?)
Execute element-wise max reduction using IL kernels.
protected object max_elementwise_il(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
mean_elementwise_il(NDArray, NPTypeCode?)
Execute element-wise mean using IL kernels for sum. Mean = Sum / count
protected object mean_elementwise_il(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
min_axis_simd(NDArray, int, NPTypeCode)
Execute axis reduction for Min with SIMD optimization. Falls back to iterator-based approach if SIMD not available.
protected NDArray min_axis_simd(NDArray arr, int axis, NPTypeCode outputTypeCode)
Parameters
arrNDArrayaxisintoutputTypeCodeNPTypeCode
Returns
min_elementwise_il(NDArray, NPTypeCode?)
Execute element-wise min reduction using IL kernels.
protected object min_elementwise_il(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
normalize_axis_tuple(int, int, object, bool)
public static int[] normalize_axis_tuple(int axis, int ndim, object argname = null, bool allow_duplicate = false)
Parameters
Returns
- int[]
normalize_axis_tuple(int[], int, object, bool)
public static int[] normalize_axis_tuple(int[] axis, int ndim, object argname = null, bool allow_duplicate = false)
Parameters
Returns
- int[]
prod_axis_simd(NDArray, int, NPTypeCode)
Execute axis reduction for Prod with SIMD optimization. Falls back to iterator-based approach if SIMD not available.
protected NDArray prod_axis_simd(NDArray arr, int axis, NPTypeCode outputTypeCode)
Parameters
arrNDArrayaxisintoutputTypeCodeNPTypeCode
Returns
prod_elementwise_il(NDArray, NPTypeCode?)
Execute element-wise product reduction using IL kernels.
protected object prod_elementwise_il(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
std_elementwise(NDArray, NPTypeCode?, int?)
protected object std_elementwise(NDArray arr, NPTypeCode? typeCode, int? ddof)
Parameters
arrNDArraytypeCodeNPTypeCode?ddofint?
Returns
sum_axis_simd(NDArray, int, NPTypeCode)
Execute axis reduction for Sum with SIMD optimization. Falls back to iterator-based approach if SIMD not available.
protected NDArray sum_axis_simd(NDArray arr, int axis, NPTypeCode outputTypeCode)
Parameters
arrNDArrayaxisintoutputTypeCodeNPTypeCode
Returns
sum_elementwise_il(NDArray, NPTypeCode?)
Execute element-wise sum reduction using IL kernels.
protected object sum_elementwise_il(NDArray arr, NPTypeCode? typeCode)
Parameters
arrNDArraytypeCodeNPTypeCode?
Returns
var_elementwise(NDArray, NPTypeCode?, int?)
protected object var_elementwise(NDArray arr, NPTypeCode? typeCode, int? ddof)
Parameters
arrNDArraytypeCodeNPTypeCode?ddofint?