MemorySegmentTensorData

Off-heap, 64-byte-aligned tensor data backed by a MemorySegment.

This avoids GC pressure and enables direct use with the Vector API's FloatVector.fromMemorySegment for SIMD-friendly access patterns.

Two constructors:

  • Primary: allocates a fresh segment via arena.

  • Secondary (slice): wraps an existing segment region (zero-copy view).

Constructors

Link copied to clipboard
constructor(shape: Shape, arena: Arena, alignment: Long = 64)

Allocates a new off-heap segment from arena with the given alignment.

constructor(shape: Shape, segment: MemorySegment, byteOffset: Long = 0)

Wraps an existing segment region starting at byteOffset (zero-copy slice).

Properties

Link copied to clipboard

Byte length of the data region.

Link copied to clipboard
open override val segment: MemorySegment

The underlying off-heap memory segment.

Link copied to clipboard
open override val segmentByteOffset: Long

Byte offset into segment where this tensor's data starts.

Link copied to clipboard
open override val shape: Shape

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

Link copied to clipboard
val volume: Int

Total number of floats in this tensor.

Functions

Link copied to clipboard
fun copyFromFloatArray(src: FloatArray, srcOffset: Int = 0, length: Int = volume)

Bulk-copy a FloatArray into this tensor's segment.

Link copied to clipboard
open override fun copyToFloatArray(): FloatArray

Copies all tensor data to a FloatArray.

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

Retrieves an element at the specified multidimensional indices.

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

Setter

Link copied to clipboard
fun slice(flatOffset: Int, size: Int): MemorySegmentTensorData<T>

Returns a zero-copy view into this tensor's segment. The returned view shares the same underlying memory.