Docs / nablatensor-tensor / com.nablatensor.tensor

final class

Tensor

An immutable, fluent tensor handle. Every operation returns a new Tensor; materialization happens on the backend as operations are issued, and eval() / blockUntilReady() wait for completion.

Backends normally reclaim device memory only once a wrapper becomes unreachable and the GC/Cleaner get around to it, which is heuristic and can lag under sustained allocation pressure. Tight loops that discard a result every iteration (benchmarks, training steps) should call close() (or use try-with-resources) to free it deterministically instead.

Methods

Shape shape()
DType dtype()
Device device()
Tensor on(Device device)

Move to another device, re-uploading through the target backend.

Tensor f32()
Tensor dtype(DType dtype)
Tensor add(Tensor other)
Tensor sub(Tensor other)
Tensor mul(Tensor other)
Tensor div(Tensor other)
Tensor maximum(Tensor other)
Tensor minimum(Tensor other)
Tensor add(double value)
Tensor sub(double value)
Tensor mul(double value)
Tensor div(double value)
Tensor maximum(double value)
Tensor minimum(double value)
Tensor neg()
Tensor exp()
Tensor log()
Tensor sqrt()
Tensor rsqrt()
Tensor tanh()
Tensor sigmoid()
Tensor relu()
Tensor abs()
Tensor sign()
Tensor transpose()
Tensor matmul(Tensor other)
Tensor cholesky()

Cholesky factor L of this SPD matrix (this = L·Lᵀ). See cholesky.

Linalg.Lu lu()

LU factorization with partial pivoting. See lu.

Linalg.Qr qr()

Householder QR factorization. See qr.

Linalg.Eigh eigh()

Symmetric eigendecomposition (cyclic Jacobi). See eigh.

Linalg.Svd svd()

Thin singular value decomposition (one-sided Jacobi). See svd.

Tensor solve(Tensor b)

Solves this · X = b for X. See solve.

Tensor inv()

The inverse of this square matrix. See inv.

double det()

The determinant of this square matrix. See det.

Tensor batchedMatmul(Tensor other)

Batched matrix multiplication: (B,M,K) x (B,K,N) -> (B,M,N).

Tensor sliceAxis0(int index)

Copies one leading-axis slice and removes the leading dimension.

static Tensor stackAxis0(List<Tensor> tensors)

Stacks equally-shaped tensors along a new leading axis.

Tensor reshape(int... dims)

Returns an independent tensor with the same elements and a different shape.

Tensor conv2d(Tensor weights, ConvSpec spec)

2-D convolution of batched images (one image per row) against weights of shape (outChannels, inChannels * k * k).

Tensor conv2dGradInput(Tensor weights, ConvSpec spec)

Gradient of conv2d with respect to the input it was given.

Tensor conv2dGradWeight(Tensor upstream, ConvSpec spec)

Gradient of conv2d with respect to its weights; this is the input.

Tensor reluBackward(Tensor input)

Routes this (an upstream gradient) through a ReLU evaluated at input.

Tensor sum()

Sums every element, returning a single-element (shape (1)) tensor.

Tensor mean()

Mean over every element, returning a single-element (shape (1)) tensor.

Tensor max()

Maximum over every element, returning a single-element (shape (1)) tensor.

Tensor sumAxis0()

Sums a rank-2 tensor over axis 0 (the batch axis), returning shape (cols).

Tensor sum(int axis)
Tensor sum(int axis, boolean keepDims)
Tensor max(int axis)
Tensor max(int axis, boolean keepDims)
Tensor argmax(int axis)

Returns maximum-value indices along axis as F32 values. Indices up to 2^24 are exact.

Tensor maxAxisBackward(Tensor upstream, int axis)

Routes reduced gradients to the first maximum position along axis.

Tensor broadcastTo(Shape target)

Broadcasts to target, following broadcast's rules.

Tensor eval()

Force completion of all pending kernels and return this handle.

Tensor blockUntilReady()
void close()

Deterministically frees this tensor's device buffer now, instead of waiting on GC/Cleaner timing. Safe to call even if the GC later also reclaims the same (by-then-unreachable) buffer - backends guarantee the underlying free only ever runs once. Do not use this tensor after closing it.

float[] toFloatArray()
float[][] toFloat2D()
float item()
String toString()