xvm

package
v0.9.18 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseTracing added in v0.9.14

func CloseTracing(ctx context.Context)

CloseTracing the tracing channel to avoid context leak. it is a nil op if context does not carry tracing information

func WithTracing added in v0.9.14

func WithTracing(parent context.Context) (context.Context, <-chan Trace)

WithTracing initializes a tracing channel and adds it to the context

Example
ctx, tracingC := WithTracing(context.Background())
defer CloseTracing(ctx)
go func() {
	for t := range tracingC {
		fmt.Println(t)
	}
}()
g := gorgonia.NewGraph()
// add operations etc...
machine := NewMachine(g)
defer machine.Close()
machine.Run(ctx)
Output:

Types

type Doer added in v0.9.13

type Doer interface {
	Do(...gorgonia.Value) (gorgonia.Value, error)
}

Doer is implementing the Do method of gorgonia's Op interface

type Machine added in v0.9.13

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

Machine is a top-level struture that will coordinate the execution of a graph

func NewMachine added in v0.9.13

func NewMachine(g *gorgonia.ExprGraph) *Machine

NewMachine creates an exeuction machine from an exprgraph

func (*Machine) Close added in v0.9.13

func (m *Machine) Close()

Close all the plumbing to avoid leaking

func (*Machine) GetResult added in v0.9.13

func (m *Machine) GetResult(id int64) gorgonia.Value

GetResult stored in a node

func (*Machine) Run added in v0.9.13

func (m *Machine) Run(ctx context.Context) error

Run the computation

Example
g := gorgonia.NewGraph()
forty := gorgonia.F32(40.0)
//fortyTwo := gorgonia.F32(42.0)
two := gorgonia.F32(2.0)
n1 := gorgonia.NewScalar(g, gorgonia.Float32, gorgonia.WithValue(&forty), gorgonia.WithName("n1"))
n2 := gorgonia.NewScalar(g, gorgonia.Float32, gorgonia.WithValue(&two), gorgonia.WithName("n2"))

added, err := gorgonia.Add(n1, n2)
if err != nil {
	log.Fatal(err)
}
machine := NewMachine(g)
ctx, cancel := context.WithTimeout(context.Background(), 1000*time.Millisecond)
defer cancel()
defer machine.Close()
err = machine.Run(ctx)
if err != nil {
	log.Fatal(err)
}
fmt.Println(machine.GetResult(added.ID()))
Output:

42

type Trace added in v0.9.14

type Trace struct {
	//fmt.Println(runtime.FuncForPC(reflect.ValueOf(state).Pointer()).Name())
	StateFunction string
	ID            int64
	Start         time.Time
	End           time.Time `json:",omitempty"`
}

Trace the nodes states

Jump to

Keyboard shortcuts

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