class

Onnx::Value

Inherits Reference < Object

Wraps an OrtValue tensor. Input tensors own their data buffer (ONNX Runtime references the memory, it does not copy it); output tensors borrow memory owned by the runtime.

Constructors

f32(values : Array(Float32) | Slice(Float32), shape : Array(Int64)) : Value
Source
i64(values : Array(Int64) | Slice(Int64), shape : Array(Int64)) : Value
Source
new(ptr : Pointer(LibOnnx::OrtValue), buffer : Pointer(Void) | Nil = nil, owner : Slice(UInt8) | Nil = nil)
Source
tensor(data : Slice(UInt8), shape : Array(Int64), type : LibOnnx::ElementType) : Value

Creates a tensor from a byte buffer (no conversion). shape is only used by the runtime; data must contain shape.product * type.bytesize bytes.

Source
tensor_nocopy(data : Slice(UInt8), shape : Array(Int64) | Slice(Int64), type : LibOnnx::ElementType) : Value

Wraps an existing buffer as a tensor without copying (allocation-free path for streaming: fill data in place and recreate the Value). The caller must keep data alive as long as the Value exists.

Source

Class methods

f16_to_f32(h : UInt16) : Float32

IEEE 754 half → float.

Source

Instance methods

data

Raw pointer to the tensor data (do not free).

Source
element_type
Source
finalize
Source
read_i16s_into(buf : Array(Int16)) : Int32

Decodes waveform tensors to Int16 PCM in place, without allocating: writes into buf (grown only when a longer result appears — do not clear it between calls) and returns the sample count. Only the first count entries of buf are valid. Float audio in [-1,1] is scaled to PCM16.

Source
shape
Source
size

Element count (product of dims).

Source
to_f32s

Decodes numeric tensors to Float32 (handles FLOAT16, FLOAT, DOUBLE).

Source
to_i16s

Decodes waveform tensors to Int16 PCM (scales float audio from [-1,1]).

Source