ImportWithOptions imports the nodes and edges from a serialized representation of another Graph into g. Multiple options can be specified for the newly imported nodes.
(def []byte, options GraphImportOptions)
| 104 | // |
| 105 | // Multiple options can be specified for the newly imported nodes. |
| 106 | func (g *Graph) ImportWithOptions(def []byte, options GraphImportOptions) error { |
| 107 | cprefix := C.CString(options.Prefix) |
| 108 | defer C.free(unsafe.Pointer(cprefix)) |
| 109 | |
| 110 | opts := C.TF_NewImportGraphDefOptions() |
| 111 | defer C.TF_DeleteImportGraphDefOptions(opts) |
| 112 | C.TF_ImportGraphDefOptionsSetPrefix(opts, cprefix) |
| 113 | |
| 114 | if len(options.Device) != 0 { |
| 115 | cdev := C.CString(options.Device) |
| 116 | defer C.free(unsafe.Pointer(cdev)) |
| 117 | C.TF_ImportGraphDefOptionsSetDefaultDevice(opts, cdev) |
| 118 | } |
| 119 | |
| 120 | buf := C.TF_NewBuffer() |
| 121 | defer C.TF_DeleteBuffer(buf) |
| 122 | // Would have preferred to use C.CBytes, but that does not play well |
| 123 | // with "go vet" till https://github.com/golang/go/issues/17201 is |
| 124 | // resolved. |
| 125 | buf.length = C.size_t(len(def)) |
| 126 | buf.data = C.malloc(buf.length) |
| 127 | if buf.data == nil { |
| 128 | return fmt.Errorf("unable to allocate memory") |
| 129 | } |
| 130 | defer C.free(buf.data) |
| 131 | C.memcpy(buf.data, unsafe.Pointer(&def[0]), buf.length) |
| 132 | |
| 133 | status := newStatus() |
| 134 | |
| 135 | C.TF_GraphImportGraphDef(g.c, buf, opts, status.c) |
| 136 | if err := status.Err(); err != nil { |
| 137 | return err |
| 138 | } |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | // Import imports the nodes and edges from a serialized representation of |
| 144 | // another Graph into g. |