Libraries.Compute.Matrix Documentation

This class is a two dimensional matrix of number variables.

Example Code

use Libraries.Compute.Matrix

class Main 
    action Main
        Matrix matrix
        matrix:Fill(3, 3, 1.1)
        output matrix:ToText()
    end
end

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Add(number value)This method is used to add a value to all the elements in a Matrix.
AddElements(Libraries.Compute.Matrix matrix)This method is used to add all the elements in a Matrix by the values in another Matrix.
Calculate(Libraries.Compute.MatrixTransform.MatrixCalculation calculate)This is a blueprint method for creating a Matrix Calculation class.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Copy()This method returns a copy of a Matrix.
Divide(number value)This method is used to divide all the elements in a Matrix by a value.
DivideElements(Libraries.Compute.Matrix matrix)This method is used to divide all the elements in a Matrix by the values in another Matrix.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Fill(number fillValue)This method fills the matrix with the specified value.
Fill(integer rows, integer columns, number value)This method fills a matrix with a specified number of rows and columns with the same value.
FillByColumn(integer columns, Libraries.Compute.Matrix matrix)This method fills a matrix from the values of a single column matrix for a specified number of columns.
FillByColumn(integer columns, Libraries.Containers.Array<number> array)This method fills a matrix from the values in an array of numbers for a specified number of columns.
FillByRow(integer rows, Libraries.Containers.Array<number> array)This method fills a matrix from the values in an array of numbers for a specified number of rows.
FillByRow(integer rows, Libraries.Compute.Matrix matrix)This method fills a matrix from the values of a single row matrix for a specified number of rows.
FlipHorizontal()This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.
FlipVertical()This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.
Get(integer row, integer column)This method is used to get the value in a specified location in the matrix.
GetColumn(integer column)This method is used to get a column of a Matrix returned as a new matrix.
GetColumnArray(integer column)This method is used to get a column of a Matrix returned as an array of numbers.
GetColumnMajorArray()This method is used to get a list of all the elements in a Matrix ordered by column returned as an array of numbers.
GetColumns()This method is used to get the number of columns in a matrix.
GetHashCode()This action gets the hash code for an object.
GetMaximum()This method returns the value of the maximum element in a Matrix Attribute Returns The value of the largest element in the matrix.
GetMean()This method returns the mean (average) of all the elements in a Matrix Attribute Returns The mean of all the elements in the matrix.
GetMedian()This method returns the median (middle value) of all the elements in a Matrix Attribute Returns The median of all the elements in the matrix.
GetMinimum()This method returns the value of the minimum element in a Matrix Attribute Returns The value of the smallest element in the matrix.
GetModes()This method returns an array of all the modes (most common value) of a Matrix Attribute Returns An array of the modes of all the elements in the matrix.
GetModesAsText()This method returns an comma separated value of all the modes (most common value) of a Matrix Attribute Returns An comma separated list of the modes of all the elements in the matrix.
GetPercentile(number rank)This method returns the value at a given percentile rank of a Matrix, assuming the elements in the Matrix are all sorted.
GetRow(integer row)This method is used to get a row of a Matrix returned as a new matrix.
GetRowArray(integer row)This method is used to get a row of a Matrix returned as an array of numbers.
GetRowMajorArray()This method is used to get a list of all the elements in a Matrix ordered by row returned as an array of numbers.
GetRows()This method is used to get the number of columns in a matrix.
GetSize()This method is used to get the number of elements in a matrix.
GetStandardDeviation()This method returns the standard deviation of all the elements in a Matrix Attribute Returns The standard deviation of all the elements in the matrix.
GetSubMatrix(integer offsetRow, integer offsetColumn, integer rows, integer columns)This method extracts a sub matrix from within a matrix, starting at the offsetRow and offsetColumn (relative to 0,0 in the upper right corner).
GetTotal()This method returns the sum of all the elements in a Matrix Attribute Returns The sum of all the elements in the matrix.
GetVariance()This method returns the variance of all the elements in a Matrix Attribute Returns The variance of all the elements in the matrix.
Identity()This method returns the identity matrix for a square matrix.
Multiply(number value)This method is used to multiply all the elements in a Matrix by a value.
Multiply(Libraries.Compute.Matrix matrix)This method performs a multiplication operation on two matrices.
MultiplyElements(Libraries.Compute.Matrix matrix)This method is used to multiply all the elements in a Matrix by the values in another Matrix.
Reshape(integer offsetRow, integer offsetColumn, integer rows, integer columns, number fillValue)This method shifts a matrix a given number of offsetRows and offsetColumns (relative to 0,0 in the upper right corner).
RotateLeft()This method rotates a Matrix to the left Attribute Returns A new matrix after the operation is performed.
RotateRight()This method rotates a Matrix to the right Attribute Returns A new matrix after the operation is performed.
Set(integer row, integer column, number value)This method is used to set the value in a specified location in the matrix.
SetColumn(integer column, Libraries.Containers.Array<number> array)This method is used to set the elements in a column of a Matrix with a list of numbers in an array.
SetColumn(integer column, Libraries.Compute.Matrix matrix)This method is used to set the elements in a column of a Matrix with a single column matrix.
SetColumn(integer column, number value)This method is used to set all the elements in a column of a Matrix to a single value.
SetLowerThreshold(number cutoffValue, number fillValue)This method compares each element in a matrix to a lower threshold value and if the element is lower, it sets that element to a fill value.
SetRow(integer row, Libraries.Containers.Array<number> array)This method is used to set the elements in a row of a Matrix with a list of numbers in an array.
SetRow(integer row, number value)This method is used to set all the elements in a row of a Matrix to a single value.
SetRow(integer row, Libraries.Compute.Matrix matrix)This method is used to set the elements in a row of a Matrix with a single row matrix.
SetSize(integer rows, integer columns)This method is used to set the dimensions of a matrix.
SetSize(Libraries.Compute.Matrix matrix)This method is used to set the dimensions of a matrix to match a different matrix.
SetUpperThreshold(number cutoffValue, number fillValue)This method compares each element in a matrix to an upper threshold value and if the element is higher, it sets that element to a fill value.
Shift(integer offsetRow, integer offsetColumn, number fillValue)This method shifts a matrix a given number of offsetRows and offsetColumns (relative to 0,0 in the upper left corner).
Subtract(number value)This method is used to subtract a value from all the elements in a Matrix.
SubtractElements(Libraries.Compute.Matrix matrix)This method is used to subtract all the elements in a Matrix from the values in another Matrix.
ToText()This method prints a matrix in text format for easy viewing.
Transform(Libraries.Compute.MatrixTransform.MatrixTransform transform)This is a blueprint method for creating a Matrix Transform class.
Transpose()This method returns the transpose of a matrix where all the rows of the matrix are turned into columns in a new matrix and vice versa.

