VariableSizeMatrix
public struct VariableSizeMatrix<MatrixType> : MatrixOperationsBase where MatrixType : Addable, MatrixType : Multiplicable, MatrixType : Numeric
A matrix whose dimensions are determined at runtime.
-
The type of the matrix’s elements.
Declaration
Swift
public typealias ElementType = MatrixType -
The dimensions of the matrix. The first component is the number of rows and the second component is the number of columns. Both components must be greater than 0.
Declaration
Swift
public let dimensions: IntSize -
The values of the matrix. The number of elements must equal the number of rows times the number of columns.
Declaration
Swift
public private(set) var elements: [MatrixType] -
Initializes the matrix with the given dimensions and all elements equal to
MatrixType.zero.Declaration
Swift
public init(dimensions: IntSize) -
Initializes the matrix with the given dimensions and elements. If
elementsdoes not contain enough elements, the remaining values are filled withMatrixType.zero. Ifelementscontains too many elements, the extra elements are ignored.Declaration
Swift
public init(dimensions: IntSize, elements: [MatrixType]) -
Provides access to the underlying elements.
Declaration
Swift
public subscript(index: Int) -> MatrixType { get set }Parameters
indexThe index of the element. Must be in range
[0, self.numberOfElements).Return Value
The value of the element at the given index.
-
Adds
selfandmatrixcomponent-wise.Declaration
Swift
public func add<M>(by matrix: M) throws -> VariableSizeMatrix<MatrixType> where M : MatrixBase, ElementType == M.ElementTypeParameters
matrixThe matrix to add to this matrix.
Return Value
The result of adding
selfandmatrix. -
Subtracts
selfandmatrixcomponent-wise.Declaration
Swift
public func subtract<M>(by matrix: M) throws -> VariableSizeMatrix<MatrixType> where M: MatrixBase, ElementType == M.ElementTypeParameters
matrixThe matrix to subtract from this matrix.
Return Value
The result of subracting
matrixandself. -
Performs matrix multiplication on
selfandmatrix(not component-wise).Throws
MatrixError.incorrectDimensionsifself.dimensions.columndoes not equalmatrix.dimensions.row.Declaration
Swift
public func multiply<M>(by matrix: M) throws -> VariableSizeMatrix<MatrixType> where M: MatrixBase, ElementType == M.ElementTypeParameters
matrixThe matrix to multiply with this matrix.
Return Value
The result of multiplying
selfandmatrix. -
Returns the transpose of this matrix. Transposing a matrix turns rows to columns and vice versa.
Declaration
Swift
public func transpose() -> VariableSizeMatrix<MatrixType>Return Value
A matrix whose rows are the columns of self and vice versa.
VariableSizeMatrix Structure Reference