Ternary2BitTensorData

class Ternary2BitTensorData(initialShape: Shape, data: ByteArray, val scale: Float = 1.0f) : TernaryTensorData, PackedBlockStorage(source)

Ternary tensor data using 2-bit encoding compatible with TQ2_0 format.

Encoding scheme (matches GGUF TQ2_0):

  • 0 → -1

  • 1 → 0

  • 2 → +1

  • 3 → (reserved, treated as +1 for safety)

This is the simpler ternary format with 4 values per byte.

Parameters

initialShape

the shape of the tensor

data

the packed byte array (4 ternary values per byte)

scale

the scale factor for FP32 dequantization

Constructors

Link copied to clipboard
constructor(initialShape: Shape, data: ByteArray, scale: Float = 1.0f)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val blockCount: Int

Number of blocks in this storage.

Link copied to clipboard
open override val blockSize: Int

Number of logical elements per block.

Link copied to clipboard
open override val encoding: TensorEncoding

The physical encoding describing the block layout.

Link copied to clipboard
open override val packedData: ByteArray

Access to the underlying packed byte array for efficient kernel operations. The packing format is implementation-defined.

Link copied to clipboard
open override val scale: Float
Link copied to clipboard
open override val shape: Shape

The shape descriptor that defines the dimensionality and size of this tensor data.

Functions

Link copied to clipboard
open override fun dequantizeBlock(blockIdx: Int, output: FloatArray, outputOffset: Int = 0)

Dequantize a single block to float values.

Link copied to clipboard
open operator override fun get(vararg indices: Int): Byte

Retrieves an element at the specified multidimensional indices.

Link copied to clipboard
open operator override fun set(vararg indices: Int, value: Byte)

Setter