Actions Documentation

Add(number value)

This method is used to add a value to all the elements in a Matrix. Attribute Parameter value The value to be added to the matrix elements. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            matrix = matrix:Add(1.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

AddElements(Libraries.Compute.Matrix matrix)

This method is used to add all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix to add to the current matrix. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2
            matrix2:Fill(2, 3, 2.0)
            matrix = matrix:AddElements(matrix2)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

Calculate(Libraries.Compute.MatrixTransform.MatrixCalculation calculate)

This is a blueprint method for creating a Matrix Calculation class.

Example Code

use Libraries.Compute.MatrixTransform.MatrixTransform
    use Libraries.Compute.Matrix

    class Add is MatrixCalculation
        action Calculate(Matrix matrix) returns Matrix
            Matrix newMatrix
            newMatrix:SetSize(matrix)
            row = 0
            repeat matrix:GetRows() times
                col = 0
                repeat matrix:GetColumns() times
                    newMatrix:Set(row, col, matrix:Get(row, col) + 3)                    col = col + 1
                end
                row = row + 1
            end
            return newMatrix
        end
    end

Parameters

Return

number: A new matrix after the operation is performed.

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Copy()

This method returns a copy of a Matrix. Attribute Returns A new copied matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2 = matrix:Copy()
            output matrix2:ToText()
        end
    end

Return

Libraries.Compute.Matrix:

Divide(number value)

This method is used to divide all the elements in a Matrix by a value. Attribute Parameter value The value to divide the matrix elements by. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            matrix = matrix:Divide(2.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

DivideElements(Libraries.Compute.Matrix matrix)

This method is used to divide all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix of values to divide by the current matrix values. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2
            matrix2:Fill(2, 3, 2.0)
            matrix = matrix:DivideElements(matrix2)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Fill(number fillValue)

This method fills the matrix with the specified value. Attribute Parameter fillValue The value to place in each element in the matrix. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0)
            matrix = matrix:Fill(1.1)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

Fill(integer rows, integer columns, number value)

This method fills a matrix with a specified number of rows and columns with the same value. Attribute Parameter rows The number of rows for the matrix. Attribute Parameter columns The number of columns for the matrix. Attribute Parameter value The value to place in each element in the matrix. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2 = matrix:Copy()
            output matrix2:ToText()
        end
    end

Parameters

FillByColumn(integer columns, Libraries.Compute.Matrix matrix)

This method fills a matrix from the values of a single column matrix for a specified number of columns. Attribute Parameter columns The number of columns to fill. Attribute Parameter matrix The set of values for each column.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            Matrix matrix2
            matrix2:Fill(1, 3, 1.1)
            matrix:FillByColumn(3, matrix2)
            output matrix:ToText()
        end
    end

Parameters

FillByColumn(integer columns, Libraries.Containers.Array<number> array)

This method fills a matrix from the values in an array of numbers for a specified number of columns. Attribute Parameter columns The number of columns to fill. Attribute Parameter array The set of values for each column.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            Array<number> array
            array:Add(1.0)
            array:Add(2.0)
            array:Add(3.0)
            matrix:FillByColumn(3, array)
            output matrix:ToText()
        end
    end

Parameters

FillByRow(integer rows, Libraries.Containers.Array<number> array)

This method fills a matrix from the values in an array of numbers for a specified number of rows. Attribute Parameter rows The number of rows to fill. Attribute Parameter array The set of values for each row.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            Array<number> array
            array:Add(1.0)
            array:Add(2.0)
            array:Add(3.0)
            matrix:FillByRow(3, array)
            output matrix:ToText()
        end
    end

Parameters

FillByRow(integer rows, Libraries.Compute.Matrix matrix)

This method fills a matrix from the values of a single row matrix for a specified number of rows. Attribute Parameter rows The number of rows to fill. Attribute Parameter matrix The set of values for each row.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            Matrix matrix2
            matrix2:Fill(1, 3, 1.1)
            matrix:FillByRow(3, matrix2)
            output matrix:ToText()
        end
    end

Parameters

FlipHorizontal()

This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix = matrix:FlipHorizontal()
            output matrix:ToText()
        end
    end

Return

Libraries.Compute.Matrix:

FlipVertical()

This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetRow(0, 1.1)
            matrix:SetRow(1, 2.1)
            matrix:SetRow(2, 3.1)
            matrix = matrix:FlipVertical()
            output matrix:ToText()
        end
    end

Return

Libraries.Compute.Matrix:

Get(integer row, integer column)

This method is used to get the value in a specified location in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 1.1)
            output matrix:Get(1, 1)
        end
    end

