Mat

org.saddle.Mat
See theMat companion object
final class Mat[T](val numRows: Int, val numCols: Int, values: Array[T], val scalarTag: ScalarTag[T]) extends NumericOps[Mat[T]]

Mat is an immutable container for 2D homogeneous data (a "matrix"). It is backed by a single array. Data is stored in row-major order.

Several element access methods are provided.

The at method returns an instance of a org.saddle.scalar.Scalar, which behaves much like an Option in that it can be either an instance of org.saddle.scalar.NA or a org.saddle.scalar.Value case class:

 val m = Mat(2,2,Array(1,2,3,4))
 m.at(0,0) == Value(1)

The method raw accesses the underlying value directly.

 val m = Mat(2,2,Array(1,2,3,4))
 m.raw(0,0) == 1d

Mat may be used in arithmetic expressions which operate on two Mats or on a Mat and a primitive value. A fe examples:

 val m = Mat(2,2,Array(1,2,3,4))
 m * m == Mat(2,2,Array(1,4,9,16))
 m dot m == Mat(2,2,Array(7d,10,15,22))
 m * 3 == Mat(2, 2, Array(3,6,9,12))

Note, Mat is generally compatible with EJML's DenseMatrix. It may be convenient to induce this conversion to do more complex linear algebra, or to work with a mutable data structure.

Type parameters

A

Type of elements within the Mat

Attributes

Companion
object
Graph
Supertypes
trait NumericOps[Mat[T]]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def T: Mat[T]
def at(i: Int): Scalar[T]

Return scalar value of matrix at offset from zero in row-major order

Return scalar value of matrix at offset from zero in row-major order

Value parameters

i

index

Attributes

def at(r: Int, c: Int): Scalar[T]

Return scalar value of Mat at at row/column

Return scalar value of Mat at at row/column

Value parameters

c

col index

r

row index

Attributes

def at(r: Array[Int], c: Array[Int]): Mat[T]

Access a slice of the Mat by integer offsets

Access a slice of the Mat by integer offsets

Value parameters

c

Array of col offsets

r

Array of row offsets

Attributes

def at(r: Array[Int], c: Int): Vec[T]

Access a slice of the Mat by integer offsets

Access a slice of the Mat by integer offsets

Value parameters

c

Integer col offset

r

Array of row offsets

Attributes

def at(r: Int, c: Array[Int]): Vec[T]

Access a slice of the Mat by integer offsets

Access a slice of the Mat by integer offsets

Value parameters

c

Array of col offsets

r

Integer row offset

Attributes

def at(r: Slice[Int], c: Slice[Int]): Mat[T]

Access a slice of the Mat by Slice parameters

Access a slice of the Mat by Slice parameters

Value parameters

c

Slice to apply to cols

r

Slice to apply to rows

Attributes

def col(c: Int): Vec[T]

Returns a specific column of the Mat as a Vec

Returns a specific column of the Mat as a Vec

Value parameters

c

Column index

Attributes

def col(locs: Int*): Mat[T]

Access Mat columns at a particular integer offsets

Access Mat columns at a particular integer offsets

Value parameters

locs

a sequence of integer offsets

Attributes

def col(locs: Array[Int]): Mat[T]

Access Mat columns at a particular integer offsets

Access Mat columns at a particular integer offsets

Value parameters

locs

an array of integer offsets

Attributes

def col(slice: Slice[Int]): Mat[T]

Access mat columns specified by a slice

Access mat columns specified by a slice

Value parameters

slice

a slice specifier

Attributes

def cols: IndexedSeq[Vec[T]]

Returns columns of Mat as an indexed sequence of Vec instances

Returns columns of Mat as an indexed sequence of Vec instances

Attributes

def cols(seq: IndexedSeq[Int]): IndexedSeq[Vec[T]]

Returns columns of Mat as an indexed sequence of Vec instances

Returns columns of Mat as an indexed sequence of Vec instances

Attributes

def colsWithNA: Set[Int]

Yields column indices where column has some NA value

Yields column indices where column has some NA value

Attributes

