Class JTensor

All Implemented Interfaces:
Tensor

public class JTensor extends AbstractTensor
A simple on-heap Tensor implementation.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int... index)
    Returns a portion of tensor given the index.
    boolean
    getBoolean(int... index)
    Returns the boolean value of element at given index.
    byte
    getByte(int... index)
    Returns the byte value of element at given index.
    double
    getDouble(int... index)
    Returns the double value of element at given index.
    float
    getFloat(int... index)
    Returns the float value of element at given index.
    int
    getInt(int... index)
    Returns the int value of element at given index.
    long
    getLong(int... index)
    Returns the long value of element at given index.
    short
    getShort(int... index)
    Returns the short value of element at given index.
    Returns the memory segment of underlying data.
    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(boolean value, int... index)
    Updates an element in place.
    set(byte value, int... index)
    Updates an element in place.
    set(double value, int... index)
    Updates an element in place.
    set(float value, int... index)
    Updates an element in place.
    set(int value, int... index)
    Updates an element in place.
    set(long value, int... index)
    Updates an element in place.
    set(short value, int... index)
    Updates an element in place.
    set(Tensor value, int... index)
    Updates a sub-tensor in place.
     
    Returns the layout that models values of basic data types.

    Methods inherited from class AbstractTensor

    dim, shape, size

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Tensor

    length
  • Method Details

    • valueLayout

      public ValueLayout valueLayout()
      Returns the layout that models values of basic data types.
      Returns:
      the layout that models values of basic data types.
    • memory

      public MemorySegment memory()
      Returns the memory segment of underlying data.
      Returns:
      the memory segment.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • scalarType

      public ScalarType scalarType()
      Description copied from interface: Tensor
      Returns the element data type.
      Returns:
      the element data type.
    • reshape

      public Tensor reshape(int... shape)
      Description copied from interface: Tensor
      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

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

      public JTensor get(int... index)
      Description copied from interface: Tensor
      Returns a portion of tensor given the index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the sub-tensor.
    • set

      public Tensor set(boolean value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • set

      public Tensor set(byte value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • set

      public Tensor set(short value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • set

      public Tensor set(int value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • set

      public Tensor set(long value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • set

      public Tensor set(float value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • set

      public Tensor set(double value, int... index)
      Updates an element in place.
      Parameters:
      value - the new element value.
      index - the element index.
      Returns:
      this tensor.
    • getBoolean

      public boolean getBoolean(int... index)
      Returns the boolean value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.
    • getByte

      public byte getByte(int... index)
      Returns the byte value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.
    • getShort

      public short getShort(int... index)
      Returns the short value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.
    • getInt

      public int getInt(int... index)
      Returns the int value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.
    • getLong

      public long getLong(int... index)
      Returns the long value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.
    • getFloat

      public float getFloat(int... index)
      Returns the float value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.
    • getDouble

      public double getDouble(int... index)
      Returns the double value of element at given index.
      Parameters:
      index - the index along the dimensions.
      Returns:
      the element value.