operators

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package operators implements ONNX operator mapping to Born tensor operations.

The package provides a registry of operator handlers that convert ONNX nodes to equivalent Born operations. Each handler validates inputs and attributes, then delegates to the appropriate backend operation.

Supported operator tiers:

  • Tier 1 (Essential): Basic math, activations, convolutions - for ResNet, MobileNet
  • Tier 2 (Extended): Advanced ops for transformers and attention models

Package operators provides ONNX operator implementations.

Index

Constants

View Source
const (
	TensorProtoUndefined = 0
	TensorProtoFloat     = 1  // float32
	TensorProtoUint8     = 2  // uint8
	TensorProtoInt8      = 3  // int8
	TensorProtoUint16    = 4  // uint16
	TensorProtoInt16     = 5  // int16
	TensorProtoInt32     = 6  // int32
	TensorProtoInt64     = 7  // int64
	TensorProtoString    = 8  // string
	TensorProtoBool      = 9  // bool
	TensorProtoFloat16   = 10 // float16
	TensorProtoDouble    = 11 // float64
	TensorProtoUint32    = 12 // uint32
	TensorProtoUint64    = 13 // uint64
)

ONNX data types (TensorProto.DataType).

Variables

This section is empty.

Functions

func GetAttrFloat

func GetAttrFloat(node *Node, name string, defaultVal float32) float32

GetAttrFloat returns a float attribute or default value.

func GetAttrInt

func GetAttrInt(node *Node, name string, defaultVal int64) int64

GetAttrInt returns an integer attribute or default value.

func GetAttrInts

func GetAttrInts(node *Node, name string) []int64

GetAttrInts returns an integer array attribute.

func GetAttrString

func GetAttrString(node *Node, name, defaultVal string) string

GetAttrString returns a string attribute or default value.

Types

type Attribute

type Attribute struct {
	Name    string    // Attribute name
	Type    int32     // Attribute type
	F       float32   // FLOAT value
	I       int64     // INT value
	S       []byte    // STRING value
	Floats  []float32 // FLOATS array
	Ints    []int64   // INTS array
	Strings [][]byte  // STRINGS array
}

Attribute represents a node attribute.

type Context

type Context struct {
	Backend tensor.Backend
}

Context provides backend and other execution context for operators.

type Node

type Node struct {
	Name       string      // Node name (optional)
	OpType     string      // Operation type (e.g., "Conv", "MatMul", "Relu")
	Inputs     []string    // Input tensor names
	Outputs    []string    // Output tensor names
	Attributes []Attribute // Operation attributes
	Domain     string      // Custom domain (empty for default)
}

Node represents an ONNX operation node. This is a local copy of the relevant fields from onnx.NodeProto to avoid import cycles between onnx and operators packages.

type OpHandler

type OpHandler func(ctx *Context, node *Node, inputs []*tensor.RawTensor) ([]*tensor.RawTensor, error)

OpHandler processes an ONNX node and returns output tensors.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maps ONNX operator types to handler functions.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new operator registry with all supported operators.

func (*Registry) Execute

func (r *Registry) Execute(ctx *Context, node *Node, inputs []*tensor.RawTensor) ([]*tensor.RawTensor, error)

Execute runs an operator with the given inputs.

func (*Registry) Get

func (r *Registry) Get(opType string) (OpHandler, bool)

Get returns the handler for an operator type.

func (*Registry) Register

func (r *Registry) Register(opType string, handler OpHandler)

Register adds a custom operator handler.

func (*Registry) SupportedOps

func (r *Registry) SupportedOps() []string

SupportedOps returns a list of all supported operator types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL