Matrix

Class and companion object for dense matrices on the CPU.


Constructor

The following syntax is available for constructing Matrix instances from indexed functions:

(0::16, 0::32){(i,j) => func(i,j) }

This returns a Matrix with 16 rows and 32 columns, with elements defined by func(i,j). More general Range forms can also be used, including strided (e.g. 0::2::8) and offset (e.g. 32::64). The iterators i and j will iterate over all values in their respective ranges.


Static methods

object Matrix
def tabulate[T:Type](rows: Index, cols: Index)(func: (Index, Index) => T): Matrix[T]
Returns an immutable Matrix with the given rows and cols and elements defined by func.
def fill[T:Type](rows: Index, cols: Index)(func: => T): Matrix[T] = this.tabulate(rows, cols){(_,_)
Returns an immutable Matrix with the given rows and cols and elements defined by func.
Note that while func does not depend on the index, it is still executed rows*****cols times.

Infix methods

class Matrix
def rows: Index
Returns the number of rows in this Matrix.
def cols: Index
Returns the number of columns in this Matrix.
def apply(i: Index, j: Index): T
Returns the element at the given two-dimensional address (i, j).
def update(i: Index, j: Index, elem: T): Unit
Updates the element at the given two dimensional address to elem.
def flatten: Array[T]
Returns a flattened, immutable Array view of this Matrix’s data.
def foreach(func: T => Unit): Unit
Applies the function func on each element in this Matrix.
def map[R:Type](func: T => R): Matrix[R]
Returns a new Matrix created using the mapping func over each element in this Matrix.
def zip[S:Type,R:Type](that: Matrix[S])(func: (T,S) => R): Matrix[R]
Returns a new Matrix created using the pairwise mapping func over each element in this Matrix
and the corresponding element in that.
def reduce(rfunc: (T,T) => T): T
Reduces the elements in this Matrix into a single element using associative function rfunc.
def transpose(): Matrix[T] = (0::cols, 0::rows){(j, i)
Returns the transpose of this Matrix.