Parameters

Return

number: The value of the item in the matrix.

GetColumn(integer column)

This method is used to get a column of a Matrix returned as a new matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 1.1)
            Matrix col1 = matrix:GetColumn(0)
            output col1:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix: A matrix containing only the specified column.

GetColumnArray(integer column)

This method is used to get a column of a Matrix returned as an array of numbers.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 1.1)
            Array<number> col1 = matrix:GetColumnArray(0)
            output col1:GetSize()
        end
    end

Parameters

Return

Libraries.Containers.Array: An array containing only the specified row.

GetColumnMajorArray()

This method is used to get a list of all the elements in a Matrix ordered by column returned as an array of numbers.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 1.1)
            Array<number> col1 = matrix:GetColumnMajorArray()
            output col1:GetSize()
        end
    end

Return

Libraries.Containers.Array: An array containing all the elements in matrix in order by column.

GetColumns()

This method is used to get the number of columns in a matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:SetSize(2, 3)
            output matrix:GetColumns()
        end
    end

Return

integer: The number of columns in the matrix.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetMaximum()

This method returns the value of the maximum element in a Matrix Attribute Returns The value of the largest element in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetMaximum()
        end
    end

Return

number:

GetMean()

This method returns the mean (average) of all the elements in a Matrix Attribute Returns The mean of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetMean()
        end
    end

