xref: /aosp_15_r20/external/tensorflow/tensorflow/c/experimental/saved_model/core/tensor_spec.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2020 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 
16 #ifndef TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_TENSOR_SPEC_H_
17 #define TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_TENSOR_SPEC_H_
18 
19 #include "tensorflow/core/framework/tensor_shape.h"
20 #include "tensorflow/core/framework/types.pb.h"
21 #include "tensorflow/core/protobuf/struct.pb.h"
22 
23 namespace tensorflow {
24 
25 // Note(bmzhao): TensorSpec deliberately does not store the "name" from a
26 // TensorSpecProto. From edloper@, "Names should really be associated with
27 // parameters, not the tensors inside those parameters. This would be
28 // inconsistent with the corresponding Python class, but I don't think that's
29 // necessarily a problem. If it turns out later that we really need a name
30 // attribute here, we can always add it back in; but let's see how far we can
31 // get without it."
32 class TensorSpec {
33  public:
34   // Constructs a scalar, DT_FLOAT TensorSpec
35   TensorSpec();
36 
37   TensorSpec(PartialTensorShape shape, DataType dtype);
38 
39   explicit TensorSpec(const TensorSpecProto& proto);
40 
41   const PartialTensorShape& shape() const;
42   DataType dtype() const;
43 
44  private:
45   PartialTensorShape shape_;
46   DataType dtype_;
47 };
48 
49 }  // namespace tensorflow
50 
51 #endif  // TENSORFLOW_C_EXPERIMENTAL_SAVED_MODEL_CORE_TENSOR_SPEC_H_
52