Back to godoc.org

Package xvm

v0.9.14
Latest Go to latest

The latest major version is .

Published: Sep 10, 2020 | License: Apache-2.0 | Module: gorgonia.org/gorgonia

Index

Examples

func CloseTracing

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

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

WithTracing initializes a tracing channel and adds it to the context

Example

Code:

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)

type Doer

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

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

type Machine

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

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

func NewMachine

func NewMachine(g *gorgonia.ExprGraph) *Machine

NewMachine creates an exeuction machine from an exprgraph

func (*Machine) Close

func (m *Machine) Close()

Close all the plumbing to avoid leaking

func (*Machine) GetResult

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

GetResult stored in a node

func (*Machine) Run

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

Run the computation

Example

Code:

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()))
42

type Trace

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier