com.intel.analytics.bigdl.tensor

TensorMath

trait TensorMath[T] extends AnyRef

It provides multiple math operation functions for manipulating Tensor objects. All functions support both allocating a new Tensor to return the result and treating the caller as a target Tensor, in which case the target Tensor(s) will be resized accordingly and filled with the result. This property is especially useful when one wants to have tight control over when memory is allocated.

T

should be double or float

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. TensorMath
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def *(t: Tensor[T]): Tensor[T]

    Multiply a Tensor by another one, return the result in new allocated memory.

    Multiply a Tensor by another one, return the result in new allocated memory. The number of elements in the Tensors must match, but the sizes do not matter. The size of the returned Tensor will be the size of the first Tensor

    t
    returns

  2. abstract def *(s: T): Tensor[T]

    multiply all elements of this with value not in place.

    multiply all elements of this with value not in place. It will allocate new memory.

    s
    returns

  3. abstract def +(t: Tensor[T]): Tensor[T]

    Add a Tensor to another one, return the result in new allocated memory.

    Add a Tensor to another one, return the result in new allocated memory. The number of elements in the Tensors must match, but the sizes do not matter. The size of the returned Tensor will be the size of the first Tensor

    t
    returns

  4. abstract def +(s: T): Tensor[T]

    Add all elements of this with value not in place.

    Add all elements of this with value not in place. It will allocate new memory.

    s
    returns

  5. abstract def -(t: Tensor[T]): Tensor[T]

    Subtract a Tensor from another one, return the result in new allocated memory.

    Subtract a Tensor from another one, return the result in new allocated memory. The number of elements in the Tensors must match, but the sizes do not matter. The size of the returned Tensor will be the size of the first Tensor

    t
    returns

  6. abstract def -(s: T): Tensor[T]

    subtract all elements of this with the value not in place.

    subtract all elements of this with the value not in place. It will allocate new memory.

    s
    returns

  7. abstract def /(t: Tensor[T]): Tensor[T]

    Divide a Tensor by another one, return the result in new allocated memory.

    Divide a Tensor by another one, return the result in new allocated memory. The number of elements in the Tensors must match, but the sizes do not matter. The size of the returned Tensor will be the size of the first Tensor

    t
    returns

  8. abstract def /(s: T): Tensor[T]

    divide all elements of this with value not in place.

    divide all elements of this with value not in place. It will allocate new memory.

    s
    returns

  9. abstract def abs(x: Tensor[T]): Tensor[T]

  10. abstract def abs(): Tensor[T]

    replaces all elements in-place with the absolute values of the elements of this.

    replaces all elements in-place with the absolute values of the elements of this.

    returns

  11. abstract def add(x: Tensor[T], y: Tensor[T]): Tensor[T]

  12. abstract def add(value: T): Tensor[T]

    x.

    x.add(value) : add value to all elements of x in place.

    value
    returns

  13. abstract def add(x: Tensor[T], value: T, y: Tensor[T]): Tensor[T]

    z.

    z.add(x, value, y) puts the result of x + value * y in z.

    x
    value
    y
    returns

  14. abstract def add(y: Tensor[T]): Tensor[T]

    accumulates all elements of y into this

    accumulates all elements of y into this

    y

    other tensor

    returns

    current tensor

  15. abstract def add(value: T, y: Tensor[T]): Tensor[T]

    x.

    x.add(value,y) multiply-accumulates values of y into x.

    value

    scalar

    y

    other tensor

    returns

    current tensor

  16. abstract def addcdiv(value: T, tensor1: Tensor[T], tensor2: Tensor[T]): Tensor[T]

    Performs the element-wise division of tensor1 by tensor2, multiply the result by the scalar value and add it to x.

    Performs the element-wise division of tensor1 by tensor2, multiply the result by the scalar value and add it to x. The number of elements must match, but sizes do not matter.

    value
    tensor1
    tensor2
    returns

  17. abstract def addcmul(tensor1: Tensor[T], tensor2: Tensor[T]): Tensor[T]

  18. abstract def addcmul(value: T, tensor1: Tensor[T], tensor2: Tensor[T]): Tensor[T]

    Performs the element-wise multiplication of tensor1 by tensor2, multiply the result by the scalar value (1 if not present) and add it to x.

    Performs the element-wise multiplication of tensor1 by tensor2, multiply the result by the scalar value (1 if not present) and add it to x. The number of elements must match, but sizes do not matter.

    value
    tensor1
    tensor2

  19. abstract def addmm(v1: T, v2: T, mat1: Tensor[T], mat2: Tensor[T]): Tensor[T]

    res = v1 * res + v2 * mat1*mat2

  20. abstract def addmm(v2: T, mat1: Tensor[T], mat2: Tensor[T]): Tensor[T]

    res = res + v2 * mat1 * mat2

  21. abstract def addmm(mat1: Tensor[T], mat2: Tensor[T]): Tensor[T]

    res = res + mat1 * mat2

  22. abstract def addmm(M: Tensor[T], mat1: Tensor[T], mat2: Tensor[T]): Tensor[T]

    res = M + (mat1*mat2)

  23. abstract def addmm(v1: T, M: Tensor[T], v2: T, mat1: Tensor[T], mat2: Tensor[T]): Tensor[T]

    Performs a matrix-matrix multiplication between mat1 (2D tensor) and mat2 (2D tensor).

    Performs a matrix-matrix multiplication between mat1 (2D tensor) and mat2 (2D tensor). Optional values v1 and v2 are scalars that multiply M and mat1 * mat2 respectively. Optional value beta is a scalar that scales the result tensor, before accumulating the result into the tensor. Defaults to 1.0. If mat1 is a n x m matrix, mat2 a m x p matrix, M must be a n x p matrix.

    res = (v1 * M) + (v2 * mat1*mat2)

    v1
    M
    v2
    mat1
    mat2

  24. abstract def addmv(alpha: T, mat: Tensor[T], vec2: Tensor[T]): Tensor[T]

    res = res + alpha * (mat * vec2)

  25. abstract def addmv(beta: T, alpha: T, mat: Tensor[T], vec2: Tensor[T]): Tensor[T]

    res = beta * res + alpha * (mat * vec2)

  26. abstract def addmv(beta: T, vec1: Tensor[T], alpha: T, mat: Tensor[T], vec2: Tensor[T]): Tensor[T]

    Performs a matrix-vector multiplication between mat (2D Tensor) and vec2 (1D Tensor) and add it to vec1.

    Performs a matrix-vector multiplication between mat (2D Tensor) and vec2 (1D Tensor) and add it to vec1. Optional values v1 and v2 are scalars that multiply vec1 and vec2 respectively.

    In other words, res = (beta * vec1) + alpha * (mat * vec2)

    Sizes must respect the matrix-multiplication operation: if mat is a n × m matrix, vec2 must be vector of size m and vec1 must be a vector of size n.

  27. abstract def addr(v1: T, t1: Tensor[T], v2: T, t2: Tensor[T], t3: Tensor[T]): Tensor[T]

    Performs the outer-product between vec1 (1D Tensor) and vec2 (1D Tensor).

    Performs the outer-product between vec1 (1D Tensor) and vec2 (1D Tensor). Optional values v1 and v2 are scalars that multiply mat and vec1 [out] vec2 respectively. In other words,res_ij = (v1 * mat_ij) + (v2 * vec1_i * vec2_j)

    v1
    t1
    v2
    t2
    t3
    returns

  28. abstract def addr(v1: T, t1: Tensor[T], v2: T, t2: Tensor[T]): Tensor[T]

  29. abstract def addr(v1: T, t1: Tensor[T], t2: Tensor[T]): Tensor[T]

  30. abstract def addr(t1: Tensor[T], t2: Tensor[T]): Tensor[T]

    Performs the outer-product between vec1 (1D tensor) and vec2 (1D tensor).

    Performs the outer-product between vec1 (1D tensor) and vec2 (1D tensor). Optional values v1 and v2 are scalars that multiply mat and vec1 [out] vec2 respectively. In other words, res_ij = (v1 * mat_ij) + (v2 * vec1_i * vec2_j)

    t1
    t2
    returns

  31. abstract def baddbmm(alpha: T, batch1: Tensor[T], batch2: Tensor[T]): Tensor[T]

    res_i = res_i + (alpha * batch1_i * batch2_i)

  32. abstract def baddbmm(beta: T, alpha: T, batch1: Tensor[T], batch2: Tensor[T]): Tensor[T]

    res_i = (beta * res_i) + (alpha * batch1_i * batch2_i)

  33. abstract def baddbmm(beta: T, M: Tensor[T], alpha: T, batch1: Tensor[T], batch2: Tensor[T]): Tensor[T]

    Perform a batch matrix matrix multiplication of matrices and stored in batch1 and batch2 with batch add.

    Perform a batch matrix matrix multiplication of matrices and stored in batch1 and batch2 with batch add. batch1 and batch2 must be 3D Tensors each containing the same number of matrices. If batch1 is a b × n × m Tensor, batch2 a b × m × p Tensor, res will be a b × n × p Tensor.

    In other words, res_i = (beta * M_i) + (alpha * batch1_i * batch2_i)

  34. abstract def bmm(batch1: Tensor[T], batch2: Tensor[T]): Tensor[T]

    res_i = res_i + batch1_i * batch2_i

  35. abstract def cdiv(x: Tensor[T], y: Tensor[T]): Tensor[T]

    Element-wise divide z.

    Element-wise divide z.cdiv(x, y) means z = x / y

    x

    tensor

    y

    tensor

    returns

    current tensor

  36. abstract def cdiv(y: Tensor[T]): Tensor[T]

    Element-wise divide x.

    Element-wise divide x.cdiv(y) all elements of x divide all elements of y. x = x / y

    y

    tensor

    returns

    current tensor

  37. abstract def cmax(x: Tensor[T], y: Tensor[T]): Tensor[T]

    stores the element-wise maximum of x and y in z.

    stores the element-wise maximum of x and y in z. z.cmax(x, y) means z = max(x, y)

    x

    tensor

    y

    tensor

  38. abstract def cmax(y: Tensor[T]): Tensor[T]

    stores the element-wise maximum of x and y in x.

    stores the element-wise maximum of x and y in x. x.cmax(y) = max(x, y)

    y

    tensor

    returns

    current tensor

  39. abstract def cmax(value: T): Tensor[T]

    For each elements of the tensor, performs the max operation compared with the given value vector.

    For each elements of the tensor, performs the max operation compared with the given value vector.

    value
    returns

  40. abstract def cmul(x: Tensor[T], y: Tensor[T]): Tensor[T]

    Element-wise multiply z.

    Element-wise multiply z.cmul(x, y) equals z = x * y

    x

    tensor

    y

    tensor

    returns

    current tensor

  41. abstract def cmul(y: Tensor[T]): Tensor[T]

    Element-wise multiply x.

    Element-wise multiply x.cmul(y) multiplies all elements of x with corresponding elements of y. x = x * y

    y

    tensor

    returns

    current tensor

  42. abstract def conv2(kernel: Tensor[T], vf: Char = 'V'): Tensor[T]

    This function computes 2 dimensional convolution of a single image with a single kernel (2D output).

    This function computes 2 dimensional convolution of a single image with a single kernel (2D output). the dimensions of input and kernel need to be 2, and Input image needs to be bigger than kernel. The last argument controls if the convolution is a full ('F') or valid ('V') convolution. The default is valid convolution.

    kernel
    vf

    full ('F') or valid ('V') convolution.

    returns

  43. abstract def dist(y: Tensor[T], norm: Int): T

    Performs the p-norm distance calculation between two tensors

    Performs the p-norm distance calculation between two tensors

    y

    the secode Tensor

    norm

    the norm of distance

    returns

  44. abstract def div(y: Tensor[T]): Tensor[T]

    Element-wise divide x.

    Element-wise divide x.div(y) all elements of x divide all elements of y. x = x / y

    y

    tensor

    returns

    current tensor

  45. abstract def div(value: T): Tensor[T]

    divide all elements of this with value in-place.

    divide all elements of this with value in-place.

    value
    returns

  46. abstract def dot(y: Tensor[T]): T

    Performs the dot product.

    Performs the dot product. The number of elements must match: both Tensors are seen as a 1D vector.

    y
    returns

  47. abstract def eq(x: Tensor[T], y: T): Tensor[T]

    Implements == operator comparing each element in x with y

    Implements == operator comparing each element in x with y

    y
    returns

    current tensor reference

  48. abstract def exp(): Tensor[T]

  49. abstract def exp(y: Tensor[T]): Tensor[T]

  50. abstract def floor(): Tensor[T]

    Replaces all elements in-place with the floor result of elements

    Replaces all elements in-place with the floor result of elements

    returns

  51. abstract def floor(y: Tensor[T]): Tensor[T]

    Populate the given tensor with the floor result of elements

    Populate the given tensor with the floor result of elements

    y
    returns

  52. abstract def gather(dim: Int, index: Tensor[T], src: Tensor[T]): Tensor[T]

    change this tensor with values from the original tensor by gathering a number of values from each "row", where the rows are along the dimension dim.

    change this tensor with values from the original tensor by gathering a number of values from each "row", where the rows are along the dimension dim.

    dim
    index
    src
    returns

    this

  53. abstract def ge(x: Tensor[T], value: Double): Tensor[T]

    Implements >= operator comparing each element in x with value

    Implements >= operator comparing each element in x with value

    x
    value
    returns

  54. abstract def gt(x: Tensor[T], y: Tensor[T]): Tensor[T]

    Implements > operator comparing each element in x with y

    Implements > operator comparing each element in x with y

    x
    y
    returns

    current tensor reference

  55. abstract def index(dim: Int, index: Tensor[T], y: Tensor[T]): Tensor[T]

    Accumulate the elements of tensor into the original tensor by adding to the indices in the order given in index.

    Accumulate the elements of tensor into the original tensor by adding to the indices in the order given in index. The shape of tensor must exactly match the elements indexed or an error will be thrown.

    dim
    index
    y
    returns

  56. abstract def indexAdd(dim: Int, index: Tensor[T], y: Tensor[T]): Tensor[T]

    Accumulate the elements of tensor into the original tensor by adding to the indices in the order given in index.

    Accumulate the elements of tensor into the original tensor by adding to the indices in the order given in index. The shape of tensor must exactly match the elements indexed or an error will be thrown.

    dim
    index
    y
    returns

  57. abstract def le(x: Tensor[T], y: Tensor[T]): Tensor[T]

    Implements <= operator comparing each element in x with y

    Implements <= operator comparing each element in x with y

    x
    y
    returns

    current tensor reference

  58. abstract def log(): Tensor[T]

  59. abstract def log(y: Tensor[T]): Tensor[T]

    Replaces all elements in-place with the elements of lnx

    Replaces all elements in-place with the elements of lnx

    y
    returns

    current tensor reference

  60. abstract def log1p(): Tensor[T]

  61. abstract def log1p(y: Tensor[T]): Tensor[T]

  62. abstract def lt(x: Tensor[T], y: Tensor[T]): Tensor[T]

    Implements < operator comparing each element in x with y

    Implements < operator comparing each element in x with y

    x
    y
    returns

    current tensor reference

  63. abstract def maskedCopy(mask: Tensor[T], y: Tensor[T]): Tensor[T]

    Copies the elements of tensor into mask locations of itself.

    Copies the elements of tensor into mask locations of itself.

    mask
    y
    returns

    current tensor reference

  64. abstract def maskedFill(mask: Tensor[T], e: T): Tensor[T]

    Fills the masked elements of itself with value val

    Fills the masked elements of itself with value val

    mask
    e
    returns

    current tensor reference

  65. abstract def maskedSelect(mask: Tensor[T], y: Tensor[T]): Tensor[T]

    Returns a new Tensor which contains all elements aligned to a 1 in the corresponding mask.

    Returns a new Tensor which contains all elements aligned to a 1 in the corresponding mask.

    mask
    y
    returns

    current tensor reference

  66. abstract def max(values: Tensor[T], indices: Tensor[T], dim: Int): (Tensor[T], Tensor[T])

    performs the max operation over the dimension n

    performs the max operation over the dimension n

    values
    indices
    dim
    returns

  67. abstract def max(dim: Int): (Tensor[T], Tensor[T])

    performs the max operation over the dimension n

    performs the max operation over the dimension n

    dim
    returns

  68. abstract def max(): T

    returns the single biggest element of x

    returns the single biggest element of x

    returns

  69. abstract def mean(dim: Int): Tensor[T]

    performs the mean operation over the dimension dim.

    performs the mean operation over the dimension dim.

    dim
    returns

  70. abstract def mean(): T

    returns the mean of all elements of this.

    returns the mean of all elements of this.

    returns

  71. abstract def min(values: Tensor[T], indices: Tensor[T], dim: Int): (Tensor[T], Tensor[T])

    performs the min operation over the dimension n

    performs the min operation over the dimension n

    values
    indices
    dim
    returns

  72. abstract def min(dim: Int): (Tensor[T], Tensor[T])

    performs the min operation over the dimension n

    performs the min operation over the dimension n

    dim
    returns

  73. abstract def min(): T

    returns the single minimum element of x

    returns the single minimum element of x

    returns

  74. abstract def mm(mat1: Tensor[T], mat2: Tensor[T]): Tensor[T]

    res = mat1*mat2

  75. abstract def mul(x: Tensor[T], value: T): Tensor[T]

    put the result of x * value in current tensor

    put the result of x * value in current tensor

    value
    returns

  76. abstract def mul(value: T): Tensor[T]

    multiply all elements of this with value in-place.

    multiply all elements of this with value in-place.

    value
    returns

  77. abstract def mv(mat: Tensor[T], vec2: Tensor[T]): Tensor[T]

    res = res + (mat * vec2)

  78. abstract def negative(x: Tensor[T]): Tensor[T]

    Computes numerical negative value element-wise.

    Computes numerical negative value element-wise. y = -x

    x
    returns

    this tensor

  79. abstract def norm(value: Int): T

    returns the sum of the n-norms on the Tensor x

    returns the sum of the n-norms on the Tensor x

    value

    the n-norms

    returns

  80. abstract def norm(y: Tensor[T], value: Int, dim: Int): Tensor[T]

    returns the p-norms of the Tensor x computed over the dimension dim.

    returns the p-norms of the Tensor x computed over the dimension dim.

    y

    result buffer

    value
    dim
    returns

  81. abstract def pow(n: T): Tensor[T]

  82. abstract def pow(y: Tensor[T], n: T): Tensor[T]

    Replaces all elements in-place with the elements of x to the power of n

    Replaces all elements in-place with the elements of x to the power of n

    y
    n
    returns

    current tensor reference

  83. abstract def prod(x: Tensor[T], dim: Int): Tensor[T]

  84. abstract def prod(): T

    returns the product of the elements of this

    returns the product of the elements of this

    returns

  85. abstract def range(xmin: Double, xmax: Double, step: Int = 1): Tensor[T]

    resize this tensor size to floor((xmax - xmin) / step) + 1 and set values from xmin to xmax with step (default to 1).

    resize this tensor size to floor((xmax - xmin) / step) + 1 and set values from xmin to xmax with step (default to 1).

    xmin
    xmax
    step
    returns

    this tensor

  86. abstract def scatter(dim: Int, index: Tensor[T], src: Tensor[T]): Tensor[T]

    Writes all values from tensor src into this tensor at the specified indices

    Writes all values from tensor src into this tensor at the specified indices

    dim
    index
    src
    returns

    this

  87. abstract def sign(): Tensor[T]

    returns a new Tensor with the sign (+/- 1 or 0) of the elements of x.

    returns a new Tensor with the sign (+/- 1 or 0) of the elements of x.

    returns

  88. abstract def sqrt(y: Tensor[T]): Tensor[T]

  89. abstract def sqrt(): Tensor[T]

    replaces all elements in-place with the square root of the elements of this.

    replaces all elements in-place with the square root of the elements of this.

    returns

  90. abstract def sub(value: T): Tensor[T]

  91. abstract def sub(x: Tensor[T], y: Tensor[T]): Tensor[T]

  92. abstract def sub(y: Tensor[T]): Tensor[T]

    subtracts all elements of y from this

    subtracts all elements of y from this

    y

    other tensor

    returns

    current tensor

  93. abstract def sub(x: Tensor[T], value: T, y: Tensor[T]): Tensor[T]

  94. abstract def sub(value: T, y: Tensor[T]): Tensor[T]

  95. abstract def sum(x: Tensor[T], dim: Int): Tensor[T]

  96. abstract def sum(dim: Int): Tensor[T]

    performs the sum operation over the dimension dim

    performs the sum operation over the dimension dim

    dim
    returns

  97. abstract def sum(): T

    returns the sum of the elements of this

    returns the sum of the elements of this

    returns

  98. abstract def tanh(y: Tensor[T]): Tensor[T]

  99. abstract def tanh(): Tensor[T]

    replaces all elements in-place with the tanh root of the elements of this.

    replaces all elements in-place with the tanh root of the elements of this.

    returns

  100. abstract def topk(k: Int, dim: Int = 1, increase: Boolean = true, result: Tensor[T] = null, indices: Tensor[T] = null): (Tensor[T], Tensor[T])

    Get the top k smallest values and their indices.

    Get the top k smallest values and their indices.

    k
    dim

    dimension, default is the last dimension

    increase

    sort order, set it to true if you want to get the smallest top k values

    result

    result buffer

    indices

    indices buffer

    returns

  101. abstract def unary_-(): Tensor[T]

  102. abstract def uniform(args: T*): T

    return pseudo-random numbers, require 0<=args.

    return pseudo-random numbers, require 0<=args.length<=2 if args.length = 0, return [0, 1) if args.length = 1, return [1, args(0)] or [args(0), 1] if args.length = 2, return [args(0), args(1)]

    args

  103. abstract def xcorr2(kernel: Tensor[T], vf: Char = 'V'): Tensor[T]

    This function operates with same options and input/output configurations as conv2, but performs cross-correlation of the input with the kernel k.

    This function operates with same options and input/output configurations as conv2, but performs cross-correlation of the input with the kernel k.

    kernel
    vf

    full ('F') or valid ('V') convolution.

    returns

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(e: Either[Tensor[T], T]): Tensor[T]

  5. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  6. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  19. def toString(): String

    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped