class OnnxRuntime::SparseTensor(T)

Overview

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

Defined in:

onnxruntime/sparse_tensor.cr

Constructors

Class Method Summary

Instance Method Summary

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

[View source]

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

[View source]
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

[View source]
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 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

[View source]

Instance Method Detail

def dense_shape #

[View source]
def format #

[View source]
def indices #

[View source]
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

[View source]
def values #

[View source]