def concat(other: Mat[T]): Mat[T]

Concatenate this Mat to an other Mat vertically, i.e. concatenate as lists of rows

Concatenate this Mat to an other Mat vertically, i.e. concatenate as lists of rows

Attributes

def contents: Array[T]

Returns (a copy of) the contents of matrix as a single array in row-major order

Returns (a copy of) the contents of matrix as a single array in row-major order

Attributes

def copy: Mat[T]

Makes a copy of this Mat

Makes a copy of this Mat

Attributes

Yields a matrix without those cols that have NA

Yields a matrix without those cols that have NA

Attributes

Yields a matrix without those rows that have NA

Yields a matrix without those rows that have NA

Attributes

override def equals(o: Any): Boolean

Row-by-row equality check of all values.

Row-by-row equality check of all values.

Attributes

Definition Classes
Any
override def hashCode(): Int

Default hashcode is simple rolling prime multiplication of sums of hashcodes for all values.

Default hashcode is simple rolling prime multiplication of sums of hashcodes for all values.

Attributes

Definition Classes
Any
def isEmpty: Boolean

Returns true if the matrix is empty

Returns true if the matrix is empty

Attributes

def isSquare: Boolean

Returns true if rows == cols

Returns true if rows == cols

Attributes

def length: Int

Returns total number of entries in the matrix

Returns total number of entries in the matrix

Attributes

def map[B : ScalarTag](f: T => B): Mat[B]
def mapCols[B : ScalarTag](f: (Vec[T], Int) => Vec[B]): Mat[B]

Maps a function over each col in the matrix f must return a Vec with numRows elements

Maps a function over each col in the matrix f must return a Vec with numRows elements

Attributes

def mapRows[B : ScalarTag](f: (Vec[T], Int) => Vec[B]): Mat[B]

Maps a function over each row in the matrix f must return a Vec with numCols elements

Maps a function over each row in the matrix f must return a Vec with numCols elements

Attributes

def mutateCols(f: (Vec[T], Int) => Vec[T]): Unit

In place mutate cols of the matrix

In place mutate cols of the matrix

Attributes

def mutateRows(f: (Vec[T], Int) => Vec[T]): Unit

In place mutate rows of the matrix

In place mutate rows of the matrix

Attributes

def mutateSetCell(r: Int, c: Int, v: T): Unit
def mutateSetColumn(c: Int, v: T): Unit
def mutateSetDiagonal(v: T): Unit
def mutateSetLowerTriangle(v: T): Unit
def mutateSetRow(r: Int, v: T): Unit
def mutateSetUpperTriangle(v: T): Unit
def raw(i: Int): T

Return unboxed value of matrix at an offset from zero in row-major order

Return unboxed value of matrix at an offset from zero in row-major order

Value parameters

i

index

Attributes

def raw(r: Int, c: Int): T

Return unboxed value of matrix at row/column

Return unboxed value of matrix at row/column

Value parameters

c

col index

r

row index

Attributes

def reduceCols[B : ScalarTag](f: (Vec[T], Int) => B): Vec[B]

Reduces each col with a function f must return a scalar

Reduces each col with a function f must return a scalar

Attributes

def reduceRows[B : ScalarTag](f: (Vec[T], Int) => B): Vec[B]

Reduces each row with a function f must return a scalar

Reduces each row with a function f must return a scalar

Attributes

def reshape(r: Int, c: Int): Mat[T]

Changes the shape of matrix without changing the underlying data

Changes the shape of matrix without changing the underlying data

Backing array will be shared between the two instances!

Attributes

def roundTo(sig: Int)(implicit ev: Numeric[T]): Mat[Double]

Rounds elements in the matrix (which must be numeric) to a significance level

Rounds elements in the matrix (which must be numeric) to a significance level

Value parameters

sig

Significance level to round to (e.g., 2 decimal places)

Attributes

def row(r: Int): Vec[T]

Returns a specific row of the Mat as a Vec

Returns a specific row of the Mat as a Vec

Value parameters

r

Row index

Attributes

def row(locs: Int*): Mat[T]

