Skip to main content

//clika-runtime/io.clika.runtime/Tensors

Tensors

[jvm]
object Tensors

The tensor factories and data entry.

ClikaRtGen.load()
val x = Tensors.of(floatArrayOf(1f, 2f, 3f, 4f), longArrayOf(2, 2))
val z = Tensors.zeros(longArrayOf(2, 2), device = Device.CPU)
println((x + z).summary())

Dtype carriage is honest end to end: payload bytes enter at the declared dtype, and dtypes the JVM lacks ride BIT CARRIERS: ofFloat16Bits / ofBFloat16Bits take the 16-bit patterns (a Float.toBits()-style carrier, one Short per element); conversion runs in the runtime (ops.cast), never host-side float math.

Functions

NameSummary
fromBlob[jvm]
@JvmOverloads
fun fromBlob(buffer: ByteBuffer, shape: LongArray, dtype: Int = ClikaRtGen.DATA_TYPE_FLOAT32, device: Device? = null, deleter: VoidCallback? = null): Tensor
Wrap memory the application owns, without copying: buffer must be a DIRECT ByteBuffer (allocateDirect, the one JVM buffer with a stable native address), holding shape elements of dtype in row-major order. With no deleter the tensor BORROWS the buffer, which must outlive every view of it; with a deleter the tensor ADOPTS it, and the deleter runs exactly once, when the last reference drops (on whichever thread that happens). Writes through the buffer are visible through the tensor: it is the same memory.
fromBlobStrided[jvm]
@JvmOverloads
fun fromBlobStrided(buffer: ByteBuffer, shape: LongArray, strides: LongArray, dtype: Int = ClikaRtGen.DATA_TYPE_FLOAT32, device: Device? = null, deleter: VoidCallback? = null): Tensor
fromBlob over a strided layout: strides are element strides per dimension (a region of a larger row-major image keeps the image's row pitch as its row stride). buffer's position 0 is the first element (slice() a buffer to start elsewhere).
fromBytes[jvm]
@JvmOverloads
fun fromBytes(bytes: ByteArray, shape: LongArray, dtype: Int, device: Device? = null): Tensor
Raw entry: bytes interpreted at dtype in row-major order.
full[jvm]
@JvmOverloads
fun full(shape: LongArray, value: Double, dtype: Int = ClikaRtGen.DATA_TYPE_FLOAT32, device: Device? = null): Tensor
A shape-extent tensor filled with value.
of[jvm]
@JvmOverloads
fun of(data: DoubleArray, shape: LongArray, device: Device? = null): Tensor
Float64 entry.
[jvm]
@JvmOverloads
fun of(data: FloatArray, shape: LongArray, device: Device? = null): Tensor
Float32 entry: data copied in row-major order over shape.
[jvm]
@JvmOverloads
fun of(data: IntArray, shape: LongArray, device: Device? = null): Tensor
Int32 entry.
[jvm]
@JvmOverloads
fun of(data: LongArray, shape: LongArray, device: Device? = null): Tensor
Int64 entry.
ofBFloat16Bits[jvm]
@JvmOverloads
fun ofBFloat16Bits(bits: ShortArray, shape: LongArray, device: Device? = null): Tensor
BFloat16 entry from the 16-bit patterns (bit-carrier form).
ofFloat16Bits[jvm]
@JvmOverloads
fun ofFloat16Bits(bits: ShortArray, shape: LongArray, device: Device? = null): Tensor
Float16 entry from the 16-bit patterns (the bit-carrier form, one IEEE-754 binary16 pattern per Short).
ones[jvm]
@JvmOverloads
fun ones(shape: LongArray, dtype: Int = ClikaRtGen.DATA_TYPE_FLOAT32, device: Device? = null): Tensor
A shape-extent tensor of ones.
zeros[jvm]
@JvmOverloads
fun zeros(shape: LongArray, dtype: Int = ClikaRtGen.DATA_TYPE_FLOAT32, device: Device? = null): Tensor
A shape-extent tensor of zeros.