message: Refactor ListDevices in TF Go API
  I pull the logic to convert a *C.TF_DeviceList to a []Device into its own function `deviceSliceFromDeviceList`. This is so I can reuse it when wrapping the Eager C API.
diff: @@ -80,37 +80,30 @@ func (d Device) String() string {
  return fmt.Sprintf("(Device: name \"%s\", type %s, %s)", d.Name, d.Type, memStr)
  }
  -// Return list of devices associated with a Session
  -func (s *Session) ListDevices() ([]Device, error) {
  +func deviceSliceFromDeviceList(list *C.TF_DeviceList) ([]Device, error) {
  var devices []Device
  -
  status := newStatus()
  - devices_list := C.TF_SessionListDevices(s.c, status.c)
  - if err := status.Err(); err != nil {
  - return nil, fmt.Errorf("SessionListDevices() failed: %v", err)
  - }
  - defer C.TF_DeleteDeviceList(devices_list)
  - for i := 0; i < int(C.TF_DeviceListCount(devices_list)); i++ {
  - device_name := C.TF_DeviceListName(devices_list, C.int(i), status.c)
  + for i := 0; i < int(C.TF_DeviceListCount(list)); i++ {
  + name := C.TF_DeviceListName(list, C.int(i), status.c)
  if err := status.Err(); err != nil {
  return nil, fmt.Errorf("DeviceListName(index=%d) failed: %v", i, err)
  }
  - device_type := C.TF_DeviceListType(devices_list, C.int(i), status.c)
  + deviceType := C.TF_DeviceListType(list, C.int(i), status.c)
  if err := status.Err(); err != nil {
  return nil, fmt.Errorf("DeviceListType(index=%d) failed: %v", i, err)
  }
  - memory_limit_bytes := C.TF_DeviceListMemoryBytes(devices_list, C.int(i), status.c)
  + memoryLimitBytes := C.TF_DeviceListMemoryBytes(list, C.int(i), status.c)
  if err := status.Err(); err != nil {
  return nil, fmt.Errorf("DeviceListMemoryBytes(index=%d) failed: %v", i, err)
  }
  device := Device{
  - Name: C.GoString(device_name),
  - Type: C.GoString(device_type),
  - MemoryLimitBytes: int64(memory_limit_bytes),
  + Name: C.GoString(name),
  + Type: C.GoString(deviceType),
  + MemoryLimitBytes: int64(memoryLimitBytes),
  }
  devices = append(devices, device)
  @@ -119,6 +112,17 @@ func (s *Session) ListDevices() ([]Device, error) {
  return devices, nil
  }
  +// ListDevices returns the list of devices associated with a Session.
  +func (s *Session) ListDevices() ([]Device, error) {
  + status := newStatus()
  + devicesList := C.TF_SessionListDevices(s.c, status.c)
  + if err := status.Err(); err != nil {
  + return nil, fmt.Errorf("SessionListDevices() failed: %v", err)
  + }
  + defer C.TF_DeleteDeviceList(devicesList)
  + return deviceSliceFromDeviceList(devicesList)
  +}
  +
  // Run the graph with the associated session starting with the supplied feeds
  // to compute the value of the requested fetches. Runs, but does not return
  // Tensors for operations specified in targets.
  