v2026.6.4
All Bundles
Bundle Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.

Matrix2D

2D matrix operations

Operations

Add # native

Adds a constant to a matrix

function : native : Add(c:Float, m:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
cFloatconstant
mFloatmatrix

Return

TypeDescription
Floatupdated matrix

Add # native

Adds a constant to a matrix

function : native : Add(m:Float[,], c:Float) ~ Float[,]

Parameters

NameTypeDescription
mFloatmatrix
cFloatconstant

Return

TypeDescription
Floatupdated matrix

Add # native

Adds two matrices

function : native : Add(m1:Float[,], m2:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
m1Floatleft matrix
m2Floatright matrix

Return

TypeDescription
Floatupdated matrix

AverageColumn # native

Average of the given column

function : native : AverageColumn(c:Int, matrix:Float[,]) ~ Float

Parameters

NameTypeDescription
cIntcolumn index
matrixFloatmatrix

Return

TypeDescription
Floataverage of the column

AverageRow # native

Average of the given row

function : native : AverageRow(r:Int, matrix:Float[,]) ~ Float

Parameters

NameTypeDescription
rIntrow index
matrixFloatmatrix

Return

TypeDescription
Floataverage of the row

Concatenate # function

Concatenates two matrix

function : Concatenate(a:Float[,], b:Float[,], is_row:Bool) ~ Float[,]

Parameters

NameTypeDescription
aFloatleft matrix
bFloatright matrix
is_rowBooltrue concatenate by rows, false for columns

Return

TypeDescription
Floatconcatenated matrix

Divide # native

Divides a constant by a matrix

function : native : Divide(c:Float, m:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
cFloatconstant
mFloatmatrix

Return

TypeDescription
Floatupdated matrix

Divide # native

Divides a constant by a matrix

function : native : Divide(m:Float[,], c:Float) ~ Float[,]

Parameters

NameTypeDescription
mFloatmatrix
cFloatconstant

Return

TypeDescription
Floatupdated matrix

DotProduct # native

Calculates the dot product.

function : native : DotProduct(m1:Float[,], m2:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
m1Floatleft matrix
m2Floatright matrix

Return

TypeDescription
Floatupdated matrix

DotSigmoid # native

Calculates the Dot Product applying while applying the Sigmoid function to all elements

function : native : DotSigmoid(a:Float[,], b:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
aFloatmatrix
bFloatmatrix

Return

TypeDescription
Floatupdated matrix

EuclideanDistance # native

Calculates the Euclidean Distance between the two vectors

function : native : EuclideanDistance(m1:Float[,]) ~ Float

Parameters

NameTypeDescription
m1Floatdata matrix

Return

TypeDescription
FloatEuclidean Distance between the two vectors

Example

# Two 3D points: [1,4], [2,5], [3,6] paired as columns
points := [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]];
dist := Matrix2D->EuclideanDistance(points);
"Distance: {$dist}"->PrintLine();

GetColumn # native

Get the column from a matrix

function : native : GetColumn(c:Int, matrix:Float[,]) ~ Float[]

Parameters

NameTypeDescription
cIntcolumn index
matrixFloatmatrix

Return

TypeDescription
Floatcolumn from matrix

GetRow # native

Get the row from a matrix

function : native : GetRow(r:Int, matrix:Float[,]) ~ Float[]

Parameters

NameTypeDescription
rIntrow index
matrixFloatmatrix

Return

TypeDescription
Floatrow from matrix

HadamardDivide # native

Divides two matrices using the Hadamard rule

function : native : HadamardDivide(m1:Float[,], m2:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
m1Floatleft matrix
m2Floatright matrix

Return

TypeDescription
Floatupdated matrix

HadamardProduct # native

Multiplies two matrices using the Hadamard rule

function : native : HadamardProduct(m1:Float[,], m2:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
m1Floatleft matrix
m2Floatright matrix

Return

TypeDescription
Floatupdated matrix

Identity # native

Creates an identity a matrix

function : native : Identity(s:Int) ~ Float[,]

Parameters

NameTypeDescription
sIntsize of matrix

Return

TypeDescription
Floatrow from matrix

Inverse # native

Inverse of matrix

function : native : Inverse(a:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
aFloatmatrix

Return

TypeDescription
Floatinverted matrix

LeakyReLU # native

Leaky ReLU activation function

function : native : LeakyReLU(x:Float, alpha:Float) ~ Float

Parameters

NameTypeDescription
xFloatinput value
alphaFloatslope for negative values (default 0.01)

Return

TypeDescription
FloatLeaky ReLU value

LeakyReLU # native

Applies the Leaky ReLU function to all elements

function : native : LeakyReLU(b:Float[,], alpha:Float) ~ Float[,]

Parameters

NameTypeDescription
bFloatmatrix
alphaFloatslope for negative values

Return

TypeDescription
Floatupdated matrix

Multiple # native

Multiplies a constant by a matrix

function : native : Multiple(c:Float, m:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
cFloatconstant
mFloatmatrix

Return

TypeDescription
Floatupdated matrix

Multiple # native

Multiplies a constant by a matrix

function : native : Multiple(m:Float[,], c:Float) ~ Float[,]

Parameters

NameTypeDescription
mFloatmatrix
cFloatconstant

Return

TypeDescription
Floatupdated matrix

Random # function

Generates a random 2D array of values from 0.0 to 1.0

function : Random(rows:Int, cols:Int) ~ Float[,]

Parameters

NameTypeDescription
rowsIntrows
colsIntcolumns

Return

TypeDescription
Floatupdated matrix

RandomNormal # function

Generates a random normal distribution of values

function : RandomNormal(mean:Float, variance:Float, rows:Int, cols:Int) ~ Float[,]

Parameters

NameTypeDescription
meanFloatcenter of values
varianceFloatvariance in values
rowsIntrows
colsIntcolumns

Return

TypeDescription
Floatupdated matrix

RandomNormal # function

Generates a random normal value

function : RandomNormal(mean:Float, variance:Float) ~ Float

Parameters

NameTypeDescription
meanFloatcenter of values
varianceFloatvariance in values

Return

TypeDescription
Floatupdated matrix

ReLU # native

ReLU (Rectified Linear Unit) activation function

function : native : ReLU(x:Float) ~ Float

Parameters

NameTypeDescription
xFloatinput value

Return

TypeDescription
FloatReLU value (max(0, x))

Example

"ReLU(-1.5)={$Matrix2D->ReLU(-1.5)}"->PrintLine();
"ReLU(3.2)={$Matrix2D->ReLU(3.2)}"->PrintLine();

ReLU # native

Applies the ReLU function to all elements

function : native : ReLU(b:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
bFloatmatrix

Return

TypeDescription
Floatupdated matrix

Sigmoid # native

Sigmoid 'S' function

function : native : Sigmoid(x:Float) ~ Float

Parameters

NameTypeDescription
xFloatinput value

Return

TypeDescription
FloatSigmoid value

Example

val := Matrix2D->Sigmoid(2.0);
"Sigmoid(2.0)={$val}"->PrintLine();

Sigmoid # native

Applies the Sigmoid function to all elements

function : native : Sigmoid(b:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
bFloatmatrix

Return

TypeDescription
Floatupdated matrix

Softmax # native

Softmax activation function for classification

function : native : Softmax(b:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
bFloatmatrix (single row or column vector)

Return

TypeDescription
Floatnormalized probability distribution

Example

logits := [[1.0], [2.0], [3.0]];
probs := Matrix2D->Softmax(logits);
each(i : probs->Size()[0]) {
  probs[i,0]->PrintLine();
};

Solve # native

Solves a unit of equations

function : native : Solve(m1:Float[,], m2:Float[,]) ~ Float[]

Parameters

NameTypeDescription
m1Floatdata matrix
m2Floatresult matrix

Return

TypeDescription
Floatleast squares

Example

A := [[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]];
b := [[1.0], [2.0], [3.0]];
coeffs := Matrix2D->Solve(A, b);
each(c in coeffs) {
  c->PrintLine();
};

Split # native

Splits a matrix

function : native : Split(b:Float[,], offset:Int, count:Int, is_row:Bool) ~ Float[,]

Parameters

NameTypeDescription
bFloatmatrix
offsetIntoffset index
countIntnumber of rows to split
is_rowBooltrue for row split, false for column

Return

TypeDescription
Floatcopied matrix

Subtract # native

Subtracts a constant from a matrix

function : native : Subtract(c:Float, m:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
cFloatconstant
mFloatmatrix

Return

TypeDescription
Floatupdated matrix

Subtract # native

Adds a constant to a matrix

function : native : Subtract(m:Float[,], c:Float) ~ Float[,]

Parameters

NameTypeDescription
mFloatmatrix
cFloatconstant

Return

TypeDescription
Floatupdated matrix

Subtract # native

Subtracts two matrices

function : native : Subtract(m1:Float[,], m2:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
m1Floatleft matrix
m2Floatright matrix

Return

TypeDescription
Floatupdated matrix

SumColumn # native

Sum of the given column

function : native : SumColumn(c:Int, matrix:Float[,]) ~ Float

Parameters

NameTypeDescription
cIntcolumn index
matrixFloatmatrix

Return

TypeDescription
Floatsum of the column

SumRow # native

Sum of the given row

function : native : SumRow(r:Int, matrix:Float[,]) ~ Float

Parameters

NameTypeDescription
rIntrow index
matrixFloatmatrix

Return

TypeDescription
Floatsum of the row

Tanh # native

Tanh (Hyperbolic Tangent) activation function

function : native : Tanh(x:Float) ~ Float

Parameters

NameTypeDescription
xFloatinput value

Return

TypeDescription
FloatTanh value

Example

"Tanh(0.5)={$Matrix2D->Tanh(0.5)}"->PrintLine();

Tanh # native

Applies the Tanh function to all elements

function : native : Tanh(b:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
bFloatmatrix

Return

TypeDescription
Floatupdated matrix

ToBool # function

Parsers a boolean value

function : ToBool(m:Float[,]) ~ Bool

Parameters

NameTypeDescription
mFloatmatrix

Return

TypeDescription
Boolboolean value

ToFloat # function

Parsers a decimal value

function : ToFloat(m:Float[,]) ~ Float

Parameters

NameTypeDescription
mFloatmatrix

Return

TypeDescription
Floatdecimal value

ToInt # function

Parsers an integer value

function : ToInt(m:Float[,]) ~ Int

Parameters

NameTypeDescription
mFloatmatrix

Return

TypeDescription
Intinteger value

Transpose # native

Transpose of matrix

function : native : Transpose(a:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
aFloatmatrix

Return

TypeDescription
Floattransposed matrix