evaluator

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Package evaluator defines interfaces for the interpreter to use to evaluate GX code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayOps added in v0.3.0

type ArrayOps interface {
	// Graph returns the graph to which new nodes are being added.
	Graph() ops.Graph

	// SubGraph returns a new graph builder.
	SubGraph(name string, args []*shape.Shape) (ArrayOps, error)

	// Einsum calls an einstein sum on x and y given the expression in ref.
	Einsum(ctx ir.Evaluator, expr *ir.EinsumExpr, x, y NumericalElement) (NumericalElement, error)

	// BroadcastInDim the data of an array across dimensions.
	BroadcastInDim(ctx ir.Evaluator, expr ir.AssignableExpr, x NumericalElement, axisLengths []NumericalElement) (NumericalElement, error)

	// Concat concatenates scalars elements into an array with one axis.
	Concat(ctx ir.Evaluator, expr ir.AssignableExpr, xs []NumericalElement) (NumericalElement, error)

	// Set a slice in an array.
	Set(ctx ir.Evaluator, expr *ir.CallExpr, x, updates, index ir.Element) (ir.Element, error)

	// ElementFromArray returns an element from an array GX value.
	ElementFromArray(ctx ir.Evaluator, expr ir.AssignableExpr, val values.Array) (NumericalElement, error)
}

ArrayOps are the operator implementations for arrays.

type Context

type Context interface {
	ir.Evaluator

	// Evaluator returns the evaluator used by the interpreter.
	Evaluator() Evaluator

	// Materialiser returns the materialiser to convert elements into graph nodes.
	Materialiser() materialise.Materialiser
}

Context in which an operator is being executed.

type Evaluator

type Evaluator interface {
	// Importer returns an importer to import package.
	Importer() ir.Importer

	// ArrayOps returns the operator implementations for arrays.
	ArrayOps() ArrayOps

	// Processor returns the used by the array evaluator.
	Processor() *processor.Processor

	// ElementFromAtom returns an element from an atomic GX value.
	ElementFromAtom(ctx ir.Evaluator, expr ir.AssignableExpr, val values.Array) (NumericalElement, error)

	// Trace register a call to the trace builtin function.
	Trace(ctx ir.Evaluator, call *ir.CallExpr, args []ir.Element) error
}

Evaluator implements GX operators.

type NumericalElement added in v0.3.0

type NumericalElement interface {
	ir.Element

	// UnaryOp applies a unary operator on x.
	UnaryOp(ctx ir.Evaluator, expr *ir.UnaryExpr) (NumericalElement, error)

	// BinaryOp applies a binary operator to x and y.
	// Note that the receiver can be either the left or right argument.
	BinaryOp(ctx ir.Evaluator, expr *ir.BinaryExpr, x, y NumericalElement) (NumericalElement, error)

	// Cast an element into a given data type.
	Cast(ctx ir.Evaluator, expr ir.AssignableExpr, target ir.Type) (NumericalElement, error)

	// Reshape an element.
	Reshape(ctx ir.Evaluator, expr ir.AssignableExpr, axisLengths []NumericalElement) (NumericalElement, error)
}

NumericalElement is a node representing a numerical value.

Jump to

Keyboard shortcuts

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