//clika-runtime/io.clika.runtime/Tensors
Tensors
[common]
object Tensors
The tensor factories and data entry.
ClikaRt.load()
val x = Tensors.of(floatArrayOf(1f, 2f, 3f, 4f), longArrayOf(2, 2))
val z = Tensors.zeros(longArrayOf(2, 2), where = Device.CPU)
println(x.sum().item())
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 (one Short per element); conversion runs in the runtime (Tensor.to), never host-side float math. A null Placement is the runtime's default placement; a Device names the device; a Stream names the lane exactly.
Functions
| Name | Summary |
|---|---|
| fromBlob | [common] fun fromBlob(buffer: <Error class: unknown class>, shape: LongArray, dtype: DType = DType.FLOAT32, where: Placement? = 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 from its position 0. With no deleter the tensor BORROWS the buffer, which the returned tensor keeps referenced while it lives (a view derived from it does not: keep the buffer alive for as long as any view is in use); 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. A buffer smaller than the shape needs is refused. |
| fromBlobStrided | [common] fun fromBlobStrided(buffer: <Error class: unknown class>, shape: LongArray, strides: LongArray, dtype: DType = DType.FLOAT32, where: Placement? = 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 | [common] fun fromBytes(bytes: ByteArray, shape: LongArray, dtype: DType, where: Placement? = null): Tensor Raw entry: bytes read at dtype in row-major order (the sub-byte dtypes pack). |
| full | [common] fun full(shape: LongArray, value: Double, dtype: DType = DType.FLOAT32, where: Placement? = null): Tensor A shape-extent tensor filled with value (cast to dtype). |
| of | [common] fun of(data: DoubleArray, shape: LongArray, where: Placement? = null): Tensor Float64 entry. [common] fun of(data: FloatArray, shape: LongArray, where: Placement? = null): Tensor Float32 entry: data copied in row-major order over shape. [common] fun of(data: IntArray, shape: LongArray, where: Placement? = null): Tensor Int32 entry. [common] fun of(data: LongArray, shape: LongArray, where: Placement? = null): Tensor Int64 entry. |
| ofBFloat16Bits | [common] fun ofBFloat16Bits(bits: ShortArray, shape: LongArray, where: Placement? = null): Tensor BFloat16 entry from the 16-bit patterns. |
| ofFloat16Bits | [common] fun ofFloat16Bits(bits: ShortArray, shape: LongArray, where: Placement? = null): Tensor Float16 entry from the 16-bit patterns (one IEEE-754 binary16 pattern per Short). |
| ones | [common] fun ones(shape: LongArray, dtype: DType = DType.FLOAT32, where: Placement? = null): Tensor A shape-extent tensor of ones. |
| zeros | [common] fun zeros(shape: LongArray, dtype: DType = DType.FLOAT32, where: Placement? = null): Tensor A shape-extent tensor of zeros. |