Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package saddle

    Saddle is a Scala Data Library.

    Saddle

    Saddle is a Scala Data Library.

    Saddle provides array-backed, indexed one- and two-dimensional data structures.

    These data structures are specialized on JVM primitives. With them one can often avoid the overhead of boxing and unboxing.

    Basic operations also aim to be robust to missing values (NA's)

    The building blocks are intended to be easily composed.

    The foundational building blocks are:

    Inspiration for Saddle comes from many sources, including the R programming language, the pandas data analysis library for Python, and the Scala collections library.

    Definition Classes
    org
  • package array

    This package contains utilities for working with arrays that are specialized for numeric types.

    This package contains utilities for working with arrays that are specialized for numeric types.

    Definition Classes
    saddle
  • package binary

    Binary serialization for Frame[String,String,T] or Mat[T] with primitive T

    Binary serialization for Frame[String,String,T] or Mat[T] with primitive T

    The layout of binary format is as follows:

    • The first 6 bytes are "SADDLE"
    • The next unsigned byte is the major version
    • The next unsigned byte is the minor version
    • The next 4 bytes form a little endian integer as HEADER_LENGTH
    • The next HEADER_LENGTH bytes form an UTF-8 string as the header.
    • The header is a valid JSON object with the following fields:
      • v: numeric positive integer is the version of the header structure
      • colix : a JSON array of strings, it is the column index of the frame
      • rowix : a JSON array of strings, it is the row index of the frame
      • numrows: numeric positive integer, number of rows
      • numcols: numeric positive integer, number of cols
      • Either one of rowix or numrows may be missing
      • Either one of colix or numcols may be missing
      • rowmajor : a boolean, indicating whether the data is stored in row-major or col-major order
      • datatype : string, either "double", "long", "int", "float", "byte"
    • The header is padded with spaces (0x20) such that HEADER_LENGTH+12 is divisible by 16. The count of spaces are included in HEADER_LENGTH.
    • The next width * numRows * numCols bytes form a little endian primitive array in row-major or col-major order. numRows and numCols are determined from the rowix/numrows and colix/numcols header fields. width is determined from the datatype field (8 for double and long, 4 for int and float, 1 for byte)
    Definition Classes
    saddle
  • package csv
    Definition Classes
    saddle
  • package groupby
    Definition Classes
    saddle
  • package index
    Definition Classes
    saddle
  • package io
    Definition Classes
    saddle
  • package linalg
    Definition Classes
    saddle
  • package macros
    Definition Classes
    saddle
  • package mat
    Definition Classes
    saddle
  • package npy
    Definition Classes
    saddle
  • package ops

    Provides type aliases for a few basic operations

    Provides type aliases for a few basic operations

    Definition Classes
    saddle
  • package scalar
    Definition Classes
    saddle
  • package spire
    Definition Classes
    saddle
  • package util

    Additional utilities that need a home

    Additional utilities that need a home

    Definition Classes
    saddle
  • package vec

    Factory methods to generate Vec instances

    Factory methods to generate Vec instances

    Definition Classes
    saddle
  • ArrToVec
  • Buffer
  • FillBackward
  • FillForward
  • FillMethod
  • Frame
  • Index
  • Mat
  • Numeric
  • OptionToScalar
  • PctMethod
  • PrimitiveToScalar
  • RankTie
  • SeqToFrame
  • SeqToFrame2
  • SeqToIndex
  • SeqToMat
  • SeqToSeries
  • SeqToVec
  • Series
  • Vec
  • VecDoubleOps
  • doubleIsNumeric
  • floatIsNumeric
  • intIsNumeric
  • longIsNumeric
  • order

final class Mat[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.

Linear Supertypes
NumericOps[Mat[T]], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Mat
  2. NumericOps
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Mat(numRows: Int, numCols: Int, values: Array[T], scalarTag: ScalarTag[T])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def %[B, That](other: B)(implicit op: BinOp[Mod, Mat[T], 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
  4. def %=[B](other: B)(implicit op: BinOpInPlace[Mod, Mat[T], B]): Unit
    Definition Classes
    NumericOps
  5. def &[B, That](other: B)(implicit op: BinOp[BitAnd, Mat[T], 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
  6. def &&[B, That](other: B)(implicit op: BinOp[AndOp, Mat[T], 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
  7. def *[B, That](other: B)(implicit op: BinOp[Multiply, Mat[T], 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
  8. def **[B, That](other: B)(implicit op: BinOp[Power, Mat[T], 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
  9. def **=[B](other: B)(implicit op: BinOpInPlace[Power, Mat[T], B]): Unit
    Definition Classes
    NumericOps
  10. def *=[B](other: B)(implicit op: BinOpInPlace[Multiply, Mat[T], B]): Unit
    Definition Classes
    NumericOps
  11. def +[B, That](other: B)(implicit op: BinOp[Add, Mat[T], 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
  12. def +=[B](other: B)(implicit op: BinOpInPlace[Add, Mat[T], B]): Unit
    Definition Classes
    NumericOps
  13. def -[B, That](other: B)(implicit op: BinOp[Subtract, Mat[T], 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
  14. def -=[B](other: B)(implicit op: BinOpInPlace[Subtract, Mat[T], B]): Unit
    Definition Classes
    NumericOps
  15. def /[B, That](other: B)(implicit op: BinOp[Divide, Mat[T], 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
  16. def /=[B](other: B)(implicit op: BinOpInPlace[Divide, Mat[T], B]): Unit
    Definition Classes
    NumericOps
  17. def <[B, That](other: B)(implicit op: BinOp[LtOp, Mat[T], 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
  18. def <<[B, That](other: B)(implicit op: BinOp[BitShl, Mat[T], 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
  19. 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

    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
  20. def <>[B, That](other: B)(implicit op: BinOp[NeqOp, Mat[T], 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
  21. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  22. def =?[B, That](other: B)(implicit op: BinOp[EqOp, Mat[T], 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
  23. def >[B, That](other: B)(implicit op: BinOp[GtOp, Mat[T], 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
  24. 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

    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
  25. def >>[B, That](other: B)(implicit op: BinOp[BitShr, Mat[T], 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
  26. def >>>[B, That](other: B)(implicit op: BinOp[BitUShr, Mat[T], 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
  27. def T: Mat[T]
  28. def ^[B, That](other: B)(implicit op: BinOp[BitXor, Mat[T], 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
  29. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  30. 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

    r

    Slice to apply to rows

    c

    Slice to apply to cols

  31. 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

    r

    Integer row offset

    c

    Array of col offsets

  32. 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

    r

    Array of row offsets

    c

    Integer col offset

  33. 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

    r

    Array of row offsets

    c

    Array of col offsets

  34. 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

    r

    row index

    c

    col index

  35. 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

    i

    index

  36. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  37. def col(slice: Slice[Int]): Mat[T]

    Access mat columns specified by a slice

    Access mat columns specified by a slice

    slice

    a slice specifier

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

    Access Mat columns at a particular integer offsets

    Access Mat columns at a particular integer offsets

    locs

    an array of integer offsets

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

    Access Mat columns at a particular integer offsets

    Access Mat columns at a particular integer offsets

    locs

    a sequence of integer offsets

  40. 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

    c

    Column index

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

    Returns columns of Mat as an indexed sequence of Vec instances

  42. def cols: IndexedSeq[Vec[T]]

    Returns columns of Mat as an indexed sequence of Vec instances

  43. def colsWithNA: Set[Int]

    Yields column indices where column has some NA value

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

    Concatenate this Mat to an other Mat vertically, i.e.

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

  45. def contents: Array[T]

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

  46. def copy: Mat[T]

    Makes a copy of this Mat

  47. def dot[B, That](other: B)(implicit op: BinOp[InnerProd, Mat[T], 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
  48. def dropColsWithNA: Mat[T]

    Yields a matrix without those cols that have NA

  49. def dropRowsWithNA: Mat[T]

    Yields a matrix without those rows that have NA

  50. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  51. def equals(o: Any): Boolean

    Row-by-row equality check of all values.

    Row-by-row equality check of all values.

    Definition Classes
    Mat → AnyRef → Any
  52. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  53. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  54. 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.

    Definition Classes
    Mat → AnyRef → Any
  55. def isEmpty: Boolean

    Returns true if the matrix is empty

  56. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  57. def isSquare: Boolean

    Returns true if rows == cols

  58. def length: Int

    Returns total number of entries in the matrix

  59. def map[B](f: (T) => B)(implicit arg0: ST[B]): Mat[B]
  60. def mapCols[B](f: (Vec[T], 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

  61. def mapRows[B](f: (Vec[T], 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

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

    In place mutate cols of the matrix

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

    In place mutate rows of the matrix

  64. def mutateSetCell(r: Int, c: Int, v: T): Unit
    Annotations
    @inline()
  65. def mutateSetColumn(c: Int, v: T): Unit
  66. def mutateSetDiagonal(v: T): Unit
  67. def mutateSetLowerTriangle(v: T): Unit
  68. def mutateSetRow(r: Int, v: T): Unit
  69. def mutateSetUpperTriangle(v: T): Unit
  70. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  71. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  72. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  73. val numCols: Int
  74. val numRows: Int
  75. def outer[B, That](other: B)(implicit op: BinOp[OuterProd, Mat[T], 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
  76. 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

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

    Return unboxed value of matrix at row/column

    Return unboxed value of matrix at row/column

    r

    row index

    c

    col index

    Annotations
    @inline()
  78. 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

    i

    index

    Annotations
    @inline()
  79. def reduceCols[B](f: (Vec[T], Int) => B)(implicit arg0: ST[B]): Vec[B]

    Reduces each col with a function f must return a scalar

  80. def reduceRows[B](f: (Vec[T], Int) => B)(implicit arg0: ST[B]): Vec[B]

    Reduces each row with a function f must return a scalar

  81. 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!

  82. def roundTo(sig: Int = 2)(implicit ev: NUM[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

    sig

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

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

    Access Mat rows specified by a slice

    Access Mat rows specified by a slice

    slice

    a slice specifier

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

    Access Mat rows at a particular integer offsets

    Access Mat rows at a particular integer offsets

    locs

    an array of integer offsets

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

    Access Mat rows at a particular integer offsets

    Access Mat rows at a particular integer offsets

    locs

    a sequence of integer offsets

  86. 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

    r

    Row index

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

    Returns rows of matrix as an indexed sequence of Vec instances

  88. def rows: IndexedSeq[Vec[T]]

    Returns rows of matrix as an indexed sequence of Vec instances

  89. def rowsWithNA: Set[Int]

    Yields row indices where row has some NA value

  90. val scalarTag: ScalarTag[T]
  91. 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

  92. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  93. def takeCols(locs: Int*): Mat[T]

    Create Mat comprised of same values in specified columns

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

    Create Mat comprised of same values in specified columns

  95. def takeRows(locs: Int*): Mat[T]

    Create Mat comprised of same values in specified rows

  96. def takeRows(locs: Vec[Int]): Mat[T]
  97. def takeRows(locs: Array[Int]): Mat[T]
  98. 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

  99. def toFrame: Frame[Int, Int, T]

    Converst to Frame

  100. def toString(): String
    Definition Classes
    Mat → AnyRef → Any
  101. 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

  102. def transpose: Mat[T]
  103. def update(r: Int, c: Int, v: T): Unit
    Annotations
    @inline()
  104. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  105. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  106. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  107. 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

    locs

    Col locations to exclude

  108. 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

    locs

    Col locations to exclude

  109. 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

    locs

    Row locations to exclude

  110. 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

    locs

    Row locations to exclude

  111. def xor[B, That](other: B)(implicit op: BinOp[XorOp, Mat[T], 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
  112. def |[B, That](other: B)(implicit op: BinOp[BitOr, Mat[T], 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
  113. def ||[B, That](other: B)(implicit op: BinOp[OrOp, Mat[T], 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

Inherited from NumericOps[Mat[T]]

Inherited from AnyRef

Inherited from Any

Ungrouped