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 tensorindices- The indices data for the sparse tensor (format-specific)dense_shape- The shape of the dense tensor this sparse tensor represents
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 tensorindices- The block indicesdense_shape- The shape of the dense tensor this sparse tensor represents
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 tensorindices- 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
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 tensorinner_indices- The column indices for each non-zero valueouter_indices- The row pointers indicating where each row starts in the values arraydense_shape- The shape of the dense tensor this sparse tensor represents
Instance methods
dense_shape
Sourceformat
Sourceindices
Sourceto_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
values
Source