Value converts the Tensor to a Go value. For now, not all Tensor types are supported, and this function may panic if it encounters an unsupported DataType. The type of the output depends on the Tensor type and dimensions. For example: Tensor(int64, 0): int64 Tensor(float64, 3): [][][]float64
()
| 168 | // Tensor(int64, 0): int64 |
| 169 | // Tensor(float64, 3): [][][]float64 |
| 170 | func (t *Tensor) Value() interface{} { |
| 171 | typ := typeOf(t.DataType(), t.Shape()) |
| 172 | val := reflect.New(typ) |
| 173 | raw := tensorData(t.c) |
| 174 | if t.DataType() != String { |
| 175 | if err := decodeTensor(bytes.NewReader(raw), t.Shape(), typ, val); err != nil { |
| 176 | panic(bug("unable to decode Tensor of type %v and shape %v - %v", t.DataType(), t.Shape(), err)) |
| 177 | } |
| 178 | } else { |
| 179 | nflattened := numElements(t.Shape()) |
| 180 | d := stringDecoder{offsets: bytes.NewReader(raw[0 : 8*nflattened]), data: raw[8*nflattened:], status: newStatus()} |
| 181 | if err := d.decode(val, t.Shape()); err != nil { |
| 182 | panic(bug("unable to decode String tensor with shape %v - %v", t.Shape(), err)) |
| 183 | } |
| 184 | } |
| 185 | return reflect.Indirect(val).Interface() |
| 186 | } |
| 187 | |
| 188 | // WriteContentsTo writes the serialized contents of t to w. |
| 189 | // |