Return

number:

GetMedian()

This method returns the median (middle value) of all the elements in a Matrix Attribute Returns The median of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetMedian()
        end
    end

Return

number:

GetMinimum()

This method returns the value of the minimum element in a Matrix Attribute Returns The value of the smallest element in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetMinimum()
        end
    end

Return

number:

GetModes()

This method returns an array of all the modes (most common value) of a Matrix Attribute Returns An array of the modes of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            Array<number> modes = matrix:GetModes()
            output modes:Get(0)
        end
    end

Return

Libraries.Containers.Array:

GetModesAsText()

This method returns an comma separated value of all the modes (most common value) of a Matrix Attribute Returns An comma separated list of the modes of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetModesAsText()
        end
    end

Return

text:

GetPercentile(number rank)

This method returns the value at a given percentile rank of a Matrix, assuming the elements in the Matrix are all sorted.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetPercentile(0.40)
        end
    end

Parameters

Return

number: The value at a given percentile rank of a Matrix.

GetRow(integer row)

This method is used to get a row of a Matrix returned as a new matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 1.1)
            Matrix row1 = matrix:GetRow(0)
            output row1:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix: A matrix containing only the specified row.

GetRowArray(integer row)

This method is used to get a row of a Matrix returned as an array of numbers.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 1.1)
            Array<number> row1 = matrix:GetRowArray(0)
            output row1:GetSize()
        end
    end

Parameters

Return

Libraries.Containers.Array: An array containing only the specified row.

GetRowMajorArray()

This method is used to get a list of all the elements in a Matrix ordered by row returned as an array of numbers.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 1.1)
            Array<number> row1 = matrix:GetRowMajorArray()
            output row1:GetSize()
        end
    end

Return

Libraries.Containers.Array: An array containing all the elements in the matrix ordered by row .

GetRows()

This method is used to get the number of columns in a matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:SetSize(2, 3)
            output matrix:GetRows()
        end
    end

Return

integer: The number of rows in the matrix.

GetSize()

This method is used to get the number of elements in a matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:SetSize(2, 3)
            output matrix:GetSize()
        end
    end

Return

integer: The total number of elements in the matrix.

GetStandardDeviation()

This method returns the standard deviation of all the elements in a Matrix Attribute Returns The standard deviation of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetStandardDeviation()
        end
    end

Return

number:

GetSubMatrix(integer offsetRow, integer offsetColumn, integer rows, integer columns)

