Matrix

trait Matrix[R <: Int, C <: Int, T](using `x$1`: R > 0 && C > 0 =:= true)(using vr: ValueOf[R], vc: ValueOf[C])

Represents a matrix in the mathematical sense and is the central type of this library. Row dimension, column dimension and the data type of the elements are set at compile-time. Elements are indexed zero-based. Concrete subclasses of this trait implement immutable storage and access to the elements of the matrix. Implementations for non-mathematical helper methods (mkString etc.) are provided here, but can be overridden. Mathematical operations are handled by type classes.

Represents a matrix in the mathematical sense and is the central type of this library. Row dimension, column dimension and the data type of the elements are set at compile-time. Elements are indexed zero-based. Concrete subclasses of this trait implement immutable storage and access to the elements of the matrix. Implementations for non-mathematical helper methods (mkString etc.) are provided here, but can be overridden. Mathematical operations are handled by type classes.

Matrix elements are indexed according to the following pattern: | 0,0 | 0,1 | 0,2 | 0,colIdx | ... | 0,colDim-1 | | 1,0 | 1,1 | 1,2 | 1,colIdx | ... | ... | | 2,0 | 2,1 | 2,2 | ... | ... | ... | | rowIdx,0 | rowIdx,1 | ... | rowIdx,colIdx | ... | ... | | ... | ... | ... | ... | ... | ... | | rowDim-1,0 | ... | ... | ... | ... | rowDim-1,colDim-1 |

Type Params
C

column dimension

R

row dimension

T

element type

Companion
object
class Object
trait Matchable
class Any
trait Builder[R, C, T]

Type members

Types

type This = Matrix[R, C, T]

Convenience type alias for this Matrix.

Convenience type alias for this Matrix.

Value members

Abstract methods

def apply(rowIdx: Int, colIdx: Int): T

Returns the element at the index specified at runtime.

Returns the element at the index specified at runtime.

Value Params
colIdx

column index

rowIdx

row index

Concrete methods

final def +(rhs: This)(using ma: MatrixAddition[R, C, T]): This

Performs a Matrix Addition.

Performs a Matrix Addition.

final def -(rhs: This)(using ms: MatrixSubtraction[R, C, T]): This

Performs a Matrix Subtraction.

Performs a Matrix Subtraction.

final def ===(rhs: This)(using me: MatrixEquality[R, C, T]): Boolean

Checks the equality of this and the other Matrix by performing element-wise comparision.

Checks the equality of this and the other Matrix by performing element-wise comparision.

Returns

true if both Matrices are equal

def apply[RowIdx <: Int, ColIdx <: Int](using RowIdx < R =:= true, ColIdx < C =:= true)(using vri: ValueOf[RowIdx], vci: ValueOf[ColIdx]): T

Returns the element at the index specified at compile-time.

Returns the element at the index specified at compile-time.

Type Params
ColIdx

column index

RowIdx

row index

final def colDim: Int

Returns the column dimension.

Returns the column dimension.

def combine[U, V](rhs: Matrix[R, C, U])(op: (T, U) => V)(using mf: MatrixFactory[R, C, V]): Matrix[R, C, V]

Combines this Matrix and the other Matrix by applying the specified operation on the respective corresponding elements.

Combines this Matrix and the other Matrix by applying the specified operation on the respective corresponding elements.

final def dot[L <: Int, U](rhs: Matrix[C, L, U])(using mm: MatrixMultiplication[R, C, L, T, U]): Out

Performs a Matrix Multiplication by calculating the dot product.

Performs a Matrix Multiplication by calculating the dot product.

def fold[S](start: S)(op: (S, Int, Int) => S): S

Folds over the elements of this Matrix by invoking the specified operation with each element's index and the result of the previous invocation.

Folds over the elements of this Matrix by invoking the specified operation with each element's index and the result of the previous invocation.

Value Params
op

operation applied to each element (index)

start

value provided to the first invocation

Returns

result of the last invocation of the specified operation

def iterate(op: (Int, Int) => Unit): Unit

Iterates over this Matrix by invoking the specified operation with each element's index.

Iterates over this Matrix by invoking the specified operation with each element's index.

def map[U](op: T => U)(using mf: MatrixFactory[R, C, U]): Matrix[R, C, U]

Maps this Matrix to a new Matrix by applying the specified operation element-wise.

Maps this Matrix to a new Matrix by applying the specified operation element-wise.

def mkString: String

Renders this Matrix to a String using the elements' toString method.

Renders this Matrix to a String using the elements' toString method.

def mkString(elemToString: T => String): String

Renders this Matrix to a String using the specified function.

Renders this Matrix to a String using the specified function.

def modify(using mf: MatrixFactory[R, C, T]): Builder[R, C, T]

Allows to easily "modify" this Matrix by creating a Builder initialized with the values of this Matrix.

Allows to easily "modify" this Matrix by creating a Builder initialized with the values of this Matrix.

final def rowDim: Int

Returns the row dimension.

Returns the row dimension.

final def submatrix[RowIdxTL <: Int, ColIdxTL <: Int, RowIdxBR <: Int, ColIdxBR <: Int](using sub: Submatrix[RowIdxTL, ColIdxTL, RowIdxBR, ColIdxBR, R, C, T]): Matrix[RowIdxBR - RowIdxTL + 1, ColIdxBR - ColIdxTL + 1, T]

Returns the submatrix with the specified bounds.

Returns the submatrix with the specified bounds.

Type Params
ColIdxBR

column index of the bottom-right vertex

ColIdxTL

column index of the top-left vertex

RowIdxBR

row index of the bottom-right vertex

RowIdxTL

row index of the top-left vertex

final def transpose(using mt: Transpose[R, C, T]): Matrix[C, R, T]

Returns the transposed Matrix.

Returns the transposed Matrix.