NewContext creates a new context for eager execution. options may be nil to use the default options.
(options *ContextOptions)
| 77 | // NewContext creates a new context for eager execution. |
| 78 | // options may be nil to use the default options. |
| 79 | func NewContext(options *ContextOptions) (*Context, error) { |
| 80 | status := newStatus() |
| 81 | cOpt, err := options.c() |
| 82 | if err != nil { |
| 83 | return nil, err |
| 84 | } |
| 85 | defer C.TFE_DeleteContextOptions(cOpt) |
| 86 | cContext := C.TFE_NewContext(cOpt, status.c) |
| 87 | if err := status.Err(); err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | |
| 91 | c := &Context{c: cContext} |
| 92 | runtime.SetFinalizer(c, (*Context).finalizer) |
| 93 | return c, nil |
| 94 | } |
| 95 | |
| 96 | func (c *Context) finalizer() { |
| 97 | C.TFE_DeleteContext(c.c) |