trait Mat[A] extends NumericOps[Mat[A]]
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 arithemetic expressions which operate on two Mat
s 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.
- A
Type of elements within the Mat
- Alphabetic
- By Inheritance
- Mat
- NumericOps
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
T: Mat[A]
Transpose of original matrix
-
abstract
def
at(r: Slice[Int], c: Slice[Int]): Mat[A]
Access a slice of the Mat by Slice parameters
Access a slice of the Mat by Slice parameters
- r
Slice to apply to rows
- c
Slice to apply to cols
-
abstract
def
at(r: Int, c: Array[Int]): Vec[A]
Access a slice of the Mat by integer offsets
Access a slice of the Mat by integer offsets
- r
Integer row offset
- c
Array of col offsets
-
abstract
def
at(r: Array[Int], c: Int): Vec[A]
Access a slice of the Mat by integer offsets
Access a slice of the Mat by integer offsets
- r
Array of row offsets
- c
Integer col offset
-
abstract
def
at(r: Array[Int], c: Array[Int]): Mat[A]
Access a slice of the Mat by integer offsets
Access a slice of the Mat by integer offsets
- r
Array of row offsets
- c
Array of col offsets
-
abstract
def
at(r: Int, c: Int): Scalar[A]
Return scalar value of Mat at at row/column
Return scalar value of Mat at at row/column
- r
row index
- c
col index
-
abstract
def
at(i: Int): Scalar[A]
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
- i
index
-
abstract
def
col(slice: Slice[Int]): Mat[A]
Access mat columns specified by a slice
Access mat columns specified by a slice
- slice
a slice specifier
-
abstract
def
col(locs: Array[Int]): Mat[A]
Access Mat columns at a particular integer offsets
Access Mat columns at a particular integer offsets
- locs
an array of integer offsets
-
abstract
def
col(locs: Int*): Mat[A]
Access Mat columns at a particular integer offsets
Access Mat columns at a particular integer offsets
- locs
a sequence of integer offsets
-
abstract
def
col(c: Int): Vec[A]
Returns a specific column of the Mat as a Vec
Returns a specific column of the Mat as a Vec
- c
Column index
-
abstract
def
cols(seq: IndexedSeq[Int]): IndexedSeq[Vec[A]]
Returns columns of Mat as an indexed sequence of Vec instances
-
abstract
def
cols(): IndexedSeq[Vec[A]]
Returns columns of Mat as an indexed sequence of Vec instances
-
abstract
def
colsWithNA: Set[Int]
Yields column indices where column has some NA value
-
abstract
def
contents: Array[A]
Returns (a copy of) the contents of matrix as a single array in row-major order
-
abstract
def
copy: Mat[A]
Makes a copy of this Mat
-
abstract
def
dropColsWithNA: Mat[A]
Yields a matrix without those cols that have NA
-
abstract
def
dropRowsWithNA: Mat[A]
Yields a matrix without those rows that have NA
-
abstract
def
isEmpty: Boolean
Returns true if the matrix is empty
-
abstract
def
isSquare: Boolean
Returns true if rows == cols
-
abstract
def
length: Int
Returns total number of entries in the matrix
-
abstract
def
map[B](f: (A) ⇒ B)(implicit arg0: ST[B]): Mat[B]
Maps a function over each element in the matrix
-
abstract
def
mapCols[B](f: (Vec[A], Int) ⇒ Vec[B])(implicit arg0: ST[B]): Mat[B]
Maps a function over each col in the matrix f must return a Vec with numRows elements
-
abstract
def
mapRows[B](f: (Vec[A], Int) ⇒ Vec[B])(implicit arg0: ST[B]): Mat[B]
Maps a function over each row in the matrix f must return a Vec with numCols elements
-
abstract
def
mutateCols[B](f: (Vec[A], Int) ⇒ Vec[A])(implicit arg0: ST[B]): Unit
In place mutate cols of the matrix
-
abstract
def
mutateRows[B](f: (Vec[A], Int) ⇒ Vec[A])(implicit arg0: ST[B]): Unit
In place mutate rows of the matrix
- abstract def mutateSetCell(r: Int, c: Int, v: A): Unit
- abstract def mutateSetColumn(c: Int, v: A): Unit
- abstract def mutateSetDiagonal(v: A): Unit
- abstract def mutateSetLowerTriangle(v: A): Unit
- abstract def mutateSetRow(r: Int, v: A): Unit
- abstract def mutateSetUpperTriangle(v: A): Unit
-
abstract
def
numCols: Int
Returns number of columns in the matrix shape
-
abstract
def
numRows: Int
Returns number of rows in the matrix shape
-
abstract
def
print(nrows: Int = 8, ncols: Int = 8, stream: OutputStream = System.out): Unit
Pretty-printer for Mat, which simply outputs the result of stringify.
Pretty-printer for Mat, which simply outputs the result of stringify.
- nrows
Number of elements to display
-
abstract
def
raw(r: Int, c: Int): A
Return unboxed value of matrix at row/column
Return unboxed value of matrix at row/column
- r
row index
- c
col index
-
abstract
def
raw(i: Int): A
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
- i
index
-
abstract
def
reshape(r: Int, c: Int): Mat[A]
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!
-
abstract
def
roundTo(sig: Int = 2)(implicit ev: NUM[A]): 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
- sig
Significance level to round to (e.g., 2 decimal places)
-
abstract
def
row(slice: Slice[Int]): Mat[A]
Access Mat rows specified by a slice
Access Mat rows specified by a slice
- slice
a slice specifier
-
abstract
def
row(locs: Array[Int]): Mat[A]
Access Mat rows at a particular integer offsets
Access Mat rows at a particular integer offsets
- locs
an array of integer offsets
-
abstract
def
row(locs: Int*): Mat[A]
Access Mat rows at a particular integer offsets
Access Mat rows at a particular integer offsets
- locs
a sequence of integer offsets
-
abstract
def
row(r: Int): Vec[A]
Returns a specific row of the Mat as a Vec
Returns a specific row of the Mat as a Vec
- r
Row index
-
abstract
def
rows(seq: IndexedSeq[Int]): IndexedSeq[Vec[A]]
Returns rows of matrix as an indexed sequence of Vec instances
-
abstract
def
rows(): IndexedSeq[Vec[A]]
Returns rows of matrix as an indexed sequence of Vec instances
-
abstract
def
rowsWithNA: Set[Int]
Yields row indices where row has some NA value
- abstract def scalarTag: ScalarTag[A]
-
abstract
def
stringify(nrows: Int = 8, ncols: Int = 8): String
Creates a string representation of Mat
Creates a string representation of Mat
- nrows
Max number of rows to include
- ncols
Max number of cols to include
-
abstract
def
takeCols(locs: Int*): Mat[A]
Create Mat comprised of same values in specified columns
-
abstract
def
takeCols(locs: Array[Int]): Mat[A]
Create Mat comprised of same values in specified columns
-
abstract
def
takeRows(locs: Int*): Mat[A]
Create Mat comprised of same values in specified rows
-
abstract
def
takeRows(locs: Vec[Int]): Mat[A]
Create Mat comprised of same values in specified rows
-
abstract
def
takeRows(locs: Array[Int]): Mat[A]
Create Mat comprised of same values in specified rows
-
abstract
def
toArray: Array[A]
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 Constant time operation
- abstract def toFrame: Frame[Int, Int, A]
-
abstract
def
toVec: Vec[A]
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
-
abstract
def
transpose: Mat[A]
Transpose of original matrix
-
abstract
def
withoutCols(locs: Int*): Mat[A]
Create Mat comprised of same values without the specified columns
Create Mat comprised of same values without the specified columns
- locs
Col locations to exclude
-
abstract
def
withoutCols(locs: Array[Int]): Mat[A]
Create Mat comprised of same values without the specified columns
Create Mat comprised of same values without the specified columns
- locs
Col locations to exclude
-
abstract
def
withoutRows(locs: Int*): Mat[A]
Create Mat comprised of same values without the specified rows
Create Mat comprised of same values without the specified rows
- locs
Row locations to exclude
-
abstract
def
withoutRows(locs: Array[Int]): Mat[A]
Create Mat comprised of same values without the specified rows
Create Mat comprised of same values without the specified rows
- locs
Row locations to exclude
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
%[B, That](other: B)(implicit op: BinOp[Mod, Mat[A], B, That]): That
Integer modulus of division
Integer modulus of division
- B
type of the other operand
- That
result type of operation
- other
other operand instance (divisor)
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
&[B, That](other: B)(implicit op: BinOp[BitAnd, Mat[A], B, That]): That
Bit-wise AND
Bit-wise AND
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
&&[B, That](other: B)(implicit op: BinOp[AndOp, Mat[A], B, That]): That
Logical AND
Logical AND
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
*[B, That](other: B)(implicit op: BinOp[Multiply, Mat[A], B, That]): That
Multiplication
Multiplication
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
**[B, That](other: B)(implicit op: BinOp[Power, Mat[A], B, That]): That
Exponentiation
Exponentiation
- B
type of the other operand
- That
result type of operation
- other
other operand instance (exponent)
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
+[B, That](other: B)(implicit op: BinOp[Add, Mat[A], B, That]): That
Addition
Addition
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
-[B, That](other: B)(implicit op: BinOp[Subtract, Mat[A], B, That]): That
Subtraction
Subtraction
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
/[B, That](other: B)(implicit op: BinOp[Divide, Mat[A], B, That]): That
Division
Division
- B
type of the other operand
- That
result type of operation
- other
other operand instance (divisor)
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
<[B, That](other: B)(implicit op: BinOp[LtOp, Mat[A], B, That]): That
Less-than comparison operator
Less-than comparison operator
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
<<[B, That](other: B)(implicit op: BinOp[BitShl, Mat[A], B, That]): That
Bit-shift left
Bit-shift left
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
<=[B, That](other: B)(implicit op: BinOp[LteOp, Mat[A], B, That]): That
Less-than-or-equal-to comparison operator
Less-than-or-equal-to comparison operator
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
<>[B, That](other: B)(implicit op: BinOp[NeqOp, Mat[A], B, That]): That
Element-wise inequality operator
Element-wise inequality operator
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
=?[B, That](other: B)(implicit op: BinOp[EqOp, Mat[A], B, That]): That
Element-wise equality operator
Element-wise equality operator
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
>[B, That](other: B)(implicit op: BinOp[GtOp, Mat[A], B, That]): That
Greater-than comparison operator
Greater-than comparison operator
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
>=[B, That](other: B)(implicit op: BinOp[GteOp, Mat[A], B, That]): That
Greater-than-or-equal-to comparison operator
Greater-than-or-equal-to comparison operator
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
>>[B, That](other: B)(implicit op: BinOp[BitShr, Mat[A], B, That]): That
Bit-shift right (arithmetic)
Bit-shift right (arithmetic)
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
>>>[B, That](other: B)(implicit op: BinOp[BitUShr, Mat[A], B, That]): That
Bit-shift right (logical)
Bit-shift right (logical)
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
^[B, That](other: B)(implicit op: BinOp[BitXor, Mat[A], B, That]): That
Bit-wise EXCLUSIVE OR
Bit-wise EXCLUSIVE OR
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
dot[B, That](other: B)(implicit op: BinOp[InnerProd, Mat[A], B, That]): That
Dot (inner) product
Dot (inner) product
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
outer[B, That](other: B)(implicit op: BinOp[OuterProd, Mat[A], B, That]): That
Outer product
Outer product
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
xor[B, That](other: B)(implicit op: BinOp[XorOp, Mat[A], B, That]): That
Logical EXCLUSIVE OR
Logical EXCLUSIVE OR
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
|[B, That](other: B)(implicit op: BinOp[BitOr, Mat[A], B, That]): That
Bit-wise OR
Bit-wise OR
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps
-
def
||[B, That](other: B)(implicit op: BinOp[OrOp, Mat[A], B, That]): That
Logical OR
Logical OR
- B
type of the other operand
- That
result type of operation
- other
other operand instance
- op
implicit evidence for operation between this and other
- Definition Classes
- NumericOps