Math.Matrix
(in ./Carbon/Math/Matrix.lua)Generates N
xM
matrices.
Matrices native to Carbon are row-major!
This does not scale very well, but is fast for small values of N
and M
.
Works only for matrices smaller than 14x14.
For larger matrices, consider a different implementation.
The 'loose' form of a Matrix, loose<Matrix>
is of the form (N, M, ...)
where N
and M
are the dimensions of the matrix and ...
represents the values within it.
Methods listed here operating on a Matrix<N, M>
work only on generated classes, while those
listed as operating on Matrix
operate only on the generator class.
Methods
class public Matrix:Generate(uint rows, uint columns
)
Returns Class<Matrix>
- required
rows
: The number of rows in the matrix - required
columns
: The number of columns in the matrix
Generates a new Matrix class with the given size. Results are cached, but this method may still be slow. It performs runtime code generation and template parsing on each generated class.
class public Matrix<N,M>:New(...
)
Returns Matrix<N,M>
class public Matrix<N,M>:PlacementNew(Matrix<N,M>? out, ...
)
Returns Matrix<N,M>
object public Matrix<N,M>:Init(...
)
Returns void
- optional
...
: The values to initialize the matrix with. Each value is nil by default.
Initializes or creates a matrix with a set of row-major values.
class public Matrix<N,M>:NewFromLoose(unumber rows, unumber columns, ...
)
Returns Matrix<N,M>
object public Matrix<N,M>:InitFromLoose(unumber rows, unumber columns, ...
)
Returns void
- required
rows
: The number of rows the loose data has. - required
columns
: The number of columns the loose data has. - optional
...
: The data to initialize or create the matrix with.
Initializes or creates a matrix with a set of sized row-major values.
class public Matrix<N,M>:NewIdentity()
Returns Matrix<N,M>
object public Matrix<N,M>:InitIdentity()
Returns void
Creates or initializes an identity matrix.
class public Matrix<N,M>:NewZero()
Returns Matrix<N,M>
object public Matrix<N,M>:InitZero()
Returns void
Creates or initializes a matrix with all zero values.
object public Matrix<N,M>:Get(unumber i, unumber j
)
Returns number?
- required
i
: The column to look up. - required
j
: The row to look up.
Gets a value of a cell specified by (column, row)
.
object public Matrix<N,M>:GetComponents()
Returns tuple<N*M, ...>
Returns the components of the Matrix in row-major ordering.
object public Matrix<N,M>:Set(unumber i, unumber j, number? value
)
Returns void
- required
i
: The column to look up. - required
j
: The row to look up. - required
value
: The value to set at the cell.
Sets a value of a cell specified by (column, row)
.
object public Matrix<N,M>:ToLoose()
Returns the loose form of the Matrix, decomposing into a tuple.
object public Matrix<N,M>:GetRow(unumber row
)
Returns tuple<N, ...>
- required
row
: The row to get values for.
Returns an entire row's values from this Matrix.
object public Matrix<N,M>:SetRow(unumber row, tuple<N, ...> values
)
Returns void
- required
row
: The row to set values for - required
values
: The values to set for this row.
Sets an entire row's values in the Matrix.
object public Matrix:SetColumn<N,M>(unumber column, tuple<M, ...> values
)
Returns void
- required
column
: The column to set values for - required
values
: The values to set for this column.
Sets an entire column's values in the Matrix.
object public Matrix<N,M>:GetColumn(unumber column
)
Returns tuple<M, ...>
- required
column
: The column to get values for.
Returns an entire column's values from this Matrix.
class public Matrix<N,M>:NewLooseIdentity()
Returns an identity loose<Matrix<N,M>>.
class public Matrix<N,M>:NewLooseZero()
Returns a loose<Matrix<N,M>> full of zeroes.
object public Matrix:MultiplyLooseMatrix<N,M>(loose<Matrix> other, [Matrix out]
)
Returns Matrix<N,M>
Multiplies the Matrix with a loose-representation matrix.
object public Matrix<N,M>:GetNative()
Returns FFI<float[N*M]>
Returns this matrix's native representation. Uses the same object for every call.
object public Matrix<N,M>:LooseMultiplyLooseVector(loose<Vector<N>>> vector
)
- required
vector
: The loose vector to multiply with.
Multiplies the matrix with a row vector and returns the result in loose form.
object public Matrix<N,M>:MultiplyLooseVector(loose<Vector<N>>> vector
)
Returns Vector<N>
- required
vector
: The loose vector to multiply with.
Multiplies the matrix with a row vector and returns the result in a Vector.
object public Matrix<N,M>:MultiplyMatrix(Matrix other, [Matrix out]
)
Returns Matrix
- required
other
: The matrix to multiply with this one. - optional
out
: Where to put the data. A new matrix if not specified.
Multiplies this Matrix with another Matrix.
object public Matrix<N,M>:MultiplyMatrix!(Matrix other
)
Returns self
object public Matrix:MultiplyMatrixInPlace(Matrix other
)
Returns self
- required
other
: The matrix to multiply with.
Multiplies this matrix with another matrix, outputting into this matrix.
Only works with square matrices.
object public Matrix<N,M>:MultiplyScalar!(number value
)
Returns self
object public Matrix<N,M>:MultiplyScalarInPlace(number value
)
Returns self
- required
value
: The scalar to scale the matrix with.
Multiplies the Matrix by a scalar value in place.
object public Matrix<N,M>:MultiplyVector(Vector<N> other, [Vector<N> out]
)
Returns Vector<N>
- required
other
: The vector to multiply with. - optional
out
: Where to put the resulting data.
Post-Multiplies the Matrix with the given Vector.
object public Matrix<N,M>:MutiplyScalar(number value, [Matrix out]
)
Returns Matrix<N,M>
- required
value
: The scalar to scale the matrix with. - optional
out
: Where to put the resulting data.
Multiplies the Matrix by a scalar value.
object public Matrix<N,M>:PreMultiplyVector(Vector<M> other, [Vector<M> out]
)
Returns Vector<M>
- required
other
: The Vector to multiply with. - optional
out
: Where to put the resulting data.
Pre-multiplies the Matrix and the given Vector.
object public Matrix<N,M>:ToNative([FFI<float[N]> out]
)
Returns FFI<float[N*M]>
- optional
out
: Where to place the resulting data.
Returns a native representation of the matrix using the LuaJIT FFI.
object public Matrix<N,M>:Transpose([Matrix<N,M> out]
)
Returns Matrix<N,M>
- optional
out
: An optional Matrix to place the data into.
Transposes the Matrix.
object public Matrix<N,M>:Transpose!()
Returns self
object public Matrix<N,M>:TransposeInPlace()
Returns self
Transposes the matrix in-place.
class private Matrix:__generate_method(string body, table arguments
)
Returns function
- required
body
: Template-enabled code to return a function. - required
arguments
: Arguments to the template
Generates a method using Carbon's TemplateEngine and handles errors.
Properties
[none]