Skip to main content

//clika-runtime/io.clika.runtime/Tensor

Tensor

[jvm]
class Tensor : AutoCloseable

A caller-owned tensor handle; release it when done (the last release frees the storage). Ops that CONSUME their operand (the donation law; see ClikaRt.addScalar) zero the handle, making a later release a no-op.

AutoCloseable so a scope can ride use { }:

Tensors.full(longArrayOf(2, 3), 1.5).use { t -> println(t.summary()) }

Functions

NameSummary
cast[jvm]
fun Tensor.cast(dtype: Int, forceCopy: Boolean = false): Tensor
Convert to dtype through the runtime (never host-side float math).
close[jvm]
open override fun close()
release, under the AutoCloseable spelling.
div[jvm]
operator fun Tensor.div(other: Tensor): Tensor
this / other, elementwise with broadcasting (true division).
[jvm]
operator fun Tensor.div(scalar: Double): Tensor
operator fun Tensor.div(scalar: Int): Tensor
this / scalar, elementwise.
dtype[jvm]
fun Tensor.dtype(): Int
The tensor's dtype, as a ClikaRtGen.DATA_TYPE_* value.
item[jvm]
fun Tensor.item(): Float
The one element of a single-element Float32 tensor (a reduction's result). Waits for the producer; refuses a numel other than 1 or another dtype (ClikaRtException).
itemDouble[jvm]
fun Tensor.itemDouble(): Double
item for a Float64 tensor.
itemInt[jvm]
fun Tensor.itemInt(): Int
item for an Int32 tensor.
itemLong[jvm]
fun Tensor.itemLong(): Long
item for an Int64 tensor.
matmul[jvm]
infix fun Tensor.matmul(other: Tensor): Tensor
t @ w: matrix multiplication (Kotlin has no @; the named infix).
minus[jvm]
operator fun Tensor.minus(other: Tensor): Tensor
this - other, elementwise with broadcasting.
[jvm]
operator fun Tensor.minus(scalar: Double): Tensor
operator fun Tensor.minus(scalar: Int): Tensor
this - scalar, elementwise.
onComplete[jvm]
fun Tensor.onComplete(callback: TensorCallback)
Register callback to run once this tensor's producer has finished (the moment the tensor becomes available; a tensor that is already available fires it right away). Non-consuming: this tensor stays the caller's.
plus[jvm]
operator fun Tensor.plus(other: Tensor): Tensor
this + other, elementwise with broadcasting.
[jvm]
operator fun Tensor.plus(scalar: Double): Tensor
operator fun Tensor.plus(scalar: Int): Tensor
this + scalar, elementwise.
release[jvm]
fun release()
Drop this handle's reference (the last release frees the storage); safe to call twice.
shape[jvm]
fun Tensor.shape(): LongArray
The tensor's shape (the recorded bound for a data-dependent producer).
summary[jvm]
fun Tensor.summary(): String
The tensor's human-readable summary (shape, dtype, device, first values). Rides the generated surface, so it works under either ClikaRt.load or ClikaRtGen.load.
times[jvm]
operator fun Tensor.times(other: Tensor): Tensor
this * other, elementwise with broadcasting.
[jvm]
operator fun Tensor.times(scalar: Double): Tensor
operator fun Tensor.times(scalar: Int): Tensor
this * scalar, elementwise.
to[jvm]
fun Tensor.to(device: Device): Tensor
Move to device. Non-consuming.
[jvm]
fun Tensor.to(device: String): Tensor
Move to device (string form, e.g. "cuda:0"). Non-consuming.
toDoubleArray[jvm]
fun Tensor.toDoubleArray(): DoubleArray
toFloatArray for a Float64 tensor.
toFloatArray[jvm]
fun Tensor.toFloatArray(): FloatArray
Every element of a 0-D or 1-D contiguous Float32 tensor, copied out (waits for the producer). Reshape a higher-rank tensor to 1-D first.
toIntArray[jvm]
fun Tensor.toIntArray(): IntArray
toFloatArray for an Int32 tensor.
toLongArray[jvm]
fun Tensor.toLongArray(): LongArray
toFloatArray for an Int64 tensor.
unaryMinus[jvm]
operator fun Tensor.unaryMinus(): Tensor
-this, elementwise.