MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Value

Method Value

tensorflow/go/tensor.go:170–186  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

168// Tensor(int64, 0): int64
169// Tensor(float64, 3): [][][]float64
170func (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//

Calls 11

DataTypeMethod · 0.95
ShapeMethod · 0.95
decodeMethod · 0.95
typeOfFunction · 0.85
tensorDataFunction · 0.85
decodeTensorFunction · 0.85
bugFunction · 0.85
numElementsFunction · 0.85
newStatusFunction · 0.85
InterfaceMethod · 0.80
NewMethod · 0.45