1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_CC_EXPERIMENTAL_LIBTF_IMPL_TENSOR_SPEC_H_ 16 #define TENSORFLOW_CC_EXPERIMENTAL_LIBTF_IMPL_TENSOR_SPEC_H_ 17 18 #include <iosfwd> 19 20 #include "tensorflow/core/framework/tensor_shape.h" 21 #include "tensorflow/core/framework/types.pb.h" 22 23 namespace tf { 24 namespace libtf { 25 namespace impl { 26 /// @brief The TensorSpec struct. 27 /// 28 /// The TensorSpec describes the shape and dtype of a Tensor. 29 30 struct TensorSpec { 31 tensorflow::PartialTensorShape shape; 32 tensorflow::DataType dtype; 33 34 bool operator==(const TensorSpec& o) const { 35 return dtype == o.dtype && shape.IsIdenticalTo(o.shape); 36 } 37 38 /// Overload AbslHashValue to make TensorSpec hashable. 39 template <typename H> AbslHashValueTensorSpec40 friend H AbslHashValue(H h, const TensorSpec& t) { 41 return H::combine(std::move(h), t.shape.DebugString(), t.dtype); 42 } 43 }; 44 45 // Defined in `iostream.cc`. 46 std::ostream& operator<<(std::ostream& o, const TensorSpec& x); 47 48 } // namespace impl 49 } // namespace libtf 50 } // namespace tf 51 52 #endif // TENSORFLOW_CC_EXPERIMENTAL_LIBTF_IMPL_TENSOR_SPEC_H_ 53