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

Class DatasetVariantWrapper

tensorflow/core/framework/dataset.cc:41–87  ·  view source on GitHub ↗

A wrapper class for storing a `DatasetBase` instance in a DT_VARIANT tensor. Objects of the wrapper class own a reference on an instance of `DatasetBase`, and the wrapper's copy constructor and destructor take care of managing the reference count. NOTE(mrry): This is not a feature-complete implementation of the DT_VARIANT specification. In particular, we cannot currently serialize an arbitrary `D

Source from the content-addressed store, hash-verified

39// `DatasetBase` object, so the `Encode()` and `Decode()` methods are not
40// implemented.
41class DatasetVariantWrapper {
42 public:
43 DatasetVariantWrapper() : dataset_(nullptr) {}
44
45 // Transfers ownership of `dataset` to `*this`.
46 explicit DatasetVariantWrapper(DatasetBase* dataset) : dataset_(dataset) {}
47
48 DatasetVariantWrapper(const DatasetVariantWrapper& other)
49 : dataset_(other.dataset_) {
50 if (dataset_) dataset_->Ref();
51 }
52
53 DatasetVariantWrapper& operator=(DatasetVariantWrapper&& other) {
54 if (&other == this) return *this;
55 std::swap(dataset_, other.dataset_);
56 return *this;
57 }
58
59 DatasetVariantWrapper& operator=(const DatasetVariantWrapper& other) = delete;
60
61 ~DatasetVariantWrapper() {
62 if (dataset_) dataset_->Unref();
63 }
64
65 DatasetBase* get() const { return dataset_; }
66
67 string TypeName() const { return "tensorflow::DatasetVariantWrapper"; }
68 string DebugString() const {
69 if (dataset_) {
70 return dataset_->DebugString();
71 } else {
72 return "<Uninitialized DatasetVariantWrapper>";
73 }
74 }
75 void Encode(VariantTensorData* data) const {
76 LOG(ERROR) << "The Encode() method is not implemented for "
77 "DatasetVariantWrapper objects.";
78 }
79 bool Decode(const VariantTensorData& data) {
80 LOG(ERROR) << "The Decode() method is not implemented for "
81 "DatasetVariantWrapper objects.";
82 return false;
83 }
84
85 private:
86 DatasetBase* dataset_; // Owns one reference.
87};
88
89const char kWrappedDatasetVariantTypeName[] =
90 "tensorflow::data::WrappedDatasetVariant";

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected