DenseMatrix

@SerialVersionUID(1L) final class DenseMatrix[@specialized(Double, Int, Float, Long) V](val rows: Int, val cols: Int, val data: Array[V], val offset: Int, val majorStride: Int, val isTranspose: Boolean) extends Matrix[V] with MatrixLike[V, DenseMatrix[V]] with Serializable

A DenseMatrix is a matrix with all elements found in an array. It is column major unless isTranspose is true, It is designed to be fast: Double- (and potentially Float-)valued DenseMatrices can be used with blas, and support operations to that effect.

Value Params
cols

number of cols

data

The underlying data. Column-major unless isTranpose is true. Mutate at your own risk. Note that this matrix may be a view of the data. Use linearIndex(r,c) to calculate indices.

isTranspose

if true, then the matrix is considered to be "transposed" (that is, row major)

majorStride

distance separating columns (or rows, for isTranspose). should have absolute value >= rows (or cols, for isTranspose)

offset

starting point into array

rows

number of rows

Companion
object
trait Serializable
trait Matrix[V]
trait MatrixLike[V, DenseMatrix[V]]
trait Tensor[(Int, Int), V]
trait TensorLike[(Int, Int), V, DenseMatrix[V]]
trait QuasiTensor[(Int, Int), V]
trait HasOps
class Object
trait Matchable
class Any

Value members

Constructors

def this(rows: Int, cols: Int)(implicit man: ClassTag[V])

Creates a matrix with the specified data array, rows, and columns.

Creates a matrix with the specified data array, rows, and columns.

def this(rows: Int, cols: Int, data: Array[V], offset: Int)

Creates a matrix with the specified data array, rows, and columns. Data must be column major

Creates a matrix with the specified data array, rows, and columns. Data must be column major

def this(rows: Int, cols: Int, data: Array[V])

Creates a matrix with the specified data array, rows, and columns. Data must be column major

Creates a matrix with the specified data array, rows, and columns. Data must be column major

def this(rows: Int, data: Array[V], offset: Int)

Creates a matrix with the specified data array and rows. columns inferred automatically

Creates a matrix with the specified data array and rows. columns inferred automatically

Concrete methods

def activeIterator: Iterator[((Int, Int), V)]
def activeKeysIterator: Iterator[(Int, Int)]
def activeSize: Int
def activeValuesIterator: Iterator[V]
def apply(row: Int, col: Int): V
def copy: DenseMatrix[V]
def delete(row: Int, axis: _0): DenseMatrix[V]
def delete(col: Int, axis: _1): DenseMatrix[V]
def delete(rows: Seq[Int], axis: _0): DenseMatrix[V]
def delete(cols: Seq[Int], axis: _1): DenseMatrix[V]
def flatten(view: View): DenseVector[V]

Converts this matrix to a DenseVector (column-major) If view = true (or View.Require), throws an exception if we cannot return a view. otherwise returns a view. If view == false (or View.Copy) returns a copy If view == View.Prefer (the default), returns a view if possible, otherwise returns a copy.

Converts this matrix to a DenseVector (column-major) If view = true (or View.Require), throws an exception if we cannot return a view. otherwise returns a view. If view == false (or View.Copy) returns a copy If view == View.Prefer (the default), returns a view if possible, otherwise returns a copy.

Views are only possible (if(isTranspose) majorStride == cols else majorStride == rows) == true

def indexAt(i: Int): Int
def isActive(i: Int): Boolean
def isContiguous: Boolean

Returns true if this dense matrix takes up a contiguous segment of the array

Returns true if this dense matrix takes up a contiguous segment of the array

def linearIndex(row: Int, col: Int): Int

Calculates the index into the data array for row and column

Calculates the index into the data array for row and column

def repr: DenseMatrix[V]
def reshape(rows: Int, cols: Int, view: View): DenseMatrix[V]

Reshapes this matrix to have the given number of rows and columns If view = true (or View.Require), throws an exception if we cannot return a view. otherwise returns a view. If view == false (or View.Copy) returns a copy If view == View.Prefer (the default), returns a view if possible, otherwise returns a copy.

Reshapes this matrix to have the given number of rows and columns If view = true (or View.Require), throws an exception if we cannot return a view. otherwise returns a view. If view == false (or View.Copy) returns a copy If view == View.Prefer (the default), returns a view if possible, otherwise returns a copy.

