flatten

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: 7 Imported by: 0

Documentation

Overview

Package flatten provides utilities to flatten/unflatten interpreter elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flatten

func Flatten(elts ...ir.Element) ([]ir.Element, error)

Flatten elements.

func ParseCompositeOf

func ParseCompositeOf[T values.Value](
	f func(ir.Type, []values.Value) (T, error),
) func(ir.Type, []values.Value) (values.Value, error)

ParseCompositeOf returns a function to unflatten a composite value.

Types

type Flattener

type Flattener interface {
	// Flatten the element, that is:
	// returns itself if the element is atomic,
	// returns its components if the element is a composite.
	Flatten() ([]ir.Element, error)
}

Flattener is an element that can be flattened.

type Parser

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

Parser unflattens the output of a graph computation into GX values.

func NewParser

func NewParser(dev platform.Device, callInputs *values.FuncInputs, handles []platform.DeviceHandle) *Parser

NewParser returns a new parser given the output of a graph computation.

func (*Parser) CallInputs

func (h *Parser) CallInputs() *values.FuncInputs

CallInputs returns the inputs with which the function was called.

func (*Parser) Device

func (h *Parser) Device() platform.Device

Device returns to which transfers the host value to. TODO(b/388207169): Always transfer the value to device because C++ bindings do not support HostValue.

func (*Parser) Next

func (h *Parser) Next() platform.DeviceHandle

Next returns a the next handle and moves the cursor to the succeeding handle.

func (*Parser) ParseArray

func (h *Parser) ParseArray(typ ir.Type) (values.Array, error)

ParseArray the next value as an array.

func (*Parser) ParseComposite

func (h *Parser) ParseComposite(ncv newCompValue, typ ir.Type, els []ir.Element) (values.Value, error)

ParseComposite unflatten a slice of elements into a single GX value.

func (*Parser) String

func (h *Parser) String() string

func (*Parser) Unflatten

func (h *Parser) Unflatten(el ir.Element) (values.Value, error)

Unflatten consumes the next available handles and returns a GX value matching the given element.

type Unflattener

type Unflattener interface {
	// Unflatten creates a GX value from the next handles available in the Unflattener.
	Unflatten(handles *Parser) (values.Value, error)
}

Unflattener uses the parser to build GX values.

Jump to

Keyboard shortcuts

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