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

Function PySeqToTensor

tensorflow/python/lib/core/py_seq_tensor.cc:515–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

513 } while (0)
514
515Status PySeqToTensor(PyObject* obj, DataType dtype, Tensor* ret) {
516 DataType infer_dtype;
517 TensorShape shape;
518 TF_RETURN_IF_ERROR(InferShapeAndType(obj, &shape, &infer_dtype));
519 DataType requested_dtype = DT_INVALID;
520 if (dtype != DT_INVALID) {
521 requested_dtype = dtype;
522 }
523 // NOTE(josh11b): If don't successfully convert to the requested type,
524 // we just try instead to create a tensor of the inferred type and
525 // let the caller convert it to the requested type using a cast
526 // operation.
527 switch (requested_dtype) {
528 case DT_FLOAT:
529 if (ConvertFloat(obj, shape, ret) == nullptr) return Status::OK();
530 break;
531
532 case DT_DOUBLE:
533 if (ConvertDouble(obj, shape, ret) == nullptr) return Status::OK();
534 break;
535
536 case DT_HALF:
537 if (ConvertNumpyHalf(obj, shape, ret) == nullptr) return Status::OK();
538 break;
539
540 case DT_INT64:
541 if (ConvertInt64(obj, shape, ret) == nullptr) return Status::OK();
542 break;
543
544 case DT_INT32:
545 if (ConvertInt32(obj, shape, ret) == nullptr) return Status::OK();
546 break;
547
548 case DT_UINT64:
549 if (ConvertUint64(obj, shape, ret) == nullptr) return Status::OK();
550 break;
551
552 case DT_COMPLEX128:
553 if (ConvertComplex(obj, shape, ret) == nullptr) return Status::OK();
554 break;
555
556 case DT_STRING:
557 if (ConvertString(obj, shape, ret) == nullptr) return Status::OK();
558 break;
559
560 case DT_BOOL:
561 if (ConvertBool(obj, shape, ret) == nullptr) return Status::OK();
562 break;
563
564 default:
565 break;
566 }
567 switch (infer_dtype) {
568 case DT_FLOAT:
569 // TODO(josh11b): Handle mixed floats and complex numbers?
570 if (requested_dtype == DT_INVALID) {
571 // TensorFlow uses float32s to represent floating point numbers
572 // by default (for space and speed over using doubles).

Callers 1

PySeqToTFE_TensorHandleFunction · 0.85

Calls 4

InferShapeAndTypeFunction · 0.85
UnimplementedFunction · 0.85
TensorClass · 0.50
DataTypeStringFunction · 0.50

Tested by

no test coverage detected