Class Tensor

java.lang.Object
smile.deep.tensor.Tensor
All Implemented Interfaces:
AutoCloseable

public class Tensor extends Object implements AutoCloseable
A Tensor is a multidimensional array containing elements of a single data type.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A class that encapsulates the construction axes of a tensor.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tensor(org.bytedeco.pytorch.Tensor tensor)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a new tensor with the arccosine of the elements of input.
    Computes the arccosine of the elements of input in place.
    add(double other)
    Returns A + b.
    add(float other)
    Returns A + b.
    add(Tensor other)
    Returns A + B.
    add(Tensor other, double alpha)
    Returns A + alpha * B.
    add_(double other)
    Returns A += b.
    add_(float other)
    Returns A += b.
    add_(Tensor other)
    Returns A += B.
    add_(Tensor other, double alpha)
    Returns A += alpha * B.
    boolean
    all()
    Tests if all elements in the tensor are true.
    and(Tensor other)
    Returns logical AND of two boolean tensors.
    and_(Tensor other)
    Returns logical AND of two boolean tensors.
    static Tensor
    arange(long start, long end, long step)
    Returns a 1-D tensor of size (end - start) / step with values from the interval [start, end) taken with common difference step beginning from start.
    argmax(int dim, boolean keepDim)
    Returns the indices of the maximum value of a tensor across a dimension.
    Returns a new tensor with the arcsine of the elements of input.
    Computes the arcsine of the elements of input in place.
    org.bytedeco.pytorch.Tensor
    Returns the PyTorch tensor object.
    void
    Computes the gradients.
    bernoulli_(double p)
    Draws binary random numbers (0 or 1) from a Bernoulli distribution.
    boolean
    Returns the boolean value when the tensor holds a single value.
    byte[]
    Returns the byte array of tensor elements
    byte
    Returns the byte value when the tensor holds a single value.
    void
     
    Returns a contiguous in memory tensor containing the same data as this tensor.
    cos()
    Returns a new tensor with the cosine of the elements of input.
    Computes the cosine of the elements of input in place.
    static Tensor
    crossEntropy(Tensor input, Tensor target, String reduction, long ignoreIndex)
    Computes the cross entropy loss between input logits and target.
    Returns a new tensor, detached from the current graph.
    Returns the device on which the tensor is.
    int
    dim()
    Returns the number of dimensions of tensor.
    div(double other)
    Returns A / b.
    div(float other)
    Returns A / b.
    div(Tensor other)
    Returns A / B element wisely.
    div_(double other)
    Returns A /= b.
    div_(float other)
    Returns A /= b.
    div_(Tensor other)
    Returns A /= B element wisely.
    double[]
    Returns the double array of tensor elements
    double
    Returns the double value when the tensor holds a single value.
    dropout(double p)
    Randomly zeroes some elements of the input tensor with probability p.
    dropout_(double p)
    Randomly zeroes some elements in place with probability p.
    Returns the element data type.
    static Tensor
    empty(long... shape)
    Returns a tensor with uninitialized data.
    static Tensor
    empty(Tensor.Options options, long... shape)
    Returns a tensor with uninitialized data.
    eq(double other)
    Computes element-wise equality.
    eq(int other)
    Computes element-wise equality.
    eq(Tensor other)
    Computes element-wise equality.
    boolean
    equals(Object other)
     
    exp()
    Returns the exponential of elements in the tensor.
    Returns the exponential of elements in the tensor in place.
    expand(long... size)
    Returns a new view of this tensor with singleton dimensions expanded to a larger size.
    static Tensor
    eye(long shape)
    Returns an identity matrix.
    static Tensor
    eye(Tensor.Options options, long shape)
    Returns an identity matrix.
    fill_(double x)
    Fills this tensor with the specified value.
    fill_(int x)
    Fills this tensor with the specified value.
    Flattens the tensor by reshaping it into a one-dimensional tensor.
    flatten(int startDim)
    Flattens the tensor by reshaping it into a one-dimensional tensor.
    flatten(int startDim, int endDim)
    Flattens the tensor by reshaping it into a one-dimensional tensor.
    float[]
    Returns the float array of tensor elements
    float
    Returns the float value when the tensor holds a single value.
    static Tensor
    full(double value, long... shape)
    Returns a tensor filled with the given value.
    static Tensor
    full(long value, long... shape)
    Returns a tensor filled with the given value.
    gather(int dim, Tensor index)
    Gathers values along an axis specified by dim.
    ge(double other)
    Computes element-wise greater-than-or-equal-to comparison.
    ge(int other)
    Computes element-wise greater-than-or-equal-to comparison.
    ge(Tensor other)
    Computes element-wise greater-than-or-equal-to comparison.
    get(int... indices)
    Returns a portion of tensor given the indices.
    get(long... indices)
    Returns a portion of tensor given the indices.
    get(Index... indices)
    Returns a portion of tensor given the indices.
    get(Tensor index)
    Returns a portion of tensor given the indices.
    byte
    getByte(int... indices)
    Returns the byte value of element at given index.
    byte
    getByte(long... indices)
    Returns the byte value of element at given index.
    double
    getDouble(int... indices)
    Returns the double value of element at given index.
    double
    getDouble(long... indices)
    Returns the double value of element at given index.
    float
    getFloat(int... indices)
    Returns the float value of element at given index.
    float
    getFloat(long... indices)
    Returns the float value of element at given index.
    int
    getInt(int... indices)
    Returns the int value of element at given index.
    int
    getInt(long... indices)
    Returns the int value of element at given index.
    long
    getLong(int... indices)
    Returns the long value of element at given index.
    long
    getLong(long... indices)
    Returns the long value of element at given index.
    boolean
    Returns true if autograd should record operations on this tensor.
    short
    getShort(int... indices)
    Returns the short value of element at given index.
    short
    getShort(long... indices)
    Returns the short value of element at given index.
    gt(double other)
    Computes element-wise greater-than comparison.
    gt(int other)
    Computes element-wise greater-than comparison.
    gt(Tensor other)
    Computes element-wise greater-than comparison.
    static Tensor
    hstack(Tensor... tensors)
    Stacks tensors in sequence horizontally (column wise).
    int[]
    Returns the integer array of tensor elements
    int
    Returns the int value when the tensor holds a single value.
    static boolean
    Checks if the CUDA device supports bf16.
    isin(Tensor other)
    Tests if each element of this tensor is in other tensor.
    le(double other)
    Computes element-wise less-than-or-equal-to comparison.
    le(int other)
    Computes element-wise less-than-or-equal-to comparison.
    le(Tensor other)
    Computes element-wise less-than-or-equal-to comparison.
    long
    Returns the number of tensor elements.
    long[]
    Returns the long integer array of tensor elements
    long
    Returns the long value when the tensor holds a single value.
    lt(double other)
    Computes element-wise less-than comparison.
    lt(int other)
    Computes element-wise less-than comparison.
    lt(Tensor other)
    Computes element-wise less-than comparison.
    matmul(Tensor other)
    Returns the matrix product of two tensors.
    Returns the mean of all elements in the tensor.
    mean(int dim, boolean keepDim)
    Returns the mean along a dimension in the tensor.
    mul(double other)
    Returns A * b.
    mul(float other)
    Returns A * b.
    mul(Tensor other)
    Returns A * B element wisely.
    mul_(double other)
    Returns A *= b.
    mul_(float other)
    Returns A *= b.
    mul_(Tensor other)
    Returns A *= B element wisely.
    ne(double other)
    Computes element-wise inequality.
    ne(int other)
    Computes element-wise inequality.
    ne(Tensor other)
    Computes element-wise inequality.
    neg()
    Returns a new tensor with the negative of the elements of input.
    Returns the tensor with the negative of the elements of input.
    newOnes(long... shape)
    Returns a tensor filled with all ones.
    newZeros(long... shape)
    Returns a tensor filled with all zeros.
    static org.bytedeco.pytorch.NoGradGuard
    Disables gradient calculation.
    not()
    Returns logical NOT of this tensor.
    Returns logical NOT of this tensor.
    static Tensor
    of(boolean[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    of(byte[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    of(double[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    of(float[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    of(int[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    of(long[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    of(short[] data, long... shape)
    Returns a tensor with given data and shape.
    static Tensor
    ones(long... shape)
    Returns a tensor filled with all ones.
    static Tensor
    ones(Tensor.Options options, long... shape)
    Returns a tensor filled with all ones.
    or(Tensor other)
    Returns logical OR of two boolean tensors.
    or_(Tensor other)
    Returns logical OR of two boolean tensors.
    outer(Tensor other)
    Returns the outer product of two tensors.
    permute(long... dims)
    Returns a view of the original tensor input with its dimensions permuted.
    static Tensor
    polar(Tensor abs, Tensor angle)
    Returns a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with abs and angle.
    static AutoScope
    pop()
    Removes the scope at the top of the tensor stack.
    pow(double exponent)
    Returns a new tensor with the power of the elements of input.
    pow_(double exponent)
    Computes the power of the elements of input in place.
    void
    Prints the tensor on the standard output.
    static void
    push(AutoScope scope)
    Pushes a scope onto the top of the tensor scope stack.
    put(Tensor source, Index... indices)
    Updates a portion of tensor.
    put(Tensor source, Tensor index)
    Updates a portion of tensor.
    put_(byte x, int... indices)
    Updates an element in place.
    put_(byte x, long... indices)
    Updates an element in place.
    put_(double x, int... indices)
    Updates an element in place.
    put_(double x, long... indices)
    Updates an element in place.
    put_(float x, int... indices)
    Updates an element in place.
    put_(float x, long... indices)
    Updates an element in place.
    put_(int x, int... indices)
    Updates an element in place.
    put_(int x, long... indices)
    Updates an element in place.
    put_(long x, int... indices)
    Updates an element in place.
    put_(long x, long... indices)
    Updates an element in place.
    put_(short x, int... indices)
    Updates an element in place.
    put_(short x, long... indices)
    Updates an element in place.
    put_(Tensor source, Index... indices)
    Updates a portion of tensor in place.
    put_(Tensor source, Tensor index)
    Updates a portion of tensor in place.
    static Tensor
    rand(long... shape)
    Returns a tensor filled with values drawn from a uniform distribution on [0, 1).
    static Tensor
    rand(Tensor.Options options, long... shape)
    Returns a tensor filled with values drawn from a uniform distribution on [0, 1).
    static Tensor
    randn(long... shape)
    Returns a tensor filled with values drawn from a unit normal distribution.
    static Tensor
    randn(Tensor.Options options, long... shape)
    Returns a tensor filled with values drawn from a unit normal distribution.
    reshape(long... shape)
    Returns a tensor with the same data and number of elements but with the specified shape.
    Returns the reciprocal of the square-root of each of the elements in the tensor.
    Returns the reciprocal of the square-root of each of the elements in the tensor.
    scatterReduce(int dim, Tensor index, Tensor source, String reduce)
    Writes all values from the tensor src into this tensor at the indices specified in the index tensor.
    scatterReduce_(int dim, Tensor index, Tensor source, String reduce)
    Writes all values from the tensor src into this tensor at the indices specified in the index tensor.
    static void
    Sets the default options to create tensors.
    setRequireGrad(boolean required)
    Sets if autograd should record operations on this tensor.
    long[]
    Returns the shape of the tensor.
    short[]
    Returns the short integer array of tensor elements
    short
    Returns the short value when the tensor holds a single value.
    sin()
    Returns a new tensor with the sine of the elements of input.
    Computes the sine of the elements of input in place.
    long
    size(int dim)
    Returns the size of given dimension.
    softmax(int dim)
    Rescales a tensor so that the elements lie in the range [0,1] and sum to 1.
    sub(double other)
    Returns A -= b.
    sub(float other)
    Returns A - b.
    sub(Tensor other)
    Returns A - B.
    sub(Tensor other, double alpha)
    Returns A - alpha * B.
    sub_(double other)
    Returns A -= b.
    sub_(float other)
    Returns A - b.
    sub_(Tensor other)
    Returns A -= B.
    sub_(Tensor other, double alpha)
    Returns A -= alpha * B.
    sum()
    Returns the sum of all elements in the tensor.
    to(Device device)
    Clone the tensor to a device.
    to(Device device, ScalarType dtype)
    Clone the tensor to a device with a different data type.
    to(ScalarType dtype)
    Clone the tensor with a different data type.
    topk(int k)
    Returns the k largest elements.
    topk(int k, int dim, boolean largest, boolean sorted)
    Returns the k largest elements along a given dimension.
    topp(double p)
    Performs top-p (nucleus) sampling on a probability distribution.
     
    transpose(long dim0, long dim1)
    Returns a tensor that is a transposed version of input.
    triu(long diagonal)
    Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.
    triu_(long diagonal)
    Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.
    unsqueeze(long dim)
    Returns a new tensor with a dimension of size one inserted at the specified position.
    view(long... shape)
    Returns a view tensor that shares the same underlying data with this base tensor.
    Returns a view of tensor as a complex tensor.
    Returns a view of tensor as a real tensor.
    static Tensor
    vstack(Tensor... tensors)
    Stacks tensors in sequence vertically (row wise).
    static Tensor
    where(Tensor condition, double input, double other)
    Returns a tensor of elements selected from either input or other, depending on condition.
    static Tensor
    where(Tensor condition, int input, int other)
    Returns a tensor of elements selected from either input or other, depending on condition.
    static Tensor
    where(Tensor condition, Tensor input, Tensor other)
    Returns a tensor of elements selected from either input or other, depending on condition.
    static Tensor
    zeros(long... shape)
    Returns a tensor filled with all zeros.
    static Tensor
    zeros(Tensor.Options options, long... shape)
    Returns a tensor filled with all zeros.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Tensor

      public Tensor(org.bytedeco.pytorch.Tensor tensor)
      Constructor.
      Parameters:
      tensor - PyTorch Tensor object.
  • Method Details

    • setDefaultOptions

      public static void setDefaultOptions(Tensor.Options options)
      Sets the default options to create tensors. This does not affect factory function calls which are called with an explicit options argument.
      Parameters:
      options - the construction options of a tensor.
    • isBF16Supported

      public static boolean isBF16Supported()
      Checks if the CUDA device supports bf16. On pre-ampere hardware bf16 works, but doesn't provide speed-ups compared to fp32 matmul operations, and some matmul operations are failing outright, so this check is more like "guaranteed to work and be performant" than "works somehow".
      Returns:
      true if bf16 works and is performant.
    • noGradGuard

      public static org.bytedeco.pytorch.NoGradGuard noGradGuard()
      Disables gradient calculation. Disabling gradient calculation is useful for inference, when you are sure that you will not call backward. It will reduce memory consumption for computations that would otherwise have requireGrad(true).

      In this mode, the result of every computation will have requireGrad(false), even when the inputs have requireGrad(true).

      This context manager is thread-local; it will not affect computation in other threads.

      Returns:
      no grad guard to be used with try-with scope.
    • push

      public static void push(AutoScope scope)
      Pushes a scope onto the top of the tensor scope stack. Newly created tensors will be automatically added to this scope.
      Parameters:
      scope - a scope to automatically release tensors.
    • pop

      public static AutoScope pop()
      Removes the scope at the top of the tensor stack. All tensors added to this scope will be released.
      Returns:
      the top level scope.
    • print

      public void print()
      Prints the tensor on the standard output.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • toString

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

      public org.bytedeco.pytorch.Tensor asTorch()
      Returns the PyTorch tensor object.
      Returns:
      the PyTorch tensor object.
    • setRequireGrad

      public Tensor setRequireGrad(boolean required)
      Sets if autograd should record operations on this tensor.
      Parameters:
      required - the flag indicating if autograd should record operations on this tensor.
      Returns:
      this tensor.
    • getRequireGrad

      public boolean getRequireGrad()
      Returns true if autograd should record operations on this tensor.
      Returns:
      true if autograd should record operations on this tensor.
    • detach

      public Tensor detach()
      Returns a new tensor, detached from the current graph. The result will never require gradient.
      Returns:
      a new tensor that doesn't require gradient.
    • to

      public Tensor to(ScalarType dtype)
      Clone the tensor with a different data type.
      Parameters:
      dtype - the element data type of new tensor.
      Returns:
      The cloned tensor.
    • to

      public Tensor to(Device device)
      Clone the tensor to a device.
      Parameters:
      device - the compute device of new tensor.
      Returns:
      The cloned tensor.
    • to

      public Tensor to(Device device, ScalarType dtype)
      Clone the tensor to a device with a different data type.
      Parameters:
      device - the compute device of new tensor.
      dtype - the element data type of new tensor.
      Returns:
      The cloned tensor.
    • dtype

      public ScalarType dtype()
      Returns the element data type.
      Returns:
      the element data type.
    • device

      public Device device()
      Returns the device on which the tensor is.
      Returns:
      the device.
    • dim

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

      public long[] shape()
      Returns the shape of the tensor.
      Returns:
      the shape of the tensor.
    • size

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

      public long length()
      Returns the number of tensor elements.
      Returns:
      the number of tensor elements.
    • neg

      public Tensor neg()
      Returns a new tensor with the negative of the elements of input.
      Returns:
      the output tensor.
    • neg_

      public Tensor neg_()
      Returns the tensor with the negative of the elements of input.
      Returns:
      this tensor.
    • contiguous

      public Tensor contiguous()
      Returns a contiguous in memory tensor containing the same data as this tensor.
      Returns:
      a contiguous in memory tensor containing the same data as this tensor.
    • expand

      public Tensor expand(long... size)
      Returns a new view of this tensor with singleton dimensions expanded to a larger size.
      Parameters:
      size - the desired expanded size.
      Returns:
      the tensor view with the expanded size.
    • reshape

      public Tensor reshape(long... 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.
    • flatten

      public Tensor flatten()
      Flattens the tensor by reshaping it into a one-dimensional tensor. This function may return the original object, a view, or copy.
      Returns:
      the tensor with the specified shape.
    • flatten

      public Tensor flatten(int startDim)
      Flattens the tensor by reshaping it into a one-dimensional tensor. Only dimensions starting with startDim and ending with endDim are flattened. The order of elements in input is unchanged. This function may return the original object, a view, or copy.
      Parameters:
      startDim - the first dim to flatten.
      Returns:
      the tensor with the specified shape.
    • flatten

      public Tensor flatten(int startDim, int endDim)
      Flattens the tensor by reshaping it into a one-dimensional tensor. Only dimensions starting with startDim and ending with endDim are flattened. The order of elements in input is unchanged. This function may return the original object, a view, or copy.
      Parameters:
      startDim - the first dim to flatten.
      endDim - the last dim to flatten
      Returns:
      the tensor with the specified shape.
    • backward

      public void backward()
      Computes the gradients.
    • fill_

      public Tensor fill_(int x)
      Fills this tensor with the specified value.
      Parameters:
      x - the value.
      Returns:
      this tensor.
    • fill_

      public Tensor fill_(double x)
      Fills this tensor with the specified value.
      Parameters:
      x - the value.
      Returns:
      this tensor.
    • bernoulli_

      public Tensor bernoulli_(double p)
      Draws binary random numbers (0 or 1) from a Bernoulli distribution.
      Parameters:
      p - Bernoulli probability.
      Returns:
      this tensor.
    • permute

      public Tensor permute(long... dims)
      Returns a view of the original tensor input with its dimensions permuted.
      Parameters:
      dims - The desired ordering of dimensions.
      Returns:
      the permuted tensor.
    • put

      public Tensor put(Tensor source, Index... indices)
      Updates a portion of tensor.
      Parameters:
      source - the new sub-tensor values.
      indices - the indices along the dimensions.
      Returns:
      the output tensor.
    • put

      public Tensor put(Tensor source, Tensor index)
      Updates a portion of tensor.
      Parameters:
      source - the new sub-tensor value.
      index - the sub-tensor index.
      Returns:
      the output tensor.
    • put_

      public Tensor put_(Tensor source, Index... indices)
      Updates a portion of tensor in place.
      Parameters:
      source - the new sub-tensor values.
      indices - the indices along the dimensions.
      Returns:
      this tensor.
    • put_

      public Tensor put_(Tensor source, Tensor index)
      Updates a portion of tensor in place.
      Parameters:
      source - the new sub-tensor value.
      index - the sub-tensor index.
      Returns:
      this tensor.
    • put_

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

      public Tensor put_(byte x, long... indices)
      Updates an element in place.
      Parameters:
      x - the new element value.
      indices - the element indices.
      Returns:
      this tensor.
    • put_

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

      public Tensor put_(short x, long... indices)
      Updates an element in place.
      Parameters:
      x - the new element value.
      indices - the element indices.
      Returns:
      this tensor.
    • put_

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

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

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

      public Tensor put_(long x, long... indices)
      Updates an element in place.
      Parameters:
      x - the new element value.
      indices - the element indices.
      Returns:
      this tensor.
    • put_

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

      public Tensor put_(float x, long... indices)
      Updates an element in place.
      Parameters:
      x - the new element value.
      indices - the element indices.
      Returns:
      this tensor.
    • put_

      public Tensor put_(double x, int... indices)
      Updates an element in place.
      Parameters:
      x - the new element value.
      indices - the element indices.
      Returns:
      this tensor.
    • put_

      public Tensor put_(double x, long... indices)
      Updates an element in place.
      Parameters:
      x - the new element value.
      indices - the element indices.
      Returns:
      this tensor.
    • get

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

      public Tensor get(long... indices)
      Returns a portion of tensor given the indices.
      Parameters:
      indices - the indices along the dimensions.
      Returns:
      the sub-tensor.
    • get

      public Tensor get(Index... indices)
      Returns a portion of tensor given the indices.
      Parameters:
      indices - the indices along the dimensions.
      Returns:
      the sub-tensor.
    • get

      public Tensor get(Tensor index)
      Returns a portion of tensor given the indices.
      Parameters:
      index - the tensor index.
      Returns:
      the sub-tensor.
    • getByte

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

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

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

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

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

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

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

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

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

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

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

      public double getDouble(long... indices)
      Returns the double value of element at given index.
      Parameters:
      indices - the indices along the dimensions.
      Returns:
      the element value.
    • boolValue

      public boolean boolValue()
      Returns the boolean value when the tensor holds a single value.
      Returns:
      the boolean value when the tensor holds a single value.
    • byteValue

      public byte byteValue()
      Returns the byte value when the tensor holds a single value.
      Returns:
      the byte value when the tensor holds a single value.
    • shortValue

      public short shortValue()
      Returns the short value when the tensor holds a single value.
      Returns:
      the short value when the tensor holds a single value.
    • intValue

      public int intValue()
      Returns the int value when the tensor holds a single value.
      Returns:
      the int value when the tensor holds a single value.
    • longValue

      public long longValue()
      Returns the long value when the tensor holds a single value.
      Returns:
      the long value when the tensor holds a single value.
    • floatValue

      public float floatValue()
      Returns the float value when the tensor holds a single value.
      Returns:
      the float value when the tensor holds a single value.
    • doubleValue

      public double doubleValue()
      Returns the double value when the tensor holds a single value.
      Returns:
      the double value when the tensor holds a single value.
    • byteArray

      public byte[] byteArray()
      Returns the byte array of tensor elements
      Returns:
      the byte array of tensor elements.
    • shortArray

      public short[] shortArray()
      Returns the short integer array of tensor elements
      Returns:
      the short integer array of tensor elements.
    • intArray

      public int[] intArray()
      Returns the integer array of tensor elements
      Returns:
      the integer array of tensor elements.
    • longArray

      public long[] longArray()
      Returns the long integer array of tensor elements
      Returns:
      the long integer array of tensor elements.
    • floatArray

      public float[] floatArray()
      Returns the float array of tensor elements
      Returns:
      the float array of tensor elements.
    • doubleArray

      public double[] doubleArray()
      Returns the double array of tensor elements
      Returns:
      the double array of tensor elements.
    • unsqueeze

      public Tensor unsqueeze(long dim)
      Returns a new tensor with a dimension of size one inserted at the specified position.

      The returned tensor shares the same underlying data with this tensor.

      A dim value within the range [-input.dim() - 1, input.dim() + 1) can be used. Negative dim will correspond to unsqueeze() applied at dim = dim + input.dim() + 1.

      Parameters:
      dim - the index at which to insert the singleton dimension.
      Returns:
      the output tensor.
    • transpose

      public Tensor transpose(long dim0, long dim1)
      Returns a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped.

      If input is a strided tensor then the resulting out tensor shares its underlying storage with the input tensor, so changing the content of one would change the content of the other.

      If input is a sparse tensor then the resulting out tensor does not share the underlying storage with the input tensor.

      If input is a sparse tensor with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments dim0 and dim1 must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions.

      Parameters:
      dim0 - the first dimension to be transposed.
      dim1 - the second dimension to be transposed.
      Returns:
      the output tensor.
    • triu

      public Tensor triu(long diagonal)
      Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.
      Parameters:
      diagonal - The parameter diagonal controls which diagonal to consider. If diagonal = 0, all elements on and above the main diagonal are retained. A positive value excludes just as many diagonals above the main diagonal, and similarly a negative value includes just as many diagonals below the main diagonal.
      Returns:
      the output tensor.
    • triu_

      public Tensor triu_(long diagonal)
      Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.
      Parameters:
      diagonal - The parameter diagonal controls which diagonal to consider. If diagonal = 0, all elements on and above the main diagonal are retained. A positive value excludes just as many diagonals above the main diagonal, and similarly a negative value includes just as many diagonals below the main diagonal.
      Returns:
      this tensor.
    • view

      public Tensor view(long... shape)
      Returns a view tensor that shares the same underlying data with this base tensor. Supporting View avoids explicit data copy, thus allows us to do fast and memory efficient reshaping, slicing and element-wise operations.
      Parameters:
      shape - the shape of view tensor.
      Returns:
      the view tensor.
    • viewAsComplex

      public Tensor viewAsComplex()
      Returns a view of tensor as a complex tensor.
      Returns:
      the complex tensor view.
    • viewAsReal

      public Tensor viewAsReal()
      Returns a view of tensor as a real tensor.
      Returns:
      the real tensor view.
    • argmax

      public Tensor argmax(int dim, boolean keepDim)
      Returns the indices of the maximum value of a tensor across a dimension.
      Parameters:
      dim - the dimension to reduce.
      keepDim - whether the output tensor has dim retained or not.
      Returns:
      the indices of the maximum value of a tensor across a dimension.
    • topk

      public Tuple2<Tensor,Tensor> topk(int k)
      Returns the k largest elements.
      Parameters:
      k - the number of largest elements.
      Returns:
      the values and indices of the largest k elements.
    • topk

      public Tuple2<Tensor,Tensor> topk(int k, int dim, boolean largest, boolean sorted)
      Returns the k largest elements along a given dimension.
      Parameters:
      k - the number of largest elements.
      dim - the dimension to sort along.
      largest - controls whether to return largest or smallest elements.
      sorted - controls whether to return the elements in sorted order.
      Returns:
      the values and indices of the largest k elements.
    • topp

      public Tensor topp(double p)
      Performs top-p (nucleus) sampling on a probability distribution. Top-p sampling selects the smallest set of tokens whose cumulative probability mass exceeds the threshold p. The distribution is renormalized based on the selected tokens.
      Parameters:
      p - Probability threshold for top-p sampling.
      Returns:
      Sampled token indices.
    • hstack

      public static Tensor hstack(Tensor... tensors)
      Stacks tensors in sequence horizontally (column wise).
      Parameters:
      tensors - the tensors to concatenate.
      Returns:
      the output tensor.
    • vstack

      public static Tensor vstack(Tensor... tensors)
      Stacks tensors in sequence vertically (row wise).
      Parameters:
      tensors - the tensors to concatenate.
      Returns:
      the output tensor.
    • polar

      public static Tensor polar(Tensor abs, Tensor angle)
      Returns a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with abs and angle.
      Parameters:
      abs - The absolute value the complex tensor. Must be float or double.
      angle - The angle of the complex tensor. Must be same dtype as abs.
      Returns:
      the complex tensor.
    • crossEntropy

      public static Tensor crossEntropy(Tensor input, Tensor target, String reduction, long ignoreIndex)
      Computes the cross entropy loss between input logits and target.
      Parameters:
      input - Predicted unnormalized logits.
      target - Ground truth class indices or class probabilities.
      reduction - Specifies the reduction to apply to the output: "none" | "mean" | "sum". "none": no reduction will be applied, "mean": the sum of the output will be divided by the number of elements in the output, "sum": the output will be summed.
      ignoreIndex - Specifies a target value that is ignored and does not contribute to the input gradient. Note that ignoreIndex is only applicable when the target contains class indices.
      Returns:
      the cross entropy loss between input logits and target.
    • where

      public static Tensor where(Tensor condition, Tensor input, Tensor other)
      Returns a tensor of elements selected from either input or other, depending on condition.
      Parameters:
      condition - a boolean tensor. When true (nonzero), yield input, otherwise yield other.
      input - value selected at indices where condition is true.
      other - value selected at indices where condition is false.
      Returns:
      the output tensor.
    • where

      public static Tensor where(Tensor condition, int input, int other)
      Returns a tensor of elements selected from either input or other, depending on condition.
      Parameters:
      condition - a boolean tensor. When true (nonzero), yield input, otherwise yield other.
      input - value selected at indices where condition is true.
      other - value selected at indices where condition is false.
      Returns:
      the output tensor.
    • where

      public static Tensor where(Tensor condition, double input, double other)
      Returns a tensor of elements selected from either input or other, depending on condition.
      Parameters:
      condition - a boolean tensor. When true (nonzero), yield input, otherwise yield other.
      input - value selected at indices where condition is true.
      other - value selected at indices where condition is false.
      Returns:
      the output tensor.
    • matmul

      public Tensor matmul(Tensor other)
      Returns the matrix product of two tensors.
      Parameters:
      other - another tensor.
      Returns:
      the matrix product of two tensors.
    • outer

      public Tensor outer(Tensor other)
      Returns the outer product of two tensors.
      Parameters:
      other - another tensor.
      Returns:
      the outer product of two tensors.
    • eq

      public Tensor eq(int other)
      Computes element-wise equality.
      Parameters:
      other - the sclar to compare.
      Returns:
      the output tensor.
    • eq

      public Tensor eq(double other)
      Computes element-wise equality.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • eq

      public Tensor eq(Tensor other)
      Computes element-wise equality.
      Parameters:
      other - the tensor to compare.
      Returns:
      the output tensor.
    • ne

      public Tensor ne(int other)
      Computes element-wise inequality.
      Parameters:
      other - the sclar to compare.
      Returns:
      the output tensor.
    • ne

      public Tensor ne(double other)
      Computes element-wise inequality.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • ne

      public Tensor ne(Tensor other)
      Computes element-wise inequality.
      Parameters:
      other - the tensor to compare.
      Returns:
      the output tensor.
    • lt

      public Tensor lt(double other)
      Computes element-wise less-than comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • lt

      public Tensor lt(int other)
      Computes element-wise less-than comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • lt

      public Tensor lt(Tensor other)
      Computes element-wise less-than comparison.
      Parameters:
      other - the tensor to compare.
      Returns:
      the output tensor.
    • le

      public Tensor le(int other)
      Computes element-wise less-than-or-equal-to comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • le

      public Tensor le(double other)
      Computes element-wise less-than-or-equal-to comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • le

      public Tensor le(Tensor other)
      Computes element-wise less-than-or-equal-to comparison.
      Parameters:
      other - the tensor to compare.
      Returns:
      the output tensor.
    • gt

      public Tensor gt(int other)
      Computes element-wise greater-than comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • gt

      public Tensor gt(double other)
      Computes element-wise greater-than comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • gt

      public Tensor gt(Tensor other)
      Computes element-wise greater-than comparison.
      Parameters:
      other - the tensor to compare.
      Returns:
      the output tensor.
    • ge

      public Tensor ge(int other)
      Computes element-wise greater-than-or-equal-to comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • ge

      public Tensor ge(double other)
      Computes element-wise greater-than-or-equal-to comparison.
      Parameters:
      other - the scalar to compare.
      Returns:
      the output tensor.
    • ge

      public Tensor ge(Tensor other)
      Computes element-wise greater-than-or-equal-to comparison.
      Parameters:
      other - the tensor to compare.
      Returns:
      the output tensor.
    • sum

      public Tensor sum()
      Returns the sum of all elements in the tensor.
      Returns:
      the sum of all elements.
    • mean

      public Tensor mean()
      Returns the mean of all elements in the tensor.
      Returns:
      the mean of all elements.
    • mean

      public Tensor mean(int dim, boolean keepDim)
      Returns the mean along a dimension in the tensor.
      Parameters:
      dim - the dimension to reduce.
      keepDim - whether the output tensor has dim retained or not.
      Returns:
      the output tensor.
    • rsqrt

      public Tensor rsqrt()
      Returns the reciprocal of the square-root of each of the elements in the tensor.
      Returns:
      the output tensor.
    • rsqrt_

      public Tensor rsqrt_()
      Returns the reciprocal of the square-root of each of the elements in the tensor.
      Returns:
      this tensor.
    • exp

      public Tensor exp()
      Returns the exponential of elements in the tensor.
      Returns:
      the output tensor.
    • exp_

      public Tensor exp_()
      Returns the exponential of elements in the tensor in place.
      Returns:
      this tensor.
    • scatterReduce

      public Tensor scatterReduce(int dim, Tensor index, Tensor source, String reduce)
      Writes all values from the tensor src into this tensor at the indices specified in the index tensor. For each value in src, its output index is specified by its index in src for dimension != dim and by the corresponding value in index for dimension = dim.

      This is the reverse operation of the manner described in gather().

      Parameters:
      dim - the axis along which to index.
      index - the indices of elements to scatter, can be either empty or of the same dimensionality as src. When empty, the operation returns self unchanged.
      source - the source elements to scatter and reduce.
      reduce - the reduction operation to apply for non-unique indices ("sum", "prod", "mean", "amax", or "amin").
      Returns:
      the output tensor.
    • scatterReduce_

      public Tensor scatterReduce_(int dim, Tensor index, Tensor source, String reduce)
      Writes all values from the tensor src into this tensor at the indices specified in the index tensor. For each value in src, its output index is specified by its index in src for dimension != dim and by the corresponding value in index for dimension = dim.

      This is the reverse operation of the manner described in gather().

      Parameters:
      dim - the axis along which to index.
      index - the indices of elements to scatter, can be either empty or of the same dimensionality as src. When empty, the operation returns self unchanged.
      source - the source elements to scatter and reduce.
      reduce - the reduction operation to apply for non-unique indices ("sum", "prod", "mean", "amax", or "amin").
      Returns:
      this tensor.
    • gather

      public Tensor gather(int dim, Tensor index)
      Gathers values along an axis specified by dim.
      Parameters:
      dim - the axis along which to index.
      index - the indices of elements to gather.
      Returns:
      the output tensor.
    • add

      public Tensor add(float other)
      Returns A + b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • add_

      public Tensor add_(float other)
      Returns A += b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • add

      public Tensor add(double other)
      Returns A + b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • add_

      public Tensor add_(double other)
      Returns A += b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • add

      public Tensor add(Tensor other)
      Returns A + B.
      Parameters:
      other - another tensor.
      Returns:
      the output tensor.
    • add_

      public Tensor add_(Tensor other)
      Returns A += B.
      Parameters:
      other - another tensor.
      Returns:
      this tensor.
    • add

      public Tensor add(Tensor other, double alpha)
      Returns A + alpha * B.
      Parameters:
      other - another tensor.
      alpha - the scaling factor.
      Returns:
      the output tensor.
    • add_

      public Tensor add_(Tensor other, double alpha)
      Returns A += alpha * B.
      Parameters:
      other - another tensor.
      alpha - the scaling factor.
      Returns:
      this tensor.
    • sub

      public Tensor sub(float other)
      Returns A - b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • sub_

      public Tensor sub_(float other)
      Returns A - b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • sub

      public Tensor sub(double other)
      Returns A -= b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • sub_

      public Tensor sub_(double other)
      Returns A -= b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • sub

      public Tensor sub(Tensor other)
      Returns A - B.
      Parameters:
      other - another tensor.
      Returns:
      the output tensor.
    • sub_

      public Tensor sub_(Tensor other)
      Returns A -= B.
      Parameters:
      other - another tensor.
      Returns:
      this tensor.
    • sub

      public Tensor sub(Tensor other, double alpha)
      Returns A - alpha * B.
      Parameters:
      other - another tensor.
      alpha - the scaling factor.
      Returns:
      the output tensor.
    • sub_

      public Tensor sub_(Tensor other, double alpha)
      Returns A -= alpha * B.
      Parameters:
      other - another tensor.
      alpha - the scaling factor.
      Returns:
      this tensor.
    • mul

      public Tensor mul(float other)
      Returns A * b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • mul_

      public Tensor mul_(float other)
      Returns A *= b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • mul

      public Tensor mul(double other)
      Returns A * b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • mul_

      public Tensor mul_(double other)
      Returns A *= b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • mul

      public Tensor mul(Tensor other)
      Returns A * B element wisely.
      Parameters:
      other - another tensor.
      Returns:
      the output tensor.
    • mul_

      public Tensor mul_(Tensor other)
      Returns A *= B element wisely.
      Parameters:
      other - another tensor.
      Returns:
      this tensor.
    • div

      public Tensor div(float other)
      Returns A / b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • div_

      public Tensor div_(float other)
      Returns A /= b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • div

      public Tensor div(double other)
      Returns A / b.
      Parameters:
      other - a scalar value.
      Returns:
      the output tensor.
    • div_

      public Tensor div_(double other)
      Returns A /= b.
      Parameters:
      other - a scalar value.
      Returns:
      this tensor.
    • div

      public Tensor div(Tensor other)
      Returns A / B element wisely.
      Parameters:
      other - another tensor.
      Returns:
      the output tensor.
    • div_

      public Tensor div_(Tensor other)
      Returns A /= B element wisely.
      Parameters:
      other - another tensor.
      Returns:
      this tensor.
    • pow

      public Tensor pow(double exponent)
      Returns a new tensor with the power of the elements of input.
      Parameters:
      exponent - the exponent value.
      Returns:
      a new tensor with the power of the elements of input.
    • pow_

      public Tensor pow_(double exponent)
      Computes the power of the elements of input in place.
      Parameters:
      exponent - the exponent value.
      Returns:
      this tensor.
    • cos

      public Tensor cos()
      Returns a new tensor with the cosine of the elements of input.
      Returns:
      a new tensor with the cosine of the elements of input.
    • cos_

      public Tensor cos_()
      Computes the cosine of the elements of input in place.
      Returns:
      this tensor.
    • sin

      public Tensor sin()
      Returns a new tensor with the sine of the elements of input.
      Returns:
      a new tensor with the sine of the elements of input.
    • sin_

      public Tensor sin_()
      Computes the sine of the elements of input in place.
      Returns:
      this tensor.
    • acos

      public Tensor acos()
      Returns a new tensor with the arccosine of the elements of input.
      Returns:
      a new tensor with the arccosine of the elements of input.
    • acos_

      public Tensor acos_()
      Computes the arccosine of the elements of input in place.
      Returns:
      this tensor.
    • asin

      public Tensor asin()
      Returns a new tensor with the arcsine of the elements of input.
      Returns:
      a new tensor with the arcsine of the elements of input.
    • asin_

      public Tensor asin_()
      Computes the arcsine of the elements of input in place.
      Returns:
      this tensor.
    • isin

      public Tensor isin(Tensor other)
      Tests if each element of this tensor is in other tensor. Returns a boolean tensor of the same shape.
      Parameters:
      other - another tensor.
      Returns:
      a boolean tensor.
    • all

      public boolean all()
      Tests if all elements in the tensor are true.
      Returns:
      the output tensor.
    • not

      public Tensor not()
      Returns logical NOT of this tensor.
      Returns:
      a new tensor of logical not results.
    • not_

      public Tensor not_()
      Returns logical NOT of this tensor.
      Returns:
      a new tensor of logical not results.
    • and

      public Tensor and(Tensor other)
      Returns logical AND of two boolean tensors.
      Parameters:
      other - another tensor.
      Returns:
      a new tensor of logical and results.
    • and_

      public Tensor and_(Tensor other)
      Returns logical AND of two boolean tensors.
      Parameters:
      other - another tensor.
      Returns:
      this tensor.
    • or

      public Tensor or(Tensor other)
      Returns logical OR of two boolean tensors.
      Parameters:
      other - another tensor.
      Returns:
      a new tensor of logical and results.
    • or_

      public Tensor or_(Tensor other)
      Returns logical OR of two boolean tensors.
      Parameters:
      other - another tensor.
      Returns:
      this tensor.
    • softmax

      public Tensor softmax(int dim)
      Rescales a tensor so that the elements lie in the range [0,1] and sum to 1.
      Parameters:
      dim - the dimension along which softmax will be computed.
      Returns:
      this tensor.
    • dropout

      public Tensor dropout(double p)
      Randomly zeroes some elements of the input tensor with probability p.
      Parameters:
      p - the probability of an element to be zeroed.
      Returns:
      a new tensor after random dropouts.
    • dropout_

      public Tensor dropout_(double p)
      Randomly zeroes some elements in place with probability p.
      Parameters:
      p - the probability of an element to be zeroed.
      Returns:
      this tensor.
    • newZeros

      public Tensor newZeros(long... shape)
      Returns a tensor filled with all zeros. The returned Tensor has the data type and device as this tensor.
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • newOnes

      public Tensor newOnes(long... shape)
      Returns a tensor filled with all ones. The returned Tensor has the data type and device as this tensor.
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • eye

      public static Tensor eye(long shape)
      Returns an identity matrix.
      Parameters:
      shape - the dimension of the resulting matrix.
      Returns:
      the created tensor.
    • eye

      public static Tensor eye(Tensor.Options options, long shape)
      Returns an identity matrix.
      Parameters:
      options - Tensor creation options.
      shape - the dimension of the resulting matrix.
      Returns:
      the created tensor.
    • full

      public static Tensor full(long value, long... shape)
      Returns a tensor filled with the given value.
      Parameters:
      value - the value to fill the output tensor with.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • full

      public static Tensor full(double value, long... shape)
      Returns a tensor filled with the given value.
      Parameters:
      value - the value to fill the output tensor with.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • empty

      public static Tensor empty(long... shape)
      Returns a tensor with uninitialized data.
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • empty

      public static Tensor empty(Tensor.Options options, long... shape)
      Returns a tensor with uninitialized data.
      Parameters:
      options - Tensor creation options.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • zeros

      public static Tensor zeros(long... shape)
      Returns a tensor filled with all zeros.
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • zeros

      public static Tensor zeros(Tensor.Options options, long... shape)
      Returns a tensor filled with all zeros.
      Parameters:
      options - Tensor creation options.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • ones

      public static Tensor ones(long... shape)
      Returns a tensor filled with all ones.
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • ones

      public static Tensor ones(Tensor.Options options, long... shape)
      Returns a tensor filled with all ones.
      Parameters:
      options - Tensor creation options.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • rand

      public static Tensor rand(long... shape)
      Returns a tensor filled with values drawn from a uniform distribution on [0, 1).
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • rand

      public static Tensor rand(Tensor.Options options, long... shape)
      Returns a tensor filled with values drawn from a uniform distribution on [0, 1).
      Parameters:
      options - Tensor creation options.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • randn

      public static Tensor randn(long... shape)
      Returns a tensor filled with values drawn from a unit normal distribution.
      Parameters:
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • randn

      public static Tensor randn(Tensor.Options options, long... shape)
      Returns a tensor filled with values drawn from a unit normal distribution.
      Parameters:
      options - Tensor creation options.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • arange

      public static Tensor arange(long start, long end, long step)
      Returns a 1-D tensor of size (end - start) / step with values from the interval [start, end) taken with common difference step beginning from start.
      Parameters:
      start - the starting value for the set of points.
      end - the ending value for the set of points.
      step - the gap between each pair of adjacent points.
      Returns:
      a 1-D tensor.
    • of

      public static Tensor of(boolean[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • of

      public static Tensor of(byte[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • of

      public static Tensor of(short[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • of

      public static Tensor of(int[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • of

      public static Tensor of(long[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • of

      public static Tensor of(float[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.
    • of

      public static Tensor of(double[] data, long... shape)
      Returns a tensor with given data and shape.
      Parameters:
      data - the initialization data.
      shape - the dimensional shape of the resulting tensor.
      Returns:
      the created tensor.