class

OnnxRuntime::SparseTensor(T)

Inherits Reference / Object

SparseTensor class provides high-level API for working with sparse tensors in ONNX Runtime.

Constructors

new(format : LibOnnxRuntime::SparseFormat, values : Array(T), indices : Hash(Symbol, Array(Int32) | Array(Int64)), dense_shape : Array(Int64))

Creates a new SparseTensor instance.

  • format - The sparse tensor format (COO, CSR, or BLOCK_SPARSE)
  • values - The non-zero values in the sparse tensor
  • indices - The indices data for the sparse tensor (format-specific)
  • dense_shape - The shape of the dense tensor this sparse tensor represents
Source

Class methods

block_sparse(values : Array(T), indices : Array, dense_shape : Array(Int64)) forall T

Creates a BlockSparse format sparse tensor.

  • values - The non-zero values in the sparse tensor
  • indices - The block indices
  • dense_shape - The shape of the dense tensor this sparse tensor represents
Source
coo(values : Array(T), indices : Array, dense_shape : Array(Int64)) forall T

Creates a COO format sparse tensor.

  • values - The non-zero values in the sparse tensor
  • indices - The indices data for the sparse tensor (2D array where each row is a coordinate)
  • dense_shape - The shape of the dense tensor this sparse tensor represents
Source
csr(values : Array(T), inner_indices : Array, outer_indices : Array, dense_shape : Array(Int64)) forall T

Creates a CSR format sparse tensor.

  • values - The non-zero values in the sparse tensor
  • inner_indices - The column indices for each non-zero value
  • outer_indices - The row pointers indicating where each row starts in the values array
  • dense_shape - The shape of the dense tensor this sparse tensor represents
Source

Instance methods

dense_shape
Source
format
Source
indices
Source
to_ort_value(session)

Converts the sparse tensor to an OrtValue that can be used with the ONNX Runtime API. Note: The caller is responsible for releasing the returned OrtValue using api.release_value.call(tensor)

  • session - The InferenceSession instance to use for creating the OrtValue
Source
values
Source