NDArray
class in package klyn.math

    public class NDArray<T extends AbstractNumber = Double>:

NDArray

Represents a multi-dimensional array (NDArray) with elements of type T.

Storage model:

- fixed-size row-major layout
- `NDArray<Double>` uses a native contiguous buffer for hot numeric kernels
- other numeric specializations currently keep boxed values in Klyn storage

@param <T> The numeric element type.

    import klyn.math

    values = NDArray<Double>.fromList([1.0, 4.0, 9.0])
    print(values.sqrt())

Properties

Modifier and Type | Member | Description
--- | --- | ---
public readonly property | ndim `ndim as UInt:` | The number of dimensions in the array.
public readonly property | shape `shape as IList<UInt>:` | The shape of the array.
public readonly property | size `size as UInt:` | The total number of elements in the array.
public readonly proper | t `ty t as NDArray<T>:` | The transpose of the NDArray (2D only).

Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | NDArray `NDArray(shape as ArrayList<Object>):` | Constructs a new NDArray with the given shape.
public | NDArray `NDArray(shape as IList<Int>):` | Constructs a new NDArray from a read-only shape.
public | NDArray `NDArray(shape as Tuple):` | Constructs a new NDArray from a tuple shape.
public | NDArray `NDArray(size as Int, initializeZeros as Boolean = true):` | Constructs a new 1D NDArray with the given size.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public native | abs `abs() as NDArray<T>` | Returns the element-wise absolute value.
public native | acos `acos() as NDArray<Double>` | Returns the element-wise arccosine.
public native | asin `asin() as NDArray<Double>` | Returns the element-wise arcsine.
public native | atan `atan() as NDArray<Double>` | Returns the element-wise arctangent.
public | atan2 `atan2(value as T) as NDArray<Double>:` | Returns the element-wise `atan2(this, value)`.
public native | atan2 `atan2(other as NDArray<T>) as NDArray<Double>` | Returns the element-wise `atan2(this, other)`.
public native | cbrt `cbrt() as NDArray<Double>` | Returns the element-wise cube root.
public native | ceil `ceil() as NDArray<T>` | Applies `ceil` element-wise while preserving the array element type.
public native | cos `cos() as NDArray<Double>` | Returns the element-wise cosine in radians.
public native | cosh `cosh() as NDArray<Double>` | Returns the element-wise hyperbolic cosine.
public native | degrees `degrees() as NDArray<Double>` | Converts each element from radians to degrees.
public native | exp `exp() as NDArray<Double>` | Returns the element-wise exponential.
public native | exp2 `exp2() as NDArray<Double>` | Returns the element-wise power of two.
public native | expm1 `expm1() as NDArray<Double>` | Returns the element-wise `exp(value) - 1`.
public static | eye `eye(size as Int) as NDArray<T>:` | Creates a new NDArray with ones on the diagonal and zeros elsewhere.
public | flatten `flatten() as NDArray<T>:` | Flattens the NDArray into a 1D array.
public native | floor `floor() as NDArray<T>` | Applies `floor` element-wise while preserving the array element type.
public | fmod `fmod(value as T) as NDArray<Double>:` | Returns the element-wise floating-point remainder with a scalar.
public native | fmod `fmod(other as NDArray<T>) as NDArray<Double>` | Returns the element-wise floating-point remainder with another array.
public static | fromList `fromList(values as IList<IList<T>>) as NDArray<T>:` | Creates a 2D NDArray from a nested list.
public static | fromList `fromList(values as IList<T>) as NDArray<T>:` | Creates a 1D NDArray from a list.
public static | full `full(shape as ArrayList<Object>, value as T) as NDArray<T>:` | Creates a new NDArray filled with a given value.
public static | full `full(shape as IList<Int>, value as T) as NDArray<T>:` | Creates a new NDArray filled with a given value.
public static | full `full(shape as IList<UInt>, value as T) as NDArray<T>:` | Creates a new NDArray filled with a given value.
public static | full `full(shape as Tuple, value as T) as NDArray<T>:` | Creates a new NDArray filled with a given value using a tuple shape.
public | hypot `hypot(value as T) as NDArray<Double>:` | Returns the element-wise Euclidean distance with a scalar.
public native | hypot `hypot(other as NDArray<T>) as NDArray<Double>` | Returns the element-wise Euclidean distance with another array.
public native | log `log() as NDArray<Double>` | Returns the element-wise natural logarithm.
public native | log10 `log10() as NDArray<Double>` | Returns the element-wise base-10 logarithm.
public native | log1p `log1p() as NDArray<Double>` | Returns the element-wise `log(1 + value)`.
public native | log2 `log2() as NDArray<Double>` | Returns the element-wise base-2 logarithm.
public | max `max() as Object:` | Returns the maximum value of the array.
public | min `min() as Object:` | Returns the minimum value of the array.
public static | ones `ones(shape as ArrayList<Object>) as NDArray<T>:` | Creates a new NDArray with ones.
public static | ones `ones(shape as IList<Int>) as NDArray<T>:` | Creates a new NDArray with ones.
public static | ones `ones(shape as IList<UInt>) as NDArray<T>:` | Creates a new NDArray with ones.
public static | ones `ones(shape as Tuple) as NDArray<T>:` | Creates a new NDArray with ones from a tuple shape.
public native | pow `pow(other as NDArray<T>) as NDArray<Double>` | Raises each element to the matching power array.
public | pow `pow(value as T) as NDArray<Double>:` | Raises each element to the given scalar power.
public native | radians `radians() as NDArray<Double>` | Converts each element from degrees to radians.
public static | randint `randint(min as Int, max as Int, shape as IList<Int>) as NDArray<T>:` | Creates a NDArray with random integers in `[min, max]` using read-only shape dimensions.
public static | randint `randint(min as Int, max as Int, shape as IList<UInt>) as NDArray<T>:` | Creates a new NDArray with random integers.
public static | randint `randint(min as Int, max as Int, shape as Tuple) as NDArray<T>:` | Creates a NDArray with random integers in `[min, max]` using a tuple shape.
public static | randint `randint(min as Int, max as Int, size as Int) as NDArray<T>:` | Creates a 1D NDArray with random integers in `[min, max]`.
public static | randn `randn(shape as IList<Int>) as NDArray<T>:` | Creates a NDArray sampled from a normal-like distribution using read-only shape dimensions.
public static | randn `randn(shape as IList<UInt>) as NDArray<T>:` | Creates a new NDArray with random floating-point numbers from a normal distribution.
public static | randn `randn(shape as Tuple) as NDArray<T>:` | Creates a NDArray sampled from a normal-like distribution using a tuple shape.
public static | randn `randn(size as Int) as NDArray<T>:` | Creates a 1D NDArray sampled from a normal-like distribution.
public static | random `random(shape as IList<Int>) as NDArray<T>:` | Creates a NDArray with random values in `[0, 1)` using read-only shape dimensions.
public static | random `random(shape as IList<UInt>) as NDArray<T>:` | Creates a new NDArray with random values in [0, 1).
public static | random `random(shape as Tuple) as NDArray<T>:` | Creates a NDArray with random values in `[0, 1)` using a tuple shape.
public static | random `random(size as Int) as NDArray<T>:` | Creates a 1D NDArray with random values in `[0, 1)`.
public | reshape `reshape(rows as Int, cols as Int) as NDArray<T>:` | Reshapes the NDArray using two dimensions.
public | reshape `reshape(shape as IList<Int>) as NDArray<T>:` | Reshapes the NDArray to the specified shape.
public | reshape `reshape(shape as Tuple) as NDArray<T>:` | Reshapes the NDArray using a tuple shape.
public native | round `round() as NDArray<T>` | Rounds each element to the nearest integer value while preserving the array element type.
public | set `set(i as Int, value as T) as Void:` | Sets one element in a 1D NDArray.
public | set `set(row as Int, col as Int, value as T) as Void:` | Sets one element in a 2D NDArray.
public native | sin `sin() as NDArray<Double>` | Returns the element-wise sine in radians.
public native | sinh `sinh() as NDArray<Double>` | Returns the element-wise hyperbolic sine.
public | sort `sort() as NDArray<T>:` | Sorts the NDArray in place.
public | sort `sort(axis as Int) as NDArray<T>:` | Sorts the NDArray along one axis, in place.
public native | sqrt `sqrt() as NDArray<Double>` | Returns the element-wise square root.
public native | sum `sum() as Object` | Computes the sum of all elements.
public | sum `sum(axis as Int) as NDArray<T>:` | Computes the sum along one axis.
public native | tan `tan() as NDArray<Double>` | Returns the element-wise tangent in radians.
public native | tanh `tanh() as NDArray<Double>` | Returns the element-wise hyperbolic tangent.
public | toString `toString() as String:` | Returns a string representation of the array.
public native | trunc `trunc() as NDArray<T>` | Applies `trunc` element-wise while preserving the array element type.
public static | zeros `zeros(shape as ArrayList<Object>) as NDArray<T>:` | Creates a new NDArray with zeros.
public static | zeros `zeros(shape as IList<Int>) as NDArray<T>:` | Creates a new NDArray with zeros.
public static | zeros `zeros(shape as IList<UInt>) as NDArray<T>:` | Creates a new NDArray with zeros.
public static | zeros `zeros(shape as Tuple) as NDArray<T>:` | Creates a new NDArray with zeros from a tuple shape.

Operators

Modifier and Type | Member | Description
--- | --- | ---
public static native | operator*(first as NDArray<T>, second as NDArray<T>) as NDArray<T> | Multiplies two NDArrays element-wise.
public static | operator**(first as NDArray<T>, second as NDArray<T>) as NDArray<T>: | Raises first NDArray to second NDArray element-wise.
public static native | operator+(first as NDArray<T>, second as NDArray<T>) as NDArray<T> | Adds two NDArrays element-wise.
public static native | operator-(first as NDArray<T>, second as NDArray<T>) as NDArray<T> | Subtracts two NDArrays element-wise.
public static native | operator/(first as NDArray<T>, second as NDArray<T>) as NDArray<T> | Divides two NDArrays element-wise.
public static | operator//(first as NDArray<T>, second as NDArray<T>) as NDArray<T>: | Integer-divides two NDArrays element-wise.
public static | operator@(first as NDArray<T>, second as NDArray<T>) as NDArray<T>: | Matrix multiplication (2D x 2D).
public | operator[](i as Int) as Object: | Gets one element for 1D arrays.
public | operator[](row as Int, col as Int) as Object: | Gets one element for 2D arrays.