Views are only possible if (!isTranspose && majorStride == rows)

rows * cols must equal size, or cols < 0 && (size / rows * rows == size)

Value Params
cols

the number of columns, or -1 to auto determine based on size and rows

rows

the number of rows

def rowColumnFromLinearIndex(index: Int): (Int, Int)
def toArray: Array[V]

Converts this matrix to a flat Array (column-major)

Converts this matrix to a flat Array (column-major)

override def toDenseMatrix(implicit cm: ClassTag[V], zero: Zero[V]): DenseMatrix[V]
Definition Classes

Converts this matrix to a DenseVector (column-major)

Converts this matrix to a DenseVector (column-major)

def update(row: Int, col: Int, v: V): Unit
def valueAt(i: Int): V
def valueAt(row: Int, col: Int): V

Inherited methods

final def %[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for :%(b) when b is a scalar.

Alias for :%(b) when b is a scalar.

Inherited from
ImmutableNumericOps
final def %:%[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise modulo of this and b.

Element-wise modulo of this and b.

Inherited from
ImmutableNumericOps
final def %=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Alias for :%=(b) when b is a scalar.

Alias for :%=(b) when b is a scalar.

Inherited from
NumericOps
final def &[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for &:&(b) for all b.

Alias for &:&(b) for all b.

Inherited from
ImmutableNumericOps
final def &:&[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise logical "and" operator -- returns true if corresponding elements are non-zero.

Element-wise logical "and" operator -- returns true if corresponding elements are non-zero.

Inherited from
ImmutableNumericOps
final def &=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise and of this and b.

Mutates this by element-wise and of this and b.

Inherited from
NumericOps
final def *[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Matrix multiplication

Matrix multiplication

Inherited from
ImmutableNumericOps
final def *:*[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise product of this and b.

Element-wise product of this and b.

Inherited from
ImmutableNumericOps
final def *=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Alias for :*=(b) when b is a scalar.

Alias for :*=(b) when b is a scalar.

Inherited from
NumericOps
final def +[B, C, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for :+(b) for all b.

Alias for :+(b) for all b.

Inherited from
NumericOps
final def +:+[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise sum of this and b.

Element-wise sum of this and b.

Inherited from
ImmutableNumericOps
final def +=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Alias for :+=(b) for all b.

Alias for :+=(b) for all b.

Inherited from
NumericOps
final def -[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for -:-(b) for all b.

Alias for -:-(b) for all b.

Inherited from
ImmutableNumericOps
final def -:-[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise difference of this and b.

Element-wise difference of this and b.

Inherited from
ImmutableNumericOps
final def -=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Alias for :-=(b) for all b.

Alias for :-=(b) for all b.

Inherited from
NumericOps
final def /[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for :/(b) when b is a scalar.

Alias for :/(b) when b is a scalar.

Inherited from
ImmutableNumericOps
final def /:/[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise quotient of this and b.

Element-wise quotient of this and b.

Inherited from
ImmutableNumericOps
final def /=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Alias for :/=(b) when b is a scalar.

Alias for :/=(b) when b is a scalar.

Inherited from
NumericOps
final def :!=[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise inequality comparator of this and b.

Element-wise inequality comparator of this and b.

Inherited from
ImmutableNumericOps
final def :%=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise modulo of b into this.

Mutates this by element-wise modulo of b into this.

Inherited from
NumericOps
final def :&=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise and of this and b.

Mutates this by element-wise and of this and b.

Inherited from
NumericOps
final def :*=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise multiplication of b into this.

Mutates this by element-wise multiplication of b into this.

Inherited from
NumericOps
final def :+=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise addition of b into this.

Mutates this by element-wise addition of b into this.

Inherited from
NumericOps
final def :-=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise subtraction of b from this

Mutates this by element-wise subtraction of b from this

Inherited from
NumericOps
final def :/=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise division of b into this

Mutates this by element-wise division of b into this

Inherited from
NumericOps
final def :=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise assignment of b into this.

Mutates this by element-wise assignment of b into this.

Inherited from
NumericOps
final def :==[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise equality comparator of this and b.

Element-wise equality comparator of this and b.

Inherited from
ImmutableNumericOps
final def :^=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise exponentiation of this by b.

Mutates this by element-wise exponentiation of this by b.

Inherited from
NumericOps
final def :^^=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise xor of this and b.

Mutates this by element-wise xor of this and b.

Inherited from
NumericOps
final def :|=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise or of this and b.

Mutates this by element-wise or of this and b.

Inherited from
NumericOps
final def <:<[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise less=than comparator of this and b.

Element-wise less=than comparator of this and b.

Inherited from
NumericOps
final def <:=[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise less-than-or-equal-to comparator of this and b.

Element-wise less-than-or-equal-to comparator of this and b.

Inherited from
NumericOps
final def >:=[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise greater-than-or-equal-to comparator of this and b.

Element-wise greater-than-or-equal-to comparator of this and b.

Inherited from
NumericOps
final def >:>[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise greater-than comparator of this and b.

Element-wise greater-than comparator of this and b.

Inherited from
NumericOps
def \[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Shaped solve of this by b.

Shaped solve of this by b.

Inherited from
ImmutableNumericOps
final def ^:^[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise exponentiation of this and b.

Element-wise exponentiation of this and b.

Inherited from
ImmutableNumericOps
final def ^^[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for :^^(b) for all b.

Alias for :^^(b) for all b.

Inherited from
ImmutableNumericOps
final def ^^:^^[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise logical "xor" operator -- returns true if only one of the corresponding elements is non-zero.

Element-wise logical "xor" operator -- returns true if only one of the corresponding elements is non-zero.

Inherited from
ImmutableNumericOps
final def ^^=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise xor of this and b.

Mutates this by element-wise xor of this and b.

Inherited from
NumericOps
def active: TensorActive[(Int, Int), V, DenseMatrix[V]]
Inherited from
TensorLike
def apply[Slice1, Slice2, Result](slice1: Slice1, slice2: Slice2)(implicit canSlice: CanSlice2[DenseMatrix[V], Slice1, Slice2, Result]): Result

Method for slicing that is tuned for Matrices.

Method for slicing that is tuned for Matrices.

Inherited from
TensorLike
def apply[Result](a: (Int, Int), b: (Int, Int), c: (Int, Int), slice: (Int, Int)*)(implicit canSlice: CanSlice[DenseMatrix[V], Seq[(Int, Int)], Result]): Result

Slice a sequence of elements. Must be at least 2.

Slice a sequence of elements. Must be at least 2.

Inherited from
TensorLike
def apply[Slice, Result](slice: Slice)(implicit canSlice: CanSlice[DenseMatrix[V], Slice, Result]): Result

method for slicing a tensor. For instance, DenseVectors support efficient slicing by a Range object.

method for slicing a tensor. For instance, DenseVectors support efficient slicing by a Range object.

Inherited from
TensorLike
final def apply(i: (Int, Int)): V
Inherited from
Matrix
final def dot[B, BB >: B, That](b: B)(implicit op: Impl2[DenseMatrix[V], BB, That]): That

Inner product of this and b.

Inner product of this and b.

Inherited from
ImmutableNumericOps
override def equals(p1: Any): Boolean
Definition Classes
Matrix -> Any
Inherited from
Matrix
def findAll(f: V => Boolean): IndexedSeq[(Int, Int)]

Returns all indices k whose value satisfies a predicate.

Returns all indices k whose value satisfies a predicate.

Inherited from
QuasiTensor
def forall(fn: V => Boolean): Boolean

Returns true if and only if the given predicate is true for all elements.

Returns true if and only if the given predicate is true for all elements.

Inherited from
TensorLike
def forall(fn: ((Int, Int), V) => Boolean): Boolean

Returns true if and only if the given predicate is true for all elements.

Returns true if and only if the given predicate is true for all elements.

Inherited from
TensorLike
def foreachKey[U](fn: (Int, Int) => U): Unit

Applies the given function to each key in the tensor.

Applies the given function to each key in the tensor.

Inherited from
TensorLike
def foreachPair[U](fn: ((Int, Int), V) => U): Unit

Applies the given function to each key and its corresponding value.

Applies the given function to each key and its corresponding value.

Inherited from
TensorLike
def foreachValue[U](fn: V => U): Unit

Applies the given function to each value in the map (one for each element of the domain, including zeros).

Applies the given function to each value in the map (one for each element of the domain, including zeros).

Inherited from
TensorLike
override def hashCode(): Int
Definition Classes
Inherited from
QuasiTensor
def iterator: Iterator[((Int, Int), V)]
Inherited from
Matrix
def keySet: Set[(Int, Int)]
Inherited from
Matrix
def keys: TensorKeys[(Int, Int), V, DenseMatrix[V]]
Inherited from
TensorLike
def keysIterator: Iterator[(Int, Int)]
Inherited from
Matrix
def map[V2, That](fn: V => V2)(implicit canMapValues: CanMapValues[DenseMatrix[V], V, V2, That]): That
Inherited from
MatrixLike
def mapActivePairs[O, That](f: ((Int, Int), V) => O)(implicit bf: CanMapKeyValuePairs[DenseMatrix[V], (Int, Int), V, O, That]): That

Maps all active key-value pairs values.

Maps all active key-value pairs values.

Inherited from
TensorLike
def mapActiveValues[O, That](f: V => O)(implicit bf: CanMapValues[DenseMatrix[V], V, O, That]): That

Maps all non-zero values.

Maps all non-zero values.

Inherited from
TensorLike
def mapPairs[O, That](f: ((Int, Int), V) => O)(implicit bf: CanMapKeyValuePairs[DenseMatrix[V], (Int, Int), V, O, That]): That

Creates a new map containing a transformed copy of this map.

Creates a new map containing a transformed copy of this map.

Inherited from
TensorLike
def mapValues[O, That](f: V => O)(implicit bf: CanMapValues[DenseMatrix[V], V, O, That]): That

Creates a new map containing a transformed copy of this map.

Creates a new map containing a transformed copy of this map.

Inherited from
TensorLike
def pairs: TensorPairs[(Int, Int), V, DenseMatrix[V]]
Inherited from
TensorLike
def size: Int
Inherited from
Matrix
final def t[That, Slice1, Result](a: Slice1)(implicit op: CanTranspose[DenseMatrix[V], That], canSlice: CanSlice[That, Slice1, Result]): Result

A transposed view of this object, followed by a slice. Sadly frequently necessary.

A transposed view of this object, followed by a slice. Sadly frequently necessary.

Inherited from
ImmutableNumericOps
final def t[That, Slice1, Slice2, Result](a: Slice1, b: Slice2)(implicit op: CanTranspose[DenseMatrix[V], That], canSlice: CanSlice2[That, Slice1, Slice2, Result]): Result

A transposed view of this object, followed by a slice. Sadly frequently necessary.

A transposed view of this object, followed by a slice. Sadly frequently necessary.

Inherited from
ImmutableNumericOps
final def t[That](implicit op: CanTranspose[DenseMatrix[V], That]): That

A transposed view of this object.

A transposed view of this object.

Inherited from
ImmutableNumericOps
override def toString: String
Definition Classes
Matrix -> Any
Inherited from
Matrix
def toString(maxLines: Int, maxWidth: Int): String
Inherited from
Matrix
final def unary_![That](implicit op: Impl[DenseMatrix[V], That]): That
Inherited from
ImmutableNumericOps
final def unary_-[That](implicit op: Impl[DenseMatrix[V], That]): That
Inherited from
ImmutableNumericOps
final def update(i: (Int, Int), e: V): Unit
Inherited from
Matrix
def values: TensorValues[(Int, Int), V, DenseMatrix[V]]
Inherited from
TensorLike
def valuesIterator: Iterator[V]
Inherited from
Matrix
final def |[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Alias for :||(b) for all b.

Alias for :||(b) for all b.

Inherited from
ImmutableNumericOps
final def |:|[B, That](b: B)(implicit op: Impl2[DenseMatrix[V], B, That]): That

Element-wise logical "or" operator -- returns true if either element is non-zero.

Element-wise logical "or" operator -- returns true if either element is non-zero.

Inherited from
ImmutableNumericOps
final def |=[B](b: B)(implicit op: InPlaceImpl2[DenseMatrix[V], B]): DenseMatrix[V]

Mutates this by element-wise or of this and b.

Mutates this by element-wise or of this and b.

Inherited from
NumericOps

Concrete fields

val cols: Int
val data: Array[V]
val isTranspose: Boolean
val majorStride: Int
val offset: Int
val rows: Int