MatrixOperationsBase
public protocol MatrixOperationsBase : MatrixBase
A matrix declaring the full suite of mathematical operations (addition, scalar addition, multiplication, scalar multiplication, etc).
-
The type returned by adding or subtracting two matrices.
Declaration
Swift
associatedtype MatrixAdditionType : MatrixBase where Self.ElementType == Self.MatrixAdditionType.ElementType, Self.MatrixAdditionType.ElementType == Self.MatrixMultiplicationType.ElementType
-
The type returned by multiplying two matrices.
Declaration
Swift
associatedtype MatrixMultiplicationType : MatrixBase
-
The type returned by transposing this matrix.
Declaration
Swift
associatedtype MatrixTransposeType : MatrixBase
-
Adds
self
andmatrix
component-wise.Declaration
Swift
func add<M>(by matrix: M) throws -> MatrixAdditionType where M : MatrixBase, Self.ElementType == M.ElementType
Parameters
matrix
The matrix to add to this matrix.
Return Value
The result of adding
self
andmatrix
. -
Subtracts
self
andmatrix
component-wise.Declaration
Swift
func subtract<M>(by matrix: M) throws -> MatrixAdditionType where M : MatrixBase, Self.ElementType == M.ElementType
Parameters
matrix
The matrix to subtract from this matrix.
Return Value
The result of subracting
matrix
andself
. -
Performs matrix multiplication on
self
andmatrix
(not component-wise).Throws
MatrixError.incorrectDimensions
ifself.dimensions.column
does not equalmatrix.dimensions.row
.Declaration
Swift
func multiply<M>(by matrix: M) throws -> MatrixMultiplicationType where M : MatrixBase, Self.ElementType == M.ElementType
Parameters
matrix
The matrix to multiply with this matrix.
Return Value
The result of multiplying
self
andmatrix
. -
Returns the transpose of this matrix. Transposing a matrix turns rows to columns and vice versa.
Declaration
Swift
func transpose() -> MatrixTransposeType
Return Value
A matrix whose rows are the columns of self and vice versa.
-
Adds a matrix and a scalar.
Declaration
Swift
static func + (lhs: Self, rhs: ElementType) -> Self
Parameters
lhs
The current matrix.
rhs
The scalar to add to the elements.
Return Value
A matrix with dimensions equal to lhs.dimensions with rhs added to all elements.
-
Adds a scalar and a matrix.
Declaration
Swift
static func + (lhs: ElementType, rhs: Self) -> Self
Parameters
lhs
The scalar to add to the elements.
rhs
The current matrix.
Return Value
A matrix with dimensions equal to rhs.dimensions with lhs added to all elements.
-
Subtracts a scalar from a matrix.
Declaration
Swift
static func - (lhs: Self, rhs: ElementType) -> Self
Parameters
lhs
The current matrix.
rhs
The scalar to subtract from the elements.
Return Value
A matrix with dimensions equal to lhs.dimensions with rhs subtracted from all elements.
-
Subtracts a matrix from a scalar.
Declaration
Swift
static func - (lhs: ElementType, rhs: Self) -> Self
Parameters
lhs
The scalar from which to subtract the matrix’s elements.
rhs
The current matrix.
Return Value
A matrix with dimensions equal to rhs.dimensions with all elements subtracted from lhs.
-
Multiplies a matrix by a scalar.
Declaration
Swift
static func * (lhs: Self, rhs: ElementType) -> Self
Parameters
lhs
The current matrix.
rhs
The scalar to multiply the elements of the matrix by.
Return Value
A matrix with dimensions equal to lhs.dimensions with all elements multiplied by rhs.
-
Multiplies a scalar by a matrix.
Declaration
Swift
static func * (lhs: ElementType, rhs: Self) -> Self
Parameters
lhs
The scalar to multiply the elements of the matrix by.
rhs
The current matrix.
Return Value
A matrix with dimensions equal to rhs.dimensions with all elements multiplied by lhs.
-
Adds and assigns a scalar and a matrix.
Declaration
Swift
static func += (lhs: inout Self, rhs: ElementType)
Parameters
lhs
The matrix to add and assign.
-
Subtracts and assigns a scalar and a matrix.
Declaration
Swift
static func -= (lhs: inout Self, rhs: ElementType)
Parameters
lhs
The matrix to subtract and assign.
-
Multiplies and assigns a scalar and a matrix.
Declaration
Swift
static func *= (lhs: inout Self, rhs: ElementType)
Parameters
lhs
The matrix to multiply and assign.