MatrixBase

public protocol MatrixBase : Equatable

An 2-dimensional NxM list of elements of some type.

Most mathematical operations are in the MatrixOperationsBase protocol. Although logically, MatrixBase represents a matrix and so should require the operations, in practice the majority of implementations don’t need the full flexibility, so it’s a lot of wasted boilerplate. Classes may conform to MatrixOperationsBase to implement the full spectrum of matrix operations.

  • The type of the elements of the matrix.

    Declaration

    Swift

    associatedtype ElementType : Addable, Multiplicable, Numeric
  • 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

    var dimensions: IntSize { get }
  • The values of the matrix. The number of elements must equal the number of rows times the number of columns.

    Declaration

    Swift

    var elements: [ElementType] { get }
  • Provides access to the individual elements.

    Declaration

    Swift

    subscript(index: Int) -> ElementType { get set }

    Parameters

    index

    The index of the element to get or set.

    Return Value

    The value of the element at the given index.

  • subscript(_:_:) Default implementation

    Provides access to the individual elements.

    Default Implementation

    Declaration

    Swift

    subscript(row: Int, column: Int) -> ElementType { get set }

    Parameters

    row

    The index of the row.

    column

    The index of the column.

    Return Value

    The value of the element at the given index.

  • Determines if two matrices are equal.

    Declaration

    Swift

    static func == <M>(lhs: Self, rhs: M) -> Bool where M : MatrixBase, Self.ElementType == M.ElementType

    Parameters

    lhs

    This matrix.

    rhs

    The matrix to compare to.

    Return Value

    true if the two matrices are equal, false otherwise.