Q4_KBlockTensorData

Implementation of Q4_KTensorData backed by a packed byte array.

Memory layout per block (144 bytes):

  • bytes 0..1: f16 d (little-endian)

  • bytes 2..3: f16 dMin (little-endian)

  • bytes 4..15: packed 12-bit scale/min indices (12 bytes)

  • bytes 16..143: 4-bit quantized codes (128 bytes, 2 codes per byte)

Scale packing: Each sub-block uses 12 bits (6 for scaleIdx, 6 for minIdx). 8 sub-blocks × 12 bits = 96 bits = 12 bytes.

Parameters

initialShape

the logical shape of the tensor (in elements, not blocks)

packedData

the raw packed block data

Constructors

Link copied to clipboard
constructor(initialShape: Shape, data: ByteArray)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val blockCount: Int

Number of Q4_K blocks in the tensor.

Link copied to clipboard
open override val packedData: ByteArray

Raw packed data containing all blocks.

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 operator override fun get(vararg indices: Int): Byte

Retrieves an element at the specified multidimensional indices.

Link copied to clipboard
open override fun getBlockD(blockIdx: Int): Float

Get the main scale factor (d) for a block.

Link copied to clipboard
open override fun getBlockDMin(blockIdx: Int): Float

Get the minimum scale factor (dMin) for a block.

Link copied to clipboard
open override fun getCode(blockIdx: Int, elementIdx: Int): Int

Get a 4-bit quantized code value (0..255 elements within block).

Link copied to clipboard
open override fun getSubBlockMin(blockIdx: Int, subBlockIdx: Int): Float

Get the minimum value for a specific sub-block within a block.

Link copied to clipboard
open override fun getSubBlockScale(blockIdx: Int, subBlockIdx: Int): Float

Get the scale for a specific sub-block within a block.

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

Setter