Variant compatible type for a list of tensors. This is mutable but instances should never be mutated after stored in a variant tensor. NOTE**: TensorList stores a refcounted container of tf::Tensor objects, which are accessible via TensorList::tensors(). Because it is refcounted, straight copies of the form: TensorList b = a; b.tensors().push_back(t); // WARNING: This modifies a.tensors(). Do
| 80 | // } |
| 81 | // |
| 82 | class TensorList { |
| 83 | public: |
| 84 | TensorList() : tensors_(new Tensors) {} |
| 85 | ~TensorList(); |
| 86 | |
| 87 | TensorList(const TensorList& other) |
| 88 | : element_shape(other.element_shape), |
| 89 | element_dtype(other.element_dtype), |
| 90 | max_num_elements(other.max_num_elements), |
| 91 | tensors_(other.tensors_) { |
| 92 | tensors_->Ref(); |
| 93 | } |
| 94 | |
| 95 | TensorList(TensorList&& rhs) |
| 96 | : element_shape(std::move(rhs.element_shape)), |
| 97 | element_dtype(rhs.element_dtype), |
| 98 | max_num_elements(rhs.max_num_elements), |
| 99 | tensors_(rhs.tensors_) { |
| 100 | rhs.tensors_ = nullptr; |
| 101 | } |
| 102 | |
| 103 | TensorList& operator=(const TensorList& rhs) { |
| 104 | if (this == &rhs) return *this; |
| 105 | element_shape = rhs.element_shape; |
| 106 | element_dtype = rhs.element_dtype; |
| 107 | max_num_elements = rhs.max_num_elements; |
| 108 | tensors_->Unref(); |
| 109 | tensors_ = rhs.tensors_; |
| 110 | tensors_->Ref(); |
| 111 | return *this; |
| 112 | } |
| 113 | |
| 114 | TensorList& operator=(TensorList&& rhs) { |
| 115 | if (this == &rhs) return *this; |
| 116 | element_shape = rhs.element_shape; |
| 117 | element_dtype = rhs.element_dtype; |
| 118 | max_num_elements = rhs.max_num_elements; |
| 119 | std::swap(tensors_, rhs.tensors_); |
| 120 | return *this; |
| 121 | } |
| 122 | |
| 123 | static const char kTypeName[]; |
| 124 | |
| 125 | string TypeName() const { return kTypeName; } |
| 126 | |
| 127 | void Encode(VariantTensorData* data) const; |
| 128 | |
| 129 | bool Decode(const VariantTensorData& data); |
| 130 | |
| 131 | // TODO(apassos) fill this out |
| 132 | string DebugString() const { return "TensorList"; } |
| 133 | |
| 134 | PartialTensorShape element_shape; |
| 135 | |
| 136 | DataType element_dtype; |
| 137 | |
| 138 | // The maximum allowed size of `tensors`. Defaults to -1 meaning that the size |
| 139 | // of `tensors` is unbounded. |
no test coverage detected