Access Mat rows at a particular integer offsets

Access Mat rows at a particular integer offsets

Value parameters

locs

a sequence of integer offsets

Attributes

def row(locs: Array[Int]): Mat[T]

Access Mat rows at a particular integer offsets

Access Mat rows at a particular integer offsets

Value parameters

locs

an array of integer offsets

Attributes

def row(slice: Slice[Int]): Mat[T]

Access Mat rows specified by a slice

Access Mat rows specified by a slice

Value parameters

slice

a slice specifier

Attributes

def rows: IndexedSeq[Vec[T]]

Returns rows of matrix as an indexed sequence of Vec instances

Returns rows of matrix as an indexed sequence of Vec instances

Attributes

def rows(seq: IndexedSeq[Int]): IndexedSeq[Vec[T]]

Returns rows of matrix as an indexed sequence of Vec instances

Returns rows of matrix as an indexed sequence of Vec instances

Attributes

def rowsWithNA: Set[Int]

Yields row indices where row has some NA value

Yields row indices where row has some NA value

Attributes

def stringify(nrows: Int, ncols: Int): String

Creates a string representation of Mat

Creates a string representation of Mat

Value parameters

ncols

Max number of cols to include

nrows

Max number of rows to include

Attributes

def takeCols(locs: Array[Int]): Mat[T]

Create Mat comprised of same values in specified columns

Create Mat comprised of same values in specified columns

Attributes

def takeCols(locs: Int*): Mat[T]

Create Mat comprised of same values in specified columns

Create Mat comprised of same values in specified columns

Attributes

def takeRows(locs: Array[Int]): Mat[T]
def takeRows(locs: Vec[Int]): Mat[T]
def takeRows(locs: Int*): Mat[T]

Create Mat comprised of same values in specified rows

Create Mat comprised of same values in specified rows

Attributes

def toArray: Array[T]

Returns the backing array of this Mat Mutations to this array are visible to this Mat

Returns the backing array of this Mat Mutations to this array are visible to this Mat

Elements are laid out in row-major order

Attributes

def toFrame: Frame[Int, Int, T]

Converst to Frame

Converst to Frame

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def toVec: Vec[T]

Concatenate all rows into a single row-wise Vec instance

Concatenate all rows into a single row-wise Vec instance

Underlying array is shared between the two instances

Attributes

def transpose: Mat[T]
def update(r: Int, c: Int, v: T): Unit
def withoutCols(locs: Array[Int]): Mat[T]

Create Mat comprised of same values without the specified columns

Create Mat comprised of same values without the specified columns

Value parameters

locs

Col locations to exclude

Attributes

def withoutCols(locs: Int*): Mat[T]

Create Mat comprised of same values without the specified columns

Create Mat comprised of same values without the specified columns

Value parameters

locs

Col locations to exclude

Attributes

def withoutRows(locs: Array[Int]): Mat[T]

Create Mat comprised of same values without the specified rows

Create Mat comprised of same values without the specified rows

Value parameters

locs

Row locations to exclude

Attributes

def withoutRows(locs: Int*): Mat[T]

Create Mat comprised of same values without the specified rows

Create Mat comprised of same values without the specified rows

Value parameters

locs

Row locations to exclude

Attributes

Inherited methods

def %[B, That](other: B)(implicit op: BinOp[Mod, Mat[T], B, That]): That

Integer modulus of division

Integer modulus of division

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance (divisor)

Attributes

Inherited from:
NumericOps
def %=[B](other: B)(implicit op: BinOpInPlace[Mod, Mat[T], B]): Unit

Attributes

Inherited from:
NumericOps
def &[B, That](other: B)(implicit op: BinOp[BitAnd, Mat[T], B, That]): That

Bit-wise AND

Bit-wise AND

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def &&[B, That](other: B)(implicit op: BinOp[AndOp, Mat[T], B, That]): That

Logical AND

Logical AND

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def *[B, That](other: B)(implicit op: BinOp[Multiply, Mat[T], B, That]): That

Multiplication

Multiplication

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def **[B, That](other: B)(implicit op: BinOp[Power, Mat[T], B, That]): That

