Mathematical
Overview
The mk.math entry point provides element-wise mathematical operations and array aggregation functions. Functions are defined in the Math and MathEx interfaces; convenience extension functions on MultiArray are also available.
Supported element types: Byte, Short, Int, Long, Float, Double, ComplexFloat, ComplexDouble (transcendental functions only support Number, Float, ComplexFloat, ComplexDouble).
Aggregation functions
Function | Description |
|---|---|
| Flat index of the maximum element, or indices along an axis. |
| Flat index of the minimum element, or indices along an axis. |
| Maximum element, or max along an axis. |
| Minimum element, or min along an axis. |
| Sum of all elements, or sum along an axis. |
| Cumulative sum (flat or along an axis). |
Signatures
Example
Extension form
argMax, argMin, and cumSum are also available as extension functions on MultiArray:
Transcendental functions
Function | Description |
|---|---|
| Element-wise sine. |
| Element-wise cosine. |
| Element-wise exponential (e^x). |
| Element-wise natural logarithm (ln). |
Signatures
Example
Extension form
Transcendental functions are also available as extensions on MultiArray:
Absolute value
The abs function returns an ndarray with the absolute value of each element. It is a standalone function (not part of mk.math).
Signatures
Example
Pitfalls
Axis-based overloads (
argMax,max,min,sumwithaxis) require explicit type parameters for the output dimension, e.g.mk.math.sum<Int, D2, D1>(a, axis = 0).cumSum()without an axis always returns a flatD1Array, regardless of input dimensionality.