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

Method decode

tensorflow/go/tensor.go:434–465  ·  view source on GitHub ↗
(ptr reflect.Value, shape []int64)

Source from the content-addressed store, hash-verified

432}
433
434func (d *stringDecoder) decode(ptr reflect.Value, shape []int64) error {
435 if len(shape) == 0 {
436 var offset uint64
437 if err := binary.Read(d.offsets, nativeEndian, &offset); err != nil {
438 return err
439 }
440 var (
441 src = (*C.char)(unsafe.Pointer(&d.data[offset]))
442 srcLen = C.size_t(len(d.data)) - C.size_t(offset)
443 dst *C.char
444 dstLen C.size_t
445 )
446 if offset > uint64(len(d.data)) {
447 return fmt.Errorf("invalid offsets in String Tensor")
448 }
449 C.TF_StringDecode(src, srcLen, &dst, &dstLen, d.status.c)
450 if err := d.status.Err(); err != nil {
451 return err
452 }
453 s := ptr.Interface().(*string)
454 *s = C.GoStringN(dst, C.int(dstLen))
455 return nil
456 }
457 val := reflect.Indirect(ptr)
458 val.Set(reflect.MakeSlice(typeOf(String, shape), int(shape[0]), int(shape[0])))
459 for i := 0; i < val.Len(); i++ {
460 if err := d.decode(val.Index(i).Addr(), shape[1:]); err != nil {
461 return err
462 }
463 }
464 return nil
465}
466
467func bug(format string, args ...interface{}) error {
468 return fmt.Errorf("BUG: Please report at https://github.com/tensorflow/tensorflow/issues with the note: Go TensorFlow %v: %v", Version(), fmt.Sprintf(format, args...))

Callers 1

ValueMethod · 0.95

Calls 6

typeOfFunction · 0.85
InterfaceMethod · 0.80
ReadMethod · 0.45
ErrMethod · 0.45
SetMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected