class
OnnxRuntime::SparseTensor(T)
- OnnxRuntime::SparseTensor(T)
- Reference
- Object
Overview
SparseTensor class provides high-level API for working with sparse tensors in ONNX Runtime.
Defined in:
onnxruntime/sparse_tensor.crConstructors
-
.new(format : LibOnnxRuntime::SparseFormat, values : Array(T), indices : Hash(Symbol, Array(Int32) | Array(Int64)), dense_shape : Array(Int64))
Creates a new SparseTensor instance.
Class Method Summary
-
.block_sparse(values : Array(T), indices : Array, dense_shape : Array(Int64)) forall T
Creates a BlockSparse format sparse tensor.
-
.coo(values : Array(T), indices : Array, dense_shape : Array(Int64)) forall T
Creates a COO format sparse tensor.
-
.csr(values : Array(T), inner_indices : Array, outer_indices : Array, dense_shape : Array(Int64)) forall T
Creates a CSR format sparse tensor.
Instance Method Summary
- #dense_shape
- #format
- #indices
-
#to_ort_value(session)
Converts the sparse tensor to an OrtValue that can be used with the ONNX Runtime API.
- #values
Constructor Detail
def self.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
Class Method Detail
def self.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
def self.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
def self.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 array#dense_shape
- The shape of the dense tensor this sparse tensor represents
Instance Method Detail
def 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