Exponentiation

Exponentiation

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance (exponent)

Attributes

Inherited from:
NumericOps
def **=[B](other: B)(implicit op: BinOpInPlace[Power, Mat[T], B]): Unit

Attributes

Inherited from:
NumericOps
def *=[B](other: B)(implicit op: BinOpInPlace[Multiply, Mat[T], B]): Unit

Attributes

Inherited from:
NumericOps
def +[B, That](other: B)(implicit op: BinOp[Add, Mat[T], B, That]): That

Addition

Addition

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def +=[B](other: B)(implicit op: BinOpInPlace[Add, Mat[T], B]): Unit

Attributes

Inherited from:
NumericOps
def -[B, That](other: B)(implicit op: BinOp[Subtract, Mat[T], B, That]): That

Subtraction

Subtraction

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def -=[B](other: B)(implicit op: BinOpInPlace[Subtract, Mat[T], B]): Unit

Attributes

Inherited from:
NumericOps
def /[B, That](other: B)(implicit op: BinOp[Divide, Mat[T], B, That]): That

Division

Division

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance (divisor)

Attributes

Inherited from:
NumericOps
def /=[B](other: B)(implicit op: BinOpInPlace[Divide, Mat[T], B]): Unit

Attributes

Inherited from:
NumericOps
def <[B, That](other: B)(implicit op: BinOp[LtOp, Mat[T], B, That]): That

Less-than comparison operator

Less-than comparison operator

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def <<[B, That](other: B)(implicit op: BinOp[BitShl, Mat[T], B, That]): That

Bit-shift left

Bit-shift left

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def <=[B, That](other: B)(implicit op: BinOp[LteOp, Mat[T], B, That]): That

Less-than-or-equal-to comparison operator

Less-than-or-equal-to comparison operator

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def <>[B, That](other: B)(implicit op: BinOp[NeqOp, Mat[T], B, That]): That

Element-wise inequality operator

Element-wise inequality operator

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def =?[B, That](other: B)(implicit op: BinOp[EqOp, Mat[T], B, That]): That

Element-wise equality operator

Element-wise equality operator

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def >[B, That](other: B)(implicit op: BinOp[GtOp, Mat[T], B, That]): That

Greater-than comparison operator

Greater-than comparison operator

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def >=[B, That](other: B)(implicit op: BinOp[GteOp, Mat[T], B, That]): That

Greater-than-or-equal-to comparison operator

Greater-than-or-equal-to comparison operator

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def >>[B, That](other: B)(implicit op: BinOp[BitShr, Mat[T], B, That]): That

Bit-shift right (arithmetic)

Bit-shift right (arithmetic)

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def >>>[B, That](other: B)(implicit op: BinOp[BitUShr, Mat[T], B, That]): That

Bit-shift right (logical)

Bit-shift right (logical)

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def ^[B, That](other: B)(implicit op: BinOp[BitXor, Mat[T], B, That]): That

Bit-wise EXCLUSIVE OR

Bit-wise EXCLUSIVE OR

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def dot[B, That](other: B)(implicit op: BinOp[InnerProd, Mat[T], B, That]): That

Dot (inner) product

Dot (inner) product

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def outer[B, That](other: B)(implicit op: BinOp[OuterProd, Mat[T], B, That]): That

Outer product

Outer product

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def xor[B, That](other: B)(implicit op: BinOp[XorOp, Mat[T], B, That]): That

Logical EXCLUSIVE OR

Logical EXCLUSIVE OR

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def |[B, That](other: B)(implicit op: BinOp[BitOr, Mat[T], B, That]): That

Bit-wise OR

Bit-wise OR

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps
def ||[B, That](other: B)(implicit op: BinOp[OrOp, Mat[T], B, That]): That

Logical OR

Logical OR

Type parameters

B

type of the other operand

That

result type of operation

Value parameters

op

implicit evidence for operation between this and other

other

other operand instance

Attributes

Inherited from:
NumericOps

Concrete fields

val numCols: Int
val numRows: Int