Interface Tensor

All Known Subinterfaces:
Matrix
All Known Implementing Classes:
AbstractTensor, AtA, BandMatrix, DenseMatrix, JTensor, Scalar, SparseMatrix, SymmMatrix, Vector

public interface Tensor
A Tensor is a multidimensional array containing elements of a single data type.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    dim()
    Returns the number of dimensions of tensor.
    get(int... index)
    Returns a portion of tensor given the index.
    default long
    Returns the number of tensor elements.
    reshape(int... shape)
    Returns a tensor with the same data and number of elements but with the specified shape.
    Returns the element data type.
    set(Tensor value, int... index)
    Updates a sub-tensor in place.
    int[]
    Returns the shape of tensor.
    int
    size(int dim)
    Returns the size of given dimension.
  • Method Details

    • scalarType

      ScalarType scalarType()
      Returns the element data type.
      Returns:
      the element data type.
    • dim

      int dim()
      Returns the number of dimensions of tensor.
      Returns:
      the number of dimensions of tensor
    • size

      int size(int dim)
      Returns the size of given dimension.
      Parameters:
      dim - dimension index.
      Returns:
      the size of given dimension.
    • length

      default long length()
      Returns the number of tensor elements. For tensors with packed storage (e.g., BandMatrix, SparseMatrix, SymmMatrix), it returns the number of non-zero elements.
      Returns:
      the number of tensor elements.
    • shape

      int[] shape()
      Returns the shape of tensor. That is a list of the extent of each dimension.
      Returns:
      the shape of tensor.
    • reshape

      Tensor reshape(int... shape)
      Returns a tensor with the same data and number of elements but with the specified shape. This method returns a view if shape is compatible with the current shape.
      Parameters:
      shape - the new shape of tensor.
      Returns:
      the tensor with the specified shape.
    • set

      Tensor set(Tensor value, int... index)
      Updates a sub-tensor in place.
      Parameters:
      value - the sub-tensor.
      index - the index.
      Returns:
      this tensor.
    • get

      Tensor get(int... index)
      Returns a portion of tensor given the index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the sub-tensor.