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

Class TensorVector

tensorflow/core/util/example_proto_fast_parsing.cc:971–1000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

969// vactor and then copy the data over.
970template <typename T>
971class TensorVector {
972 public:
973 using value_type = T;
974
975 const Tensor& tensor() {
976 if (!tensor_.has_value()) {
977 resize(0);
978 }
979 return *tensor_;
980 }
981
982 int64 size() const {
983 return tensor_.has_value() ? tensor_->NumElements() : 0;
984 }
985 void resize(int64 new_size) {
986 DCHECK(!tensor_.has_value());
987 tensor_ = Tensor(DataTypeToEnum<T>::v(), TensorShape({new_size}));
988 data_ = tensor_->flat<T>().data();
989 }
990 T* data() { return data_; }
991 const T* data() const { return data_; }
992
993 private:
994 // Use absl::optional to avoid calling the default constructor of Tensor
995 // unnecessarily.
996 absl::optional<Tensor> tensor_;
997
998 // Cached pointer to the raw data inside the tensor.
999 T* data_ = nullptr;
1000};
1001
1002} // namespace
1003

Callers 2

IsSimplifiableReshapeMethod · 0.85
SimplifyReductionMethod · 0.85

Calls 2

resizeFunction · 0.85
has_valueMethod · 0.45

Tested by

no test coverage detected