This method extracts a sub matrix from within a matrix, starting at the offsetRow and offsetColumn (relative to 0,0 in the upper right corner). The sub matrix will have the number of rows and columns specified by those parameters Attribute Parameter offsetRow The row offset for the first element in the new matrix. Attribute Parameter offsetColumn The column offset for the first element in the new matrix. Attribute Parameter rows The number of rows to extract. Attribute Parameter columns The number of columns to extract. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(4, 4, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix:SetColumn(3, 4.1)
            matrix = matrix:GetSubMatrix(1, 1, 2, 2)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

GetTotal()

This method returns the sum of all the elements in a Matrix Attribute Returns The sum of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetTotal()
        end
    end

Return

number:

GetVariance()

This method returns the variance of all the elements in a Matrix Attribute Returns The variance of all the elements in the matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            output matrix:GetVariance()
        end
    end

Return

number:

Identity()

This method returns the identity matrix for a square matrix. An identity matrix with ones along the main diagonal from top left to bottom right and zeroes everywhere else. Attribute Returns A new identity matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(4, 4, 0.0)
            matrix = matrix:Identity()
            output matrix:ToText()
        end
    end

Return

Libraries.Compute.Matrix:

Multiply(number value)

This method is used to multiply all the elements in a Matrix by a value. Attribute Parameter value The value to multiply the matrix elements by. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            matrix = matrix:Multiply(2.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

Multiply(Libraries.Compute.Matrix matrix)

This method performs a multiplication operation on two matrices. The dimensions of the matrices must be compatible so that the columns in the first matrix are equal to the rows in the second matrix.

Example Code

Attribute Parameter matrix The matrix to multiply by the current matrix.

    Attribute Returns A new matrix after the operation is performed.

    use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2
            matrix2:Fill(3, 2, 2.0)
            matrix = matrix:Multiply(matrix2)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

MultiplyElements(Libraries.Compute.Matrix matrix)

This method is used to multiply all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix of values to multiply by the current matrix values. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2
            matrix2:Fill(2, 3, 2.0)
            matrix = matrix:MultiplyElements(matrix2)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

Reshape(integer offsetRow, integer offsetColumn, integer rows, integer columns, number fillValue)

This method shifts a matrix a given number of offsetRows and offsetColumns (relative to 0,0 in the upper right corner). The new matrix will have the number of rows and columns specified by those parameters and any empty values in the new matrix will be filled with fillValue. Attribute Parameter offsetRow The row offset for the first element in the new matrix. Attribute Parameter offsetColumn The column offset for the first element in the new matrix. Attribute Parameter rows The number of rows to extract. Attribute Parameter columns The number of columns to extract. Attribute Parameter fillValue The value to fill in any undefined cells in the new matrix.. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(4, 4, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix:SetColumn(3, 4.1)
            matrix = matrix:Reshape(1, 1, 6, 6, 0.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

RotateLeft()

This method rotates a Matrix to the left Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix = matrix:RotateLeft()
            output matrix:ToText()
        end
    end

Return

Libraries.Compute.Matrix:

RotateRight()

This method rotates a Matrix to the right Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix = matrix:RotateRight()
            output matrix:ToText()
        end
    end

Return

Libraries.Compute.Matrix:

Set(integer row, integer column, number value)

This method is used to set the value in a specified location in the matrix.

Parameters

SetColumn(integer column, Libraries.Containers.Array<number> array)

This method is used to set the elements in a column of a Matrix with a list of numbers in an array. The length of the array must match the height of the Matrix. Attribute parameter column The column number of the array to set. Attribute parameter array The array of values to set.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            Array<number> array
            array:Add(1.1)
            array:Add(2.1)
            matrix:SetColumn(0, array)
            output matrix:ToText()
        end
    end

Parameters

SetColumn(integer column, Libraries.Compute.Matrix matrix)

This method is used to set the elements in a column of a Matrix with a single column matrix. The heights of the matrices must match. Attribute parameter column The column number of the array to set. Attribute parameter matrix The matrix of values to set.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            Matrix matrix2
            matrix2:Fill(2, 1, 1.0)
            matrix:SetColumn(0, matrix2)
            output matrix:ToText()
        end
    end

Parameters

SetColumn(integer column, number value)

This method is used to set all the elements in a column of a Matrix to a single value. Attribute parameter column The column number of the array to set. Attribute parameter value The value to set in each element of a column.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            matrix:SetColumn(0, 1.0)
            output matrix:ToText()
        end
    end

Parameters

SetLowerThreshold(number cutoffValue, number fillValue)

This method compares each element in a matrix to a lower threshold value and if the element is lower, it sets that element to a fill value. Attribute Parameter cutoffValue The lower threshold value. Attribute Parameter fillValue The value to fill if the element is below the threshold. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(1, 3, 1.1)
            matrix = matrix:SetLowerThreshold(2.0, 3.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

SetRow(integer row, Libraries.Containers.Array<number> array)

This method is used to set the elements in a row of a Matrix with a list of numbers in an array. The length of the array must match the width of the Matrix. Attribute parameter row The row number of the array to set. Attribute parameter array The array of values to set.

Example Code

use Libraries.Compute.Matrix
    use Libraries.Containers.Array

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            Array<number> array
            array:Add(1.1)
            array:Add(2.1)
            array:Add(3.1)
            matrix:SetRow(0, array)
            output matrix:ToText()
        end
    end

Parameters

SetRow(integer row, number value)

This method is used to set all the elements in a row of a Matrix to a single value. Attribute parameter row The row number of the array to set. Attribute parameter value The value to set in each element of a row.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            matrix:SetRow(0, 1.0)
            output matrix:ToText()
        end
    end

Parameters

SetRow(integer row, Libraries.Compute.Matrix matrix)

This method is used to set the elements in a row of a Matrix with a single row matrix. The widths of the matrices must match. Attribute parameter row The row number of the array to set. Attribute parameter matrix The matrix of values to set.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 0.0)
            Matrix matrix2
            matrix2:Fill(1, 3, 1.0)
            matrix:SetRow(0, matrix2)
            output matrix:ToText()
        end
    end

Parameters

SetSize(integer rows, integer columns)

This method is used to set the dimensions of a matrix.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:SetSize(2, 3)
            output matrix:GetSize()
        end
    end

Parameters

SetSize(Libraries.Compute.Matrix matrix)

This method is used to set the dimensions of a matrix to match a different matrix..

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix1
            matrix:SetSize(2, 3)
            output matrix:GetSize()
        end
    end

Parameters

SetUpperThreshold(number cutoffValue, number fillValue)

This method compares each element in a matrix to an upper threshold value and if the element is higher, it sets that element to a fill value. Attribute Parameter cutoffValue The upper threshold value. Attribute Parameter fillValue The value to fill if the element is above the threshold. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(1, 3, 1.1)
            matrix = matrix:SetUpperThreshold(1.0, 0.5)
            output matrix:ToText()
        end 
    end

Parameters

Return

Libraries.Compute.Matrix:

Shift(integer offsetRow, integer offsetColumn, number fillValue)

This method shifts a matrix a given number of offsetRows and offsetColumns (relative to 0,0 in the upper left corner). The new matrix is the same size and any empty values in the new matrix will be filled with fillValue. Attribute Parameter offsetRow The row offset for the first element in the new matrix. Attribute Parameter offsetColumn The column offset for the first element in the new matrix. Attribute Parameter fillValue The value to fill in any undefined cells in the new matrix. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(4, 4, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix:SetColumn(3, 4.1)
            matrix = matrix:Shift(1, 1, 0.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

Subtract(number value)

This method is used to subtract a value from all the elements in a Matrix. Attribute Parameter value The value to be subtracted from the matrix elements. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            matrix = matrix:Subtract(1.0)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

SubtractElements(Libraries.Compute.Matrix matrix)

This method is used to subtract all the elements in a Matrix from the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix to subtract from the current matrix. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(2, 3, 10.0)
            Matrix matrix2
            matrix2:Fill(2, 3, 2.0)
            matrix = matrix:SubtractElements(matrix2)
            output matrix:ToText()
        end
    end

Parameters

Return

Libraries.Compute.Matrix:

ToText()

This method prints a matrix in text format for easy viewing.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(3, 3, 1.0)
            output matrix:ToText()
        end
    end

Return

text: A text value representation of the matrix.

Transform(Libraries.Compute.MatrixTransform.MatrixTransform transform)

This is a blueprint method for creating a Matrix Transform class.

Example Code

use Libraries.Compute.MatrixTransform.MatrixTransform
    use Libraries.Compute.Matrix

    class AddScalar is MatrixTransform
        action Transform(Matrix matrix) returns Matrix
            Matrix newMatrix
            newMatrix:SetSize(matrix)
            row = 0
            repeat matrix:GetRows() times
                col = 0
                repeat matrix:GetColumns() times
                    newMatrix:Set(row, col, matrix:Get(row, col) + 2)                    col = col + 1
                end
                row = row + 1
            end
            return newMatrix
        end
    end

Parameters

Return

Libraries.Compute.Matrix: A new matrix after the operation is performed.

Transpose()

This method returns the transpose of a matrix where all the rows of the matrix are turned into columns in a new matrix and vice versa. Attribute Returns A new matrix after the operation is performed.

Example Code

use Libraries.Compute.Matrix

    class Main 
        action Main
            Matrix matrix
            matrix:Fill(4, 4, 0.0)
            matrix:SetColumn(0, 1.1)
            matrix:SetColumn(1, 2.1)
            matrix:SetColumn(2, 3.1)
            matrix:SetColumn(3, 4.1)
            matrix = matrix:Transpose()
            output matrix:ToText()
        end
    end

Return

Libraries.Compute.Matrix: