TensorD

scalation.mathstat.TensorD
See theTensorD companion object
class TensorD(val dim: Int, val dim2: Int, val dim3: Int, var v: Array[Array[Array[Double]]] = ...) extends Serializable

The TensorD class is a simple implementation for 3-dimensional tensors. The names of the dimensions corresponds to MATLAB (row, column, sheet).

Value parameters

dim

size of the 1st level/dimension (row) of the tensor (height)

dim2

size of the 2nd level/dimension (column) of the tensor (width)

dim3

size of the 3rd level/dimension (sheet) of the tensor (depth)

v

the 3D array for holding the tensor elements

Attributes

See also

RTensorD for non-rectangular (ragged) tensors.

Companion
object
Graph
Supertypes
trait Serializable
class Object
trait Matchable
class Any

Members list

Type members

Types

type Broadcastable = TensorD | MatrixD | VectorD | Double

Value members

Constructors

def this(dim: Int)

Construct a dim by dim by dim cubic tensor.

Construct a dim by dim by dim cubic tensor.

Value parameters

dim

the row and column dimension

Attributes

def this(u: Array[Array[Array[Double]]])

Construct a tensor from three dimensional array.

Construct a tensor from three dimensional array.

Value parameters

u

the three dimensional array

Attributes

Concrete methods

inline def *(b: Broadcastable): TensorD
def *(b: MatrixD, c: MatrixD, d: MatrixD): TensorD

Multiply (multi-linear product) this tensor by three matrices b, c and d. this * (a, b, c)

Multiply (multi-linear product) this tensor by three matrices b, c and d. this * (a, b, c)

Value parameters

b

the first matrix to multiply by (requires leDimensions)

c

the second matrix to multiply by (requires leDimensions)

d

the third matrix to multiply by (requires leDimensions)

Attributes

See also
inline def *~(b: Broadcastable): TensorD
inline def +(b: Broadcastable): TensorD
inline def -(b: Broadcastable): TensorD
inline def /(b: Broadcastable): TensorD
def abs: TensorD

Absolute value.

Absolute value.

Attributes

def apply(i: Int, j: Int, k: Int): Double

Retrieve the i, j, k-th SCALAR element from the tensor x_ijk.

Retrieve the i, j, k-th SCALAR element from the tensor x_ijk.

Value parameters

i

the 1st dimension (row) index of the tensor

j

the 2nd dimension (column) index of the tensor

k

the 3rd dimension (sheet) index of the tensor

Attributes

def apply(i: Int, j: Int): VectorD

Retrieve the i, j-th VECTOR from the tensor x_ij:.

Retrieve the i, j-th VECTOR from the tensor x_ij:.

Value parameters

i

the 1st dimension (row) index of the tensor

j

the 2nd dimension (column) index of the tensor

Attributes

def apply(i: Int, all: Char, k: Int): VectorD

Retrieve the i, k-th VECTOR from the tensor x_i:k.

Retrieve the i, k-th VECTOR from the tensor x_i:k.

Value parameters

all

use the all columns indicator ?

i

the 1st dimension (row) index of the tensor

k

the 3rd dimension (sheet) index of the tensor

Attributes

def apply(all: Char, j: Int, k: Int): VectorD

Retrieve the j, k-th VECTOR from the tensor x_:jk.

Retrieve the j, k-th VECTOR from the tensor x_:jk.

Value parameters

all

use the all rows indicator ?

j

the 2nd dimension (column) index of the tensor

k

the 3rd dimension (sheet) index of the tensor

Attributes

def apply(i: Int): MatrixD

Return the i-th ROW FIXED MATRIX from the tensor (horizontal slice x_i::).

Return the i-th ROW FIXED MATRIX from the tensor (horizontal slice x_i::).

Value parameters

i

the 1st dimension (row) index of the tensor

Attributes

See also
def apply(all: Char, j: Int): MatrixD

Retrieve the j-th COLUMN FIXED MATRIX from the tensor (lateral slice x_:j:).

Retrieve the j-th COLUMN FIXED MATRIX from the tensor (lateral slice x_:j:).

Value parameters

all

use the all rows indicator ?

j

the 2nd dimension (column) index of the tensor

Attributes

See also
inline def apply(all: Char, all2: Char, k: Int): MatrixD

Retrieve the k-th SHEET FIXED MATRIX from the tensor (frontal slice x_::k).

Retrieve the k-th SHEET FIXED MATRIX from the tensor (frontal slice x_::k).

Value parameters

all

use the all rows indicator ?

all2

use the all columns indicator ?

k

the 3rd dimension (sheet) index of the tensor

Attributes

See also
def apply(ii: (Int, Int)): TensorD

Retrieve the ii._1 to ii._2 row slice of the tensor.

Retrieve the ii._1 to ii._2 row slice of the tensor.

Value parameters

ii

1st dimension (row) (start, end) indices of the tensor

Attributes

inline def apply(ir: Range): TensorD
def apply(ii: (Int, Int), jj: (Int, Int)): TensorD

Retrieve the ii._1 to ii._2, jj._1 to jj._2 row-column slice of the tensor.

Retrieve the ii._1 to ii._2, jj._1 to jj._2 row-column slice of the tensor.

Value parameters

ii

1st dimension (row) indices of the tensor (null => all)

jj

2nd dimension (column) indices of the tensor

Attributes

inline def apply(ir: Range, jr: Range): TensorD
def apply(ii: (Int, Int), jj: (Int, Int), kk: (Int, Int)): TensorD

Retrieve the ii._1 to ii._2, jj._1 to jj._2, kk._1 to kk._2 row-column-sheet slice of the tensor.

Retrieve the ii._1 to ii._2, jj._1 to jj._2, kk._1 to kk._2 row-column-sheet slice of the tensor.

Value parameters

ii

1st dimension (row) indices of the tensor (null => all)

jj

2nd dimension (column) indices of the tensor (null => all)

kk

3rd dimension (sheet) indices of the tensor

Attributes

def apply(is: Array[Int]): TensorD

Retrieve the is row selections from the tensor.

Retrieve the is row selections from the tensor.

Value parameters

is

1st dimension (row) indices of the tensor

Attributes

inline def apply(is: VectorI): TensorD
inline def apply(is: Seq[Int]): TensorD
def apply(is: Array[Int], js: Array[Int]): TensorD

Retrieve the is, js row-column selections from the tensor.

Retrieve the is, js row-column selections from the tensor.

Value parameters

is

1st dimension (row) indices of the tensor (null => all)

js

2nd dimension (column) indices of the tensor

Attributes

def apply(is: Array[Int], js: Array[Int], ks: Array[Int]): TensorD

Retrieve the is, js, ks row-column-sheet selections from the tensor.

Retrieve the is, js, ks row-column-sheet selections from the tensor.

Value parameters

is

1st dimension (row) indices of the tensor (null => all)

js

2nd dimension (column) indices of the tensor (null => all)

ks

3rd dimension (sheet) indices of the tensor

Attributes

def apply(ir: Range, all2: Char, sheet: Int): MatrixD

Retrieve a slice of the tensor as a MatrixD, based on a row range and specified sheet.

Retrieve a slice of the tensor as a MatrixD, based on a row range and specified sheet.

Value parameters

all2

a character indicating all columns should be included (typically '?').

ir

the range of rows to include in the slice.

sheet

the index of the sheet to extract from.

Attributes

def apply(ir: Range, jr: Range, kr: Range): TensorD

Retrieve a sub-tensor based on the three ranges.

Retrieve a sub-tensor based on the three ranges.

Value parameters

ir

the range of rows to include in the slice.

jr

the range of columns to include in the slice.

kr

the range of sheet to include in the slice.

Attributes

infix def bmm(b: TensorD): TensorD
def ceil: TensorD

Ceil each element.

Ceil each element.

Attributes

def clipByNorm(maxNorm: Double): TensorD
def clipByValue(minVal: Double, maxVal: Double): TensorD

Clip elements between min and max.

Clip elements between min and max.

Attributes

inline def dims: (Int, Int, Int)

Return the row, column and sheet dimensions of this tensor.

Return the row, column and sheet dimensions of this tensor.

Attributes

infix def dot(b: TensorD): TensorD

Compute the dot product of two vectors stored as tensors. Both tensors must have shape (n, 1, 1), representing row vectors. Leverages the existing VectorD dot method. Returns a scalar wrapped in a tensor of shape (1, 1, 1).

Compute the dot product of two vectors stored as tensors. Both tensors must have shape (n, 1, 1), representing row vectors. Leverages the existing VectorD dot method. Returns a scalar wrapped in a tensor of shape (1, 1, 1).

Value parameters

b

the tensor to take the dot product with

Attributes

def eLU(alpha: Double = ...): TensorD
override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Any
def exp: TensorD

Exponential.

Exponential.

Attributes

Flatten this tensor in row-major fashion, returning a matrix containing all the elements from the tensor.

Flatten this tensor in row-major fashion, returning a matrix containing all the elements from the tensor.

Attributes

Returns

a MatrixD containing all elements of the tensor in row-major order.

Flatten this 3D tensor into a 1D vector in row-major order. This method iterates through all elements of the tensor and stores them sequentially in a 1D array, which is then wrapped in a VectorD object.

Flatten this 3D tensor into a 1D vector in row-major order. This method iterates through all elements of the tensor and stores them sequentially in a 1D array, which is then wrapped in a VectorD object.

Attributes

Returns

a VectorD containing all elements of the tensor in row-major order.

def floor: TensorD

Floor each element.

Floor each element.

Attributes

def fullLike(value: Double): TensorD
def geLU: TensorD
override def hashCode(): Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Any
def id: TensorD
def leDimensions(b: TensorD): Boolean

Check whether the dimensions of this tensor are less than or equal to le those of the other tensor b.

Check whether the dimensions of this tensor are less than or equal to le those of the other tensor b.

Value parameters

b

the other matrix

Attributes

def log: TensorD

Log base e (natural log).

Log base e (natural log).

Attributes

def log10: TensorD

Log base 10.

Log base 10.

Attributes

def logBase(base: Double): TensorD

Log base-n.

Log base-n.

Attributes

def logistic(a: Double = ..., b: Double = ..., c: Double = ...): TensorD
def logit: TensorD
def lreLU(alpha: Double = ...): TensorD

Map each row of this tensor by applying function f to each row matrix and returning the collected result as a matrix.

Map each row of this tensor by applying function f to each row matrix and returning the collected result as a matrix.

Value parameters

f

the matrix to vector function to apply

Attributes

Map each element of this tensor by applying function f to each element and returning the collected result as a tensor.

Map each element of this tensor by applying function f to each element and returning the collected result as a tensor.

Value parameters

f

the scalar to scalar function to apply

Attributes

infix def matmul(b: TensorD): TensorD

Matrix‑matrix product for batch‑first tensors. Expected shapes A : (1, m, k) B : (1, k, n) Returns C : (1, m, n)

Matrix‑matrix product for batch‑first tensors. Expected shapes A : (1, m, k) B : (1, k, n) Returns C : (1, m, n)

Attributes

inline def max(that: TensorD): TensorD
def maxScalar(s: Double): TensorD

Max with a scalar.

Max with a scalar.

Attributes

def maxValue: Double
def mean: Double

Mean of all elements.

Mean of all elements.

Attributes

def meanAlongAxis(axis: Int): TensorD
inline def min(that: TensorD): TensorD
def minScalar(s: Double): TensorD

Min with a scalar.

Min with a scalar.

Attributes

def minValue: Double

Map each row of this tensor by applying function f to each row matrix and returning the collected result as a tensor.

Map each row of this tensor by applying function f to each row matrix and returning the collected result as a tensor.

Value parameters

f

the matrix to matrix function to apply

Attributes

def normF: Double
def normFSq: Double
def not(is: Array[Int]): TensorD

Retrieve the complement of the is row selections from the tensor.

Retrieve the complement of the is row selections from the tensor.

Value parameters

is

1st dimension (row) indices of the tensor

Attributes

def not(is: Array[Int], js: Array[Int]): TensorD

Retrieve the complement of the is row selections from the tensor.

Retrieve the complement of the is row selections from the tensor.

Value parameters

is

1st dimension (row) indices of the tensor

js

2nd dimension (column) indices of the tensor

Attributes

def not(is: Array[Int], js: Array[Int], ks: Array[Int]): TensorD

Retrieve the complement of the is row selections from the tensor.

Retrieve the complement of the is row selections from the tensor.

Value parameters

is

1st dimension (row) indices of the tensor

js

2nd dimension (column) indices of the tensor

ks

3rd dimension (sheet) indices of the tensor

Attributes

def permute(axes: Seq[Int]): TensorD

Permute the axes of this tensor according to the specified order. This method rearranges the dimensions of the tensor based on the given permutation of axes. The input axes specifies the new order of the axes. For example, if the original tensor has shape (a, b, c) and axes is Seq(1, 2, 0), the resulting tensor will have shape (b, c, a).

Permute the axes of this tensor according to the specified order. This method rearranges the dimensions of the tensor based on the given permutation of axes. The input axes specifies the new order of the axes. For example, if the original tensor has shape (a, b, c) and axes is Seq(1, 2, 0), the resulting tensor will have shape (b, c, a).

Value parameters

axes

the sequence specifying the new order of the axes

Attributes

Returns

a new TensorD with permuted axes

Throws
IllegalArgumentException

if axes does not contain a valid permutation

def reLU: TensorD

Reciprocal.

Reciprocal.

Attributes

def reshape(newShape: Seq[Int]): TensorD

Reshape this tensor to a new shape while preserving the order of elements. This method ensures that the total number of elements remains the same and rearranges the elements into the specified dimensions.

Reshape this tensor to a new shape while preserving the order of elements. This method ensures that the total number of elements remains the same and rearranges the elements into the specified dimensions.

Value parameters

newShape

the desired shape as a sequence of three integers

Attributes

Returns

a new TensorD with the specified shape

Throws
IllegalArgumentException

if the total number of elements does not match

def round: TensorD

Round each element.

Round each element.

Attributes

def set(x: Double): Unit

Set all the tensor element values to x.

Set all the tensor element values to x.

Value parameters

x

the value to set all elements to

Attributes

def setFormat(newFormat: String): Unit

Set the format to the newFormat.

Set the format to the newFormat.

Value parameters

newFormat

the new format string

Attributes

def setSlice(i: Int, d: MatrixD): Unit
inline def shape: List[Int]

Get the shape of this tensor as a list of integers.

Get the shape of this tensor as a list of integers.

Attributes

Returns

the shape of the tensor

def sign: TensorD

Sign of each element (-1, 0, 1).

Sign of each element (-1, 0, 1).

Attributes

def slice(i: Int): MatrixD
def sqrt: TensorD

Square root.

Square root.

Attributes

def standardize(axis: Int): TensorD
def std: Double

Standard deviation of all elements.

Standard deviation of all elements.

Attributes

def stdAlongAxis(axis: Int): TensorD
def sum: Double

Sum of all elements.

Sum of all elements.

Attributes

def sumAlongAxis(axis: Int): TensorD
def tanh: TensorD
def toInt: TensorD

Convert this tensor to a matrix where all the elements have integer values.

Convert this tensor to a matrix where all the elements have integer values.

Attributes

override def toString: String

Convert this tensor to a string with a double line break after each sheet and a single line break after each row.

Convert this tensor to a string with a double line break after each sheet and a single line break after each row.

Attributes

Definition Classes
Any
def toString2: String

Convert this tensor to a string with a line break after each sheet.

Convert this tensor to a string with a line break after each sheet.

Attributes

def transpose(i: Int, j: Int): TensorD

Transpose/swap two axes of this tensor.

Transpose/swap two axes of this tensor.

Value parameters

i

first axis index (0..2)

j

second axis index (0..2)

Attributes

Returns

a new TensorD with axes i and j swapped

Throws
IllegalArgumentException

if an axis index is out of range

inline def unary_-: TensorD

Negate the tensor (unary -).

Negate the tensor (unary -).

Attributes

def update(i: Int, j: Int, k: Int, x: Double): Unit

Update a single SCALAR element of the tensor to the given value. Usage: z(i, j, k) = x

Update a single SCALAR element of the tensor to the given value. Usage: z(i, j, k) = x

Value parameters

i

1st dimension (row) index of the tensor

j

2nd dimension (column) index of the tensor

k

3rd dimension (sheet) index of the tensor

x

the value for updating the tensor at the above position

Attributes

def update(i: Int, j: Int, x: VectorD): Unit

Update a single VECTOR of the tensor to the given vector. Usage: z(i, j) = x

Update a single VECTOR of the tensor to the given vector. Usage: z(i, j) = x

Value parameters

i

1st dimension (row) index of the tensor

j

2nd dimension (column) index of the tensor

x

the vector for updating the tensor at the above position

Attributes

def update(i: Int, all: Char, k: Int, x: VectorD): Unit

Update a single VECTOR of the tensor to the given vector. Usage: z(i, ?, k) = x

Update a single VECTOR of the tensor to the given vector. Usage: z(i, ?, k) = x

Value parameters

all

use the all columns indicator ?

i

1st dimension (row) index of the tensor

k

3rd dimension (sheet) index of the tensor

x

the vector for updating the tensor at the above position

Attributes

def update(all: Char, j: Int, k: Int, x: VectorD): Unit

Update a single VECTOR of the tensor to the given vector. Usage: z(?, j, k) = x

Update a single VECTOR of the tensor to the given vector. Usage: z(?, j, k) = x

Value parameters

all

use the all rows indicator ?

j

2nd dimension (column) index of the tensor

k

3rd dimension (sheet) index of the tensor

x

the vector for updating the tensor at the above position

Attributes

def update(i: Int, x: MatrixD): Unit

Update a single MATRIX of the tensor (for ROW i) to the given matrix. Usage: z(i) = x

Update a single MATRIX of the tensor (for ROW i) to the given matrix. Usage: z(i) = x

Value parameters

i

1st dimension (row) index of the tensor

x

the matrix for updating the tensor at the above position

Attributes

def update(all: Char, j: Int, x: MatrixD): Unit

Update a single MATRIX of the tensor (for COLUMN j) to the given matrix. Usage: z(?, j) = x

Update a single MATRIX of the tensor (for COLUMN j) to the given matrix. Usage: z(?, j) = x

Value parameters

all

use the all rows indicator ?

j

2nd dimension (column) index of the tensor

x

the matrix for updating the tensor at the above position

Attributes

def update(all: Char, all2: Char, k: Int, x: MatrixD): Unit

Update a single MATRIX of the tensor (for SHEET k) to the given matrix. Usage: z(?, ?, k) = x

Update a single MATRIX of the tensor (for SHEET k) to the given matrix. Usage: z(?, ?, k) = x

Value parameters

all

use the all rows indicator ?

all2

use the all columns indicator ?

k

the 3rd dimension (sheet) index of the tensor

x

the matrix for updating the tensor at the above position

Attributes

def update(ir: Range, all2: Char, sheet: Int, matrix: MatrixD): Unit

Update a slice of the tensor with values from a given matrix.

Update a slice of the tensor with values from a given matrix.

Value parameters

all2

a character indicating all columns should be updated (typically '?').

ir

the range of rows in the tensor to update.

matrix

the matrix containing the values to update the tensor with.

sheet

the index of the sheet in the tensor to update.

Attributes

Throws
IllegalArgumentException

if the dimensions of the row range and matrix do not match.

def update(all: Char, all2: Char, kr: Range, tensorBlk: TensorD): Unit

Update a slice of the tensor with values from a given 3D block (matrix over multiple sheets).

Update a slice of the tensor with values from a given 3D block (matrix over multiple sheets).

Value parameters

all

a character indicating all rows should be updated (typically '?').

all2

a character indicating all columns should be updated (typically '?').

kr

the range of sheets in the tensor to update.

tensorBlk

the 3D block (rows x columns x sheets) containing the values to update the tensor with.

Attributes

Throws
IllegalArgumentException

if the dimensions of the tensor block do not match the tensor's dimensions.

def update(ir: Range, jr: Range, kr: Range, tensorBlk: TensorD): Unit

Update a slice of the tensor with values from a given 3D block.

Update a slice of the tensor with values from a given 3D block.

Value parameters

ir

the range of rows in the tensor to update.

jr

the range of columns in the tensor to update.

kr

the range of sheets in the tensor to update.

tensorBlk

the 3D block containing the values to write.

Attributes

Throws
IllegalArgumentException

if the dimensions do not match.

def variance: Double

Variance of all elements.

Variance of all elements.

Attributes

def varianceAlongAxis(axis: Int): TensorD
inline def ~^(b: Broadcastable): TensorD
def ~^(s: Int): TensorD

Raise each element to an integer power.

Raise each element to an integer power.

Attributes

Concrete fields

val dim: Int
val dim2: Int
val dim3: Int
val indices: Range
val indices2: Range
val indices3: Range