Class Tensor

java.lang.Object
ai.beestream.jitnn.Tensor
All Implemented Interfaces:
AutoCloseable

public final class Tensor extends Object implements AutoCloseable
An n-dimensional array. Operations are lazy on TornadoVM: they are recorded and run at the next sync point (item(), toFloatArray(), Engine.sync(Tensor...)). Tensors are always contiguous and row-major; reshape(int...) shares storage, permute(int...) copies.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    |x|, element-wise.
    Element-wise arccosine.
    Element-wise inverse hyperbolic cosine.
    add(float c)
    this + c.
    this + o, element-wise with broadcasting.
    static Tensor
    alias(Tensor base, Shape shape)
    A tensor that shares base's storage under another shape.
    static Tensor
    arange(float start, float end, float step)
    start, start + step, ... below end (above end for a negative step): torch.arange, ONNX Range.
    argmax(int axis)
    Index of the maximum along axis, as an INT32 tensor (no gradient).
    argmin(int axis)
    INT32 index of the first minimum along axis.
    argsort(int axis, boolean descending)
    INT32 indices that sort along axis (stable).
    Element-wise arcsine.
    Element-wise inverse hyperbolic sine.
    void
    Records a copy of src into this persistent FP32 tensor of the same size (a running statistic, an optimiser buffer): later operators see the new values.
    Element-wise arctangent.
    atan2(this, o), the angle of the point (o, this), with broadcasting.
    Element-wise inverse hyperbolic tangent.
    void
    Back-propagates from this scalar.
    void
    backward(Tensor gradient)
    Back-propagates from this tensor with gradient (its shape) as the gradient of the result.
    This tensor converted to BF16 (to(DType.BF16)).
    Bitwise and of INT32 tensors, with broadcasting.
    Bitwise complement of an INT32 tensor.
    Bitwise or of INT32 tensors, with broadcasting.
    Bitwise exclusive or of INT32 tensors, with broadcasting.
    static Tensor
    cat(int axis, Tensor... parts)
    Joins tensors along an existing axis.
    Element-wise ceiling.
    celu(float alpha)
    CELU: max(0, x) + min(0, alpha (exp(x / alpha) - 1)).
    chunk(int chunks, int axis)
    Splits axis into chunks equal pieces.
    clamp(float lo, float hi)
    x clamped to [lo, hi].
    void
    release(), for try-with-resources.
    void
    copyFrom(float[] values)
    Overwrites a persistent tensor's contents from the host (e.g. loading weights).
    cos()
    Element-wise cosine.
    Element-wise hyperbolic cosine.
    x^3 (DL4J's Cube activation).
    cumprod(int axis)
    Inclusive cumulative product along axis; its gradient is exact with zeros.
    cumsum(int axis)
    Inclusive cumulative sum along axis.
    The same data without gradient history.
    int
    dim(int axis)
    The size of axis axis; a negative axis counts from the end.
    this / o, element-wise with broadcasting.
    The element type of this tensor.
    elu(float alpha)
    ELU: x for x > 0, else alpha (exp(x) - 1).
    1 where this == o, else 0, with broadcasting.
    erf()
    Element-wise error function.
    Element-wise complementary error function.
    exp()
    e^x, element-wise.
    expand(Shape target)
    Broadcast copy to target shape.
    Element-wise exp(x) - 1, accurate near 0.
    static Tensor
    eye(int n, int m, int k)
    The n x m matrix with ones on diagonal k (0 main, positive above, negative below), zeros elsewhere.
    static Tensor
    eyeLike(Tensor like, int k)
    eye(int, int, int) with the shape of the rank-2 tensor like (ONNX EyeLike).
    Element-wise floor.
    Element-wise maximum ignoring a NaN operand (torch.fmax).
    Element-wise minimum ignoring a NaN operand (torch.fmin).
    this - trunc(this / o) o, with broadcasting: the remainder with the sign of the dividend (torch.fmod).
    static Tensor
    full(float value, int... dims)
    An FP32 tensor of the given shape with every element value.
    gather(int axis, Tensor index)
    torch.gather along axis with an INT32 index of this shape except along the axis.
    1 where this >= o, else 0, with broadcasting.
    GELU, exact form x * Phi(x) (PyTorch's default, approximate='none').
    GELU with the tanh approximation (GPT-2's form, PyTorch's approximate='tanh').
    The accumulated gradient of a leaf tensor after backward(), or null.
    1 where this > o, else 0, with broadcasting.
    This tensor converted to FP16 (to(DType.F16)).
    HardSigmoid, PyTorch's form: clamp(x / 6 + 1/2, 0, 1).
    HardSwish: x hardSigmoid(x).
    hardTanh(float lo, float hi)
    HardTanh: x clamped to [lo, hi] (PyTorch's default -1, 1).
    indexSelect(int axis, Tensor idx)
    Elements idx[0 .. m-1] (INT32 [m]) of axis, torch.index_select.
    1 where finite, else 0.
    1 where +inf or -inf, else 0.
    boolean
    True unless the tensor is the output of an operator that tracks gradients (it is a leaf of autograd).
    1 where NaN, else 0 (tested by bit pattern).
    boolean
    True for persistent device storage: weights (persistent(Tensor), parameter(Tensor)) and their views.
    float
    The value of a single-element tensor, as a float.
    1 where this <= o, else 0, with broadcasting.
    leakyRelu(float slope)
    LeakyReLU: x for x > 0, else slope * x (PyTorch's default slope is 0.01).
    log()
    The natural logarithm, element-wise.
    Element-wise log(1 + x), accurate near 0.
    1 where both are non-zero, with broadcasting.
    Element-wise logical not: 1 where x is 0, else 0.
    1 where either is non-zero, with broadcasting.
    1 where exactly one is non-zero, with broadcasting.
    Log-softmax along the last axis.
    1 where this < o, else 0, with broadcasting.
    The elements where mask (broadcast) is not zero, as a vector (torch.masked_select); reads the count back to the host.
    The matrix product this b: [M, K] x [K, N] to [M, N], or batched over leading axes, which must match unless one side is a plain matrix shared by every batch.
    matmul(Tensor b, boolean transposeThis, boolean transposeB)
    op(this) * op(b), where op transposes when the flag is set, without materialising the transpose.
    max(int axis, boolean keepDim)
    The maximum along axis, which is kept with size 1 when keepDim is set; argmax(int) gives its index.
    The element-wise maximum of this and o, with broadcasting (maximumNaN(Tensor) propagates NaN).
    Element-wise maximum propagating NaN (torch.maximum).
    The mean of all elements, as a scalar.
    mean(int axis, boolean keepDim)
    The mean along axis, which is kept with size 1 when keepDim is set.
    min(int axis, boolean keepDim)
    The minimum along axis, which is kept with size 1 when keepDim is set; argmin(int) gives its index.
    The element-wise minimum of this and o, with broadcasting (minimumNaN(Tensor) propagates NaN).
    Element-wise minimum propagating NaN (torch.minimum).
    Mish: x tanh(softplus(x)).
    mul(float c)
    this * c.
    this * o, element-wise with broadcasting.
    nanToNum(float nan, float posInf)
    NaN to nan, +inf to posInf and -inf to -posInf (torch.nan_to_num with a symmetric infinity).
    narrow(int axis, int start, int length)
    Elements start .. start + length - 1 along axis, as a new tensor.
    1 where this !
    neg()
    -this.
    INT32 coordinates [count, rank] of the non-zero elements (torch.nonzero); reads the count back to the host.
    norm(int p, int axis, boolean keepDim)
    The p-norm (p = 1 or 2) along axis: sum |x| or sqrt(sum x^2).
    static Tensor
    normal(long seed, float mean, float std, int... dims)
    Normal with the given mean and standard deviation, counter-based like uniform(long, float, float, int...).
    static Tensor
    normal(Tensor seed, float mean, float std, int... dims)
    As normal(long, float, float, int...) with the seed in an INT32 [2] tensor.
    int
    The number of elements (1 for a scalar).
    static Tensor
    of(float[] data, int... dims)
    An FP32 tensor with a copy of data in the shape dims (a vector of all the values when no dims are given).
    static Tensor
    of(int[] data, int... dims)
    An INT32 tensor (labels, indices) with a copy of data; of(float[], int...) for int data.
    static Tensor
    of(uk.ac.manchester.tornado.api.types.arrays.HalfFloatArray data, int... dims)
    An FP16 input over data, held without a copy (an FP16 image batch for half-precision inference, say): plans read it as they read any host input.
    static Tensor
    ones(int... dims)
    An FP32 tensor of ones.
    void
    Calls hook with this leaf tensor (a parameter) during each backward pass, as soon as its gradient is final: after the last operator that contributes to it, while the rest of the backward pass is still being recorded.
    static Tensor
    A trainable parameter: persistent storage (it stays on the device across steps), gradient tracking on, initialised with the values of init.
    permute(int... order)
    The axes reordered: axis i of the result is axis order[i] of this tensor.
    static Tensor
    Persistent storage without gradient tracking (optimiser state, running statistics).
    static Tensor
    persistent(uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray array, DType dtype, int... dims)
    A persistent tensor (a weight that stays on the device) over an existing native array, without copying it: for example an array that wraps a memory-mapped file.
    static Tensor
    persistentHalf(float[] values, int... dims)
    Persistent FP16 storage (weights kept in half precision on the device), from FP32 values rounded to nearest.
    pow(float exponent)
    x^exponent, element-wise.
    pow(Tensor exponent)
    x^exponent, element-wise, with broadcasting.
    Product of all elements.
    prod(int axis, boolean keepDim)
    Product along axis.
    static Tensor
    quantized(DType type, byte[] blocks, int... dims)
    A weight in one of GGUF's block-quantised formats (Q8_0, Q4_0, Q4_1, Q4_K, Q5_K, Q6_K, Q5_0, Q5_1, Q2_K, Q3_K) from its raw blocks, as a GGUF file stores them: persistent, so it stays on the device.
    int
    The number of axes (0 for a scalar).
    1 / x, element-wise.
    static void
    record(ai.beestream.jitnn.engine.Op op, Tensor[] inputs, Tensor[] outputs, int[] iattr, float[] fattr, boolean traced)
    Records an operator application.
    void
    Declares the tensor no longer used; using it, or a view of it, afterwards is an error.
    max(x, 0), element-wise.
    min(max(x, 0), 6).
    this - floor(this / o) o, with broadcasting: the remainder with the sign of the divisor (torch.remainder).
    boolean
    Whether gradients are tracked for this tensor.
    requiresGrad(boolean on)
    Turns gradient tracking on or off for a leaf tensor.
    reshape(int... dims)
    Same data, new shape; one dimension may be -1.
    static Tensor
    result(Shape shape, DType dtype)
    An output tensor for an operator; its storage is allocated when the operator runs.
    Element-wise rounding to the nearest integer, halves to even (PyTorch's round).
    static Tensor
    scalar(float value)
    A rank-0 FP32 tensor holding value.
    scatter(int axis, Tensor index, Tensor src)
    torch.scatter: this with src written at index (duplicates: the last wins); no gradient.
    scatterAdd(int axis, Tensor index, Tensor src)
    torch.scatter_add: this with src added at index along axis.
    static Tensor
    seed(long seed)
    A 64-bit seed as the INT32 [2] host tensor [lo, hi] that the seeded random operators take.
    SELU with PyTorch's constants (alpha 1.6732632, scale 1.0507010).
    void
    Replaces the gradient of this leaf tensor (same shape), for example by its average over data-parallel ranks before the optimiser step.
    The shape of this tensor.
    this << o for INT32 tensors, with broadcasting.
    this >> o (arithmetic: the sign is kept) for INT32 tensors, with broadcasting.
    The logistic sigmoid 1 / (1 + exp(-x)), element-wise.
    Element-wise sign: -1, 0 or 1.
    SiLU (swish): x * sigmoid(x).
    sin()
    Element-wise sine.
    Element-wise hyperbolic sine.
    slice(int axis, int start, int end)
    Elements start .. end - 1 along axis; negative indices count from the end.
    Softmax along the last axis.
    Softplus, log(1 + exp(x)) (beta 1), computed without overflow.
    Softsign: x / (1 + |x|).
    sort(int axis, boolean descending)
    Stable sort along axis: {values, INT32 original indices}; values carry the gradient.
    split(int axis, int... sizes)
    Splits axis into consecutive pieces of the given sizes.
    The square root, element-wise.
    x^2, element-wise.
    squeeze(int axis)
    A view without the size-1 axis axis.
    static Tensor
    stack(int axis, Tensor... parts)
    Joins same-shape tensors along a new axis.
    ai.beestream.jitnn.engine.Storage
    The memory behind this tensor, shared with its views.
    this - o, element-wise with broadcasting.
    sum()
    The sum of all elements, as a scalar.
    sum(int axis, boolean keepDim)
    The sum along axis, which is kept with size 1 when keepDim is set.
    sumTo(Shape target)
    Sums broadcast dimensions away so the result has target shape (gradient of broadcasting).
    t()
    Transpose of a matrix.
    tan()
    Element-wise tangent.
    The hyperbolic tangent, element-wise.
    thresholdedRelu(float theta)
    ThresholdedReLU (Keras): x where x > theta, else 0.
    tile(int... reps)
    This tensor repeated reps[i] times along each axis (torch.Tensor.repeat, numpy.tile, ONNX Tile); reps longer than the rank adds leading axes.
    to(DType dtype)
    This tensor converted to dtype: between FP32, FP16 and BF16 (round to nearest even; differentiable), or between FP32 and INT32 (truncating toward zero; no gradient).
    This tensor converted to FP32 (to(DType.F32)).
    float[]
    The elements in row-major order, converted to float from any element type (INT32, FP16, BF16, FP8, GGUF blocks).
    float[]
    toFloatArray(float[] dst)
    Copies an F32, F16 or BF16 tensor into dst (length numel()) without allocating: for BERT's [32, 128, 768] output, a fresh float[] costs more than the copy itself.
    int[]
    The elements of an INT32 tensor in row-major order.
    topk(int k)
    The k largest values along the last axis and their INT32 indices (descending; ties: lower index first).
     
    transpose(int a, int b)
    Axes a and b swapped (negative axes count from the end); a copy, as permute(int...).
    Element-wise rounding towards zero.
    static Tensor
    uniform(long seed, float lo, float hi, int... dims)
    Uniform in [lo, hi), from a counter-based generator: the same seed gives the same values everywhere.
    static Tensor
    uniform(Tensor seed, float lo, float hi, int... dims)
    As uniform(long, float, float, int...) with the seed in an INT32 [2] tensor (see seed(long)): a plan replayed with a new seed draws new values without recompiling, so use this for noise drawn every step.
    unsqueeze(int axis)
    A view with a new size-1 axis at axis (negative counts from the end of the result).
    static Tensor
    wrap(float[] data, int... dims)
    A tensor over data itself, without a copy, as PyTorch's from_numpy: the array is read when the operators that use it run (at the next sync), so it must not change until then, and later reads of the tensor see later changes.
    static Tensor
    wrap(int[] data, int... dims)
    wrap(float[], int...) for int data.
    void
    Clears the accumulated gradient of this leaf tensor.
    static Tensor
    zeros(int... dims)
    An FP32 tensor of zeros.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static Tensor of(float[] data, int... dims)
      An FP32 tensor with a copy of data in the shape dims (a vector of all the values when no dims are given). wrap(float[], int...) shares the array instead.
    • wrap

      public static Tensor wrap(float[] data, int... dims)
      A tensor over data itself, without a copy, as PyTorch's from_numpy: the array is read when the operators that use it run (at the next sync), so it must not change until then, and later reads of the tensor see later changes. of(float[], int...) copies instead.
    • of

      public static Tensor of(uk.ac.manchester.tornado.api.types.arrays.HalfFloatArray data, int... dims)
      An FP16 input over data, held without a copy (an FP16 image batch for half-precision inference, say): plans read it as they read any host input.
    • wrap

      public static Tensor wrap(int[] data, int... dims)
      wrap(float[], int...) for int data.
    • of

      public static Tensor of(int[] data, int... dims)
      An INT32 tensor (labels, indices) with a copy of data; of(float[], int...) for int data.
    • scalar

      public static Tensor scalar(float value)
      A rank-0 FP32 tensor holding value.
    • full

      public static Tensor full(float value, int... dims)
      An FP32 tensor of the given shape with every element value.
    • eye

      public static Tensor eye(int n, int m, int k)
      The n x m matrix with ones on diagonal k (0 main, positive above, negative below), zeros elsewhere.
    • eyeLike

      public static Tensor eyeLike(Tensor like, int k)
      eye(int, int, int) with the shape of the rank-2 tensor like (ONNX EyeLike).
    • arange

      public static Tensor arange(float start, float end, float step)
      start, start + step, ... below end (above end for a negative step): torch.arange, ONNX Range.
    • zeros

      public static Tensor zeros(int... dims)
      An FP32 tensor of zeros.
    • ones

      public static Tensor ones(int... dims)
      An FP32 tensor of ones.
    • uniform

      public static Tensor uniform(long seed, float lo, float hi, int... dims)
      Uniform in [lo, hi), from a counter-based generator: the same seed gives the same values everywhere.
    • uniform

      public static Tensor uniform(Tensor seed, float lo, float hi, int... dims)
      As uniform(long, float, float, int...) with the seed in an INT32 [2] tensor (see seed(long)): a plan replayed with a new seed draws new values without recompiling, so use this for noise drawn every step.
    • normal

      public static Tensor normal(Tensor seed, float mean, float std, int... dims)
      As normal(long, float, float, int...) with the seed in an INT32 [2] tensor.
    • seed

      public static Tensor seed(long seed)
      A 64-bit seed as the INT32 [2] host tensor [lo, hi] that the seeded random operators take.
    • normal

      public static Tensor normal(long seed, float mean, float std, int... dims)
      Normal with the given mean and standard deviation, counter-based like uniform(long, float, float, int...).
    • parameter

      public static Tensor parameter(Tensor init)
      A trainable parameter: persistent storage (it stays on the device across steps), gradient tracking on, initialised with the values of init.
    • persistent

      public static Tensor persistent(Tensor init)
      Persistent storage without gradient tracking (optimiser state, running statistics).
    • quantized

      public static Tensor quantized(DType type, byte[] blocks, int... dims)
      A weight in one of GGUF's block-quantised formats (Q8_0, Q4_0, Q4_1, Q4_K, Q5_K, Q6_K, Q5_0, Q5_1, Q2_K, Q3_K) from its raw blocks, as a GGUF file stores them: persistent, so it stays on the device. The last axis must be a multiple of the format's block size.
    • persistent

      public static Tensor persistent(uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray array, DType dtype, int... dims)
      A persistent tensor (a weight that stays on the device) over an existing native array, without copying it: for example an array that wraps a memory-mapped file. The array class must be the one that holds dtype (FloatArray for F32, HalfFloatArray for F16, ShortArray for BF16, IntArray for I32, ByteArray for the GGUF block formats) and its size must match dims; for a block format the last axis must be a multiple of the block size.
    • persistentHalf

      public static Tensor persistentHalf(float[] values, int... dims)
      Persistent FP16 storage (weights kept in half precision on the device), from FP32 values rounded to nearest.
    • result

      public static Tensor result(Shape shape, DType dtype)
      An output tensor for an operator; its storage is allocated when the operator runs.
    • alias

      public static Tensor alias(Tensor base, Shape shape)
      A tensor that shares base's storage under another shape.
    • record

      public static void record(ai.beestream.jitnn.engine.Op op, Tensor[] inputs, Tensor[] outputs, int[] iattr, float[] fattr, boolean traced)
      Records an operator application. Outputs track gradients when gradient mode is on and any input does; the node is traced (run at the next sync) unless traced is false.
    • storage

      public ai.beestream.jitnn.engine.Storage storage()
      The memory behind this tensor, shared with its views. Internal: for jitNN's operators and modules, not part of the API.
    • release

      public void release()
      Declares the tensor no longer used; using it, or a view of it, afterwards is an error.
      • A persistent tensor (a weight), as when its model is closed: compiled plans that use it can then run another model of the same structure without compiling again.
      • Any other tensor, typically an output once read: its contents are dropped. When its plan runs again they need not be copied out of the plan's buffer first, and a host array of its own goes back to a pool for later outputs. Serving loops that read each output and release it (or use try-with-resources) avoid an allocation and a copy per call; without it, the array is recycled only when the tensor is collected.
    • close

      public void close()
      release(), for try-with-resources.
      Specified by:
      close in interface AutoCloseable
    • isLeaf

      public boolean isLeaf()
      True unless the tensor is the output of an operator that tracks gradients (it is a leaf of autograd).
    • isPersistent

      public boolean isPersistent()
      True for persistent device storage: weights (persistent(Tensor), parameter(Tensor)) and their views.
    • assign

      public void assign(Tensor src)
      Records a copy of src into this persistent FP32 tensor of the same size (a running statistic, an optimiser buffer): later operators see the new values.
    • onGradReady

      public void onGradReady(Consumer<Tensor> hook)
      Calls hook with this leaf tensor (a parameter) during each backward pass, as soon as its gradient is final: after the last operator that contributes to it, while the rest of the backward pass is still being recorded. Data-parallel training starts the gradient all-reduce from it (DataParallel.overlapGradients). One hook per tensor; null removes it.
    • setGrad

      public void setGrad(Tensor g)
      Replaces the gradient of this leaf tensor (same shape), for example by its average over data-parallel ranks before the optimiser step.
    • shape

      public Shape shape()
      The shape of this tensor.
    • dtype

      public DType dtype()
      The element type of this tensor.
    • numel

      public int numel()
      The number of elements (1 for a scalar).
    • rank

      public int rank()
      The number of axes (0 for a scalar).
    • dim

      public int dim(int axis)
      The size of axis axis; a negative axis counts from the end.
    • requiresGrad

      public boolean requiresGrad()
      Whether gradients are tracked for this tensor.
    • requiresGrad

      public Tensor requiresGrad(boolean on)
      Turns gradient tracking on or off for a leaf tensor.
    • grad

      public Tensor grad()
      The accumulated gradient of a leaf tensor after backward(), or null.
    • zeroGrad

      public void zeroGrad()
      Clears the accumulated gradient of this leaf tensor.
    • backward

      public void backward()
      Back-propagates from this scalar.
    • backward

      public void backward(Tensor gradient)
      Back-propagates from this tensor with gradient (its shape) as the gradient of the result.
    • detach

      public Tensor detach()
      The same data without gradient history.
    • item

      public float item()
      The value of a single-element tensor, as a float. A sync point: runs every operator recorded so far.
    • toFloatArray

      public float[] toFloatArray()
      The elements in row-major order, converted to float from any element type (INT32, FP16, BF16, FP8, GGUF blocks). A sync point: runs every operator recorded so far.
    • toFloatArray

      public float[] toFloatArray(float[] dst)
      Copies an F32, F16 or BF16 tensor into dst (length numel()) without allocating: for BERT's [32, 128, 768] output, a fresh float[] costs more than the copy itself.
    • toIntArray

      public int[] toIntArray()
      The elements of an INT32 tensor in row-major order. A sync point: runs every operator recorded so far.
    • copyFrom

      public void copyFrom(float[] values)
      Overwrites a persistent tensor's contents from the host (e.g. loading weights).
    • add

      public Tensor add(Tensor o)
      this + o, element-wise with broadcasting.
    • sub

      public Tensor sub(Tensor o)
      this - o, element-wise with broadcasting.
    • mul

      public Tensor mul(Tensor o)
      this * o, element-wise with broadcasting.
    • div

      public Tensor div(Tensor o)
      this / o, element-wise with broadcasting.
    • maximum

      public Tensor maximum(Tensor o)
      The element-wise maximum of this and o, with broadcasting (maximumNaN(Tensor) propagates NaN).
    • minimum

      public Tensor minimum(Tensor o)
      The element-wise minimum of this and o, with broadcasting (minimumNaN(Tensor) propagates NaN).
    • gt

      public Tensor gt(Tensor o)
      1 where this > o, else 0, with broadcasting.
    • lt

      public Tensor lt(Tensor o)
      1 where this < o, else 0, with broadcasting.
    • ge

      public Tensor ge(Tensor o)
      1 where this >= o, else 0, with broadcasting.
    • eq

      public Tensor eq(Tensor o)
      1 where this == o, else 0, with broadcasting.
    • add

      public Tensor add(float c)
      this + c.
    • mul

      public Tensor mul(float c)
      this * c.
    • neg

      public Tensor neg()
      -this.
    • exp

      public Tensor exp()
      e^x, element-wise.
    • log

      public Tensor log()
      The natural logarithm, element-wise.
    • sqrt

      public Tensor sqrt()
      The square root, element-wise.
    • abs

      public Tensor abs()
      |x|, element-wise.
    • relu

      public Tensor relu()
      max(x, 0), element-wise.
    • relu6

      public Tensor relu6()
      min(max(x, 0), 6).
    • pow

      public Tensor pow(Tensor exponent)
      x^exponent, element-wise, with broadcasting.
    • pow

      public Tensor pow(float exponent)
      x^exponent, element-wise.
    • clamp

      public Tensor clamp(float lo, float hi)
      x clamped to [lo, hi].
    • reciprocal

      public Tensor reciprocal()
      1 / x, element-wise.
    • square

      public Tensor square()
      x^2, element-wise.
    • tanh

      public Tensor tanh()
      The hyperbolic tangent, element-wise.
    • sigmoid

      public Tensor sigmoid()
      The logistic sigmoid 1 / (1 + exp(-x)), element-wise.
    • gelu

      public Tensor gelu()
      GELU, exact form x * Phi(x) (PyTorch's default, approximate='none').
    • geluTanh

      public Tensor geluTanh()
      GELU with the tanh approximation (GPT-2's form, PyTorch's approximate='tanh').
    • silu

      public Tensor silu()
      SiLU (swish): x * sigmoid(x).
    • leakyRelu

      public Tensor leakyRelu(float slope)
      LeakyReLU: x for x > 0, else slope * x (PyTorch's default slope is 0.01).
    • sin

      public Tensor sin()
      Element-wise sine.
    • cos

      public Tensor cos()
      Element-wise cosine.
    • tan

      public Tensor tan()
      Element-wise tangent.
    • asin

      public Tensor asin()
      Element-wise arcsine.
    • acos

      public Tensor acos()
      Element-wise arccosine.
    • atan

      public Tensor atan()
      Element-wise arctangent.
    • sinh

      public Tensor sinh()
      Element-wise hyperbolic sine.
    • cosh

      public Tensor cosh()
      Element-wise hyperbolic cosine.
    • asinh

      public Tensor asinh()
      Element-wise inverse hyperbolic sine.
    • acosh

      public Tensor acosh()
      Element-wise inverse hyperbolic cosine.
    • atanh

      public Tensor atanh()
      Element-wise inverse hyperbolic tangent.
    • erf

      public Tensor erf()
      Element-wise error function.
    • erfc

      public Tensor erfc()
      Element-wise complementary error function.
    • round

      public Tensor round()
      Element-wise rounding to the nearest integer, halves to even (PyTorch's round).
    • trunc

      public Tensor trunc()
      Element-wise rounding towards zero.
    • floor

      public Tensor floor()
      Element-wise floor.
    • ceil

      public Tensor ceil()
      Element-wise ceiling.
    • sign

      public Tensor sign()
      Element-wise sign: -1, 0 or 1.
    • log1p

      public Tensor log1p()
      Element-wise log(1 + x), accurate near 0.
    • expm1

      public Tensor expm1()
      Element-wise exp(x) - 1, accurate near 0.
    • logicalNot

      public Tensor logicalNot()
      Element-wise logical not: 1 where x is 0, else 0.
    • atan2

      public Tensor atan2(Tensor o)
      atan2(this, o), the angle of the point (o, this), with broadcasting.
    • bitwiseAnd

      public Tensor bitwiseAnd(Tensor o)
      Bitwise and of INT32 tensors, with broadcasting.
    • bitwiseOr

      public Tensor bitwiseOr(Tensor o)
      Bitwise or of INT32 tensors, with broadcasting.
    • bitwiseXor

      public Tensor bitwiseXor(Tensor o)
      Bitwise exclusive or of INT32 tensors, with broadcasting.
    • bitwiseNot

      public Tensor bitwiseNot()
      Bitwise complement of an INT32 tensor.
    • shiftLeft

      public Tensor shiftLeft(Tensor o)
      this << o for INT32 tensors, with broadcasting.
    • shiftRight

      public Tensor shiftRight(Tensor o)
      this >> o (arithmetic: the sign is kept) for INT32 tensors, with broadcasting.
    • remainder

      public Tensor remainder(Tensor o)
      this - floor(this / o) o, with broadcasting: the remainder with the sign of the divisor (torch.remainder). INT32 tensors give an INT32 result (0 where o is 0), with no gradient.
    • fmod

      public Tensor fmod(Tensor o)
      this - trunc(this / o) o, with broadcasting: the remainder with the sign of the dividend (torch.fmod). INT32 tensors give an INT32 result (0 where o is 0), with no gradient.
    • ne

      public Tensor ne(Tensor o)
      1 where this != o, else 0, with broadcasting.
    • le

      public Tensor le(Tensor o)
      1 where this <= o, else 0, with broadcasting.
    • logicalAnd

      public Tensor logicalAnd(Tensor o)
      1 where both are non-zero, with broadcasting.
    • logicalOr

      public Tensor logicalOr(Tensor o)
      1 where either is non-zero, with broadcasting.
    • logicalXor

      public Tensor logicalXor(Tensor o)
      1 where exactly one is non-zero, with broadcasting.
    • indexSelect

      public Tensor indexSelect(int axis, Tensor idx)
      Elements idx[0 .. m-1] (INT32 [m]) of axis, torch.index_select.
    • gather

      public Tensor gather(int axis, Tensor index)
      torch.gather along axis with an INT32 index of this shape except along the axis.
    • scatterAdd

      public Tensor scatterAdd(int axis, Tensor index, Tensor src)
      torch.scatter_add: this with src added at index along axis.
    • scatter

      public Tensor scatter(int axis, Tensor index, Tensor src)
      torch.scatter: this with src written at index (duplicates: the last wins); no gradient.
    • cumsum

      public Tensor cumsum(int axis)
      Inclusive cumulative sum along axis.
    • cumprod

      public Tensor cumprod(int axis)
      Inclusive cumulative product along axis; its gradient is exact with zeros.
    • nonzero

      public Tensor nonzero()
      INT32 coordinates [count, rank] of the non-zero elements (torch.nonzero); reads the count back to the host.
    • maskedSelect

      public Tensor maskedSelect(Tensor mask)
      The elements where mask (broadcast) is not zero, as a vector (torch.masked_select); reads the count back to the host.
    • sort

      public Tensor[] sort(int axis, boolean descending)
      Stable sort along axis: {values, INT32 original indices}; values carry the gradient.
    • argsort

      public Tensor argsort(int axis, boolean descending)
      INT32 indices that sort along axis (stable).
    • isNaN

      public Tensor isNaN()
      1 where NaN, else 0 (tested by bit pattern).
    • isInf

      public Tensor isInf()
      1 where +inf or -inf, else 0.
    • isFiniteMask

      public Tensor isFiniteMask()
      1 where finite, else 0.
    • nanToNum

      public Tensor nanToNum(float nan, float posInf)
      NaN to nan, +inf to posInf and -inf to -posInf (torch.nan_to_num with a symmetric infinity).
    • maximumNaN

      public Tensor maximumNaN(Tensor o)
      Element-wise maximum propagating NaN (torch.maximum).
    • minimumNaN

      public Tensor minimumNaN(Tensor o)
      Element-wise minimum propagating NaN (torch.minimum).
    • fmax

      public Tensor fmax(Tensor o)
      Element-wise maximum ignoring a NaN operand (torch.fmax).
    • fmin

      public Tensor fmin(Tensor o)
      Element-wise minimum ignoring a NaN operand (torch.fmin).
    • elu

      public Tensor elu(float alpha)
      ELU: x for x > 0, else alpha (exp(x) - 1).
    • selu

      public Tensor selu()
      SELU with PyTorch's constants (alpha 1.6732632, scale 1.0507010).
    • celu

      public Tensor celu(float alpha)
      CELU: max(0, x) + min(0, alpha (exp(x / alpha) - 1)).
    • mish

      public Tensor mish()
      Mish: x tanh(softplus(x)).
    • softsign

      public Tensor softsign()
      Softsign: x / (1 + |x|).
    • hardSigmoid

      public Tensor hardSigmoid()
      HardSigmoid, PyTorch's form: clamp(x / 6 + 1/2, 0, 1).
    • hardSwish

      public Tensor hardSwish()
      HardSwish: x hardSigmoid(x).
    • hardTanh

      public Tensor hardTanh(float lo, float hi)
      HardTanh: x clamped to [lo, hi] (PyTorch's default -1, 1).
    • thresholdedRelu

      public Tensor thresholdedRelu(float theta)
      ThresholdedReLU (Keras): x where x > theta, else 0.
    • cube

      public Tensor cube()
      x^3 (DL4J's Cube activation).
    • softplus

      public Tensor softplus()
      Softplus, log(1 + exp(x)) (beta 1), computed without overflow.
    • sum

      public Tensor sum()
      The sum of all elements, as a scalar.
    • sum

      public Tensor sum(int axis, boolean keepDim)
      The sum along axis, which is kept with size 1 when keepDim is set.
    • mean

      public Tensor mean()
      The mean of all elements, as a scalar.
    • mean

      public Tensor mean(int axis, boolean keepDim)
      The mean along axis, which is kept with size 1 when keepDim is set.
    • max

      public Tensor max(int axis, boolean keepDim)
      The maximum along axis, which is kept with size 1 when keepDim is set; argmax(int) gives its index.
    • min

      public Tensor min(int axis, boolean keepDim)
      The minimum along axis, which is kept with size 1 when keepDim is set; argmin(int) gives its index.
    • argmax

      public Tensor argmax(int axis)
      Index of the maximum along axis, as an INT32 tensor (no gradient).
    • argmin

      public Tensor argmin(int axis)
      INT32 index of the first minimum along axis.
    • prod

      public Tensor prod(int axis, boolean keepDim)
      Product along axis.
    • prod

      public Tensor prod()
      Product of all elements.
    • norm

      public Tensor norm(int p, int axis, boolean keepDim)
      The p-norm (p = 1 or 2) along axis: sum |x| or sqrt(sum x^2).
    • sumTo

      public Tensor sumTo(Shape target)
      Sums broadcast dimensions away so the result has target shape (gradient of broadcasting).
    • tile

      public Tensor tile(int... reps)
      This tensor repeated reps[i] times along each axis (torch.Tensor.repeat, numpy.tile, ONNX Tile); reps longer than the rank adds leading axes.
    • expand

      public Tensor expand(Shape target)
      Broadcast copy to target shape.
    • reshape

      public Tensor reshape(int... dims)
      Same data, new shape; one dimension may be -1.
    • permute

      public Tensor permute(int... order)
      The axes reordered: axis i of the result is axis order[i] of this tensor. A copy, not a view.
    • transpose

      public Tensor transpose(int a, int b)
      Axes a and b swapped (negative axes count from the end); a copy, as permute(int...).
    • to

      public Tensor to(DType dtype)
      This tensor converted to dtype: between FP32, FP16 and BF16 (round to nearest even; differentiable), or between FP32 and INT32 (truncating toward zero; no gradient).
    • half

      public Tensor half()
      This tensor converted to FP16 (to(DType.F16)).
    • bfloat16

      public Tensor bfloat16()
      This tensor converted to BF16 (to(DType.BF16)).
    • toFloat

      public Tensor toFloat()
      This tensor converted to FP32 (to(DType.F32)).
    • topk

      public Tensor[] topk(int k)
      The k largest values along the last axis and their INT32 indices (descending; ties: lower index first).
    • narrow

      public Tensor narrow(int axis, int start, int length)
      Elements start .. start + length - 1 along axis, as a new tensor.
    • slice

      public Tensor slice(int axis, int start, int end)
      Elements start .. end - 1 along axis; negative indices count from the end.
    • split

      public Tensor[] split(int axis, int... sizes)
      Splits axis into consecutive pieces of the given sizes.
    • chunk

      public Tensor[] chunk(int chunks, int axis)
      Splits axis into chunks equal pieces.
    • cat

      public static Tensor cat(int axis, Tensor... parts)
      Joins tensors along an existing axis.
    • stack

      public static Tensor stack(int axis, Tensor... parts)
      Joins same-shape tensors along a new axis.
    • unsqueeze

      public Tensor unsqueeze(int axis)
      A view with a new size-1 axis at axis (negative counts from the end of the result).
    • squeeze

      public Tensor squeeze(int axis)
      A view without the size-1 axis axis.
    • t

      public Tensor t()
      Transpose of a matrix.
    • matmul

      public Tensor matmul(Tensor b)
      The matrix product this b: [M, K] x [K, N] to [M, N], or batched over leading axes, which must match unless one side is a plain matrix shared by every batch. Half-precision operands accumulate in FP32; under Autocast FP32 operands are cast to the autocast type first.
    • matmul

      public Tensor matmul(Tensor b, boolean transposeThis, boolean transposeB)
      op(this) * op(b), where op transposes when the flag is set, without materialising the transpose.
    • softmax

      public Tensor softmax()
      Softmax along the last axis.
    • logSoftmax

      public Tensor logSoftmax()
      Log-softmax along the last axis.
    • toString

      public String toString()
      Overrides:
      toString in class Object