• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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_CORE_KERNELS_DATA_NAME_UTILS_H_
16 #define TENSORFLOW_CORE_KERNELS_DATA_NAME_UTILS_H_
17 
18 #include <vector>
19 
20 #include "tensorflow/core/lib/strings/strcat.h"
21 #include "tensorflow/core/platform/types.h"
22 
23 namespace tensorflow {
24 namespace data {
25 namespace name_utils {
26 
27 extern const char kDelimiter[];
28 extern const char kDefaultDatasetDebugStringPrefix[];
29 
30 struct OpNameParams {
31   int op_version = 1;
32 };
33 
34 struct DatasetDebugStringParams {
35   template <typename... T>
set_argsDatasetDebugStringParams36   void set_args(T... input_args) {
37     args = {static_cast<const strings::AlphaNum&>(input_args).data()...};
38   }
39 
40   int op_version = 1;
41   string dataset_prefix = "";
42   std::vector<string> args;
43 };
44 
45 struct IteratorPrefixParams {
46   int op_version = 1;
47   string dataset_prefix = "";
48 };
49 
50 // Merge the given args in the format of "(arg1, arg2, ..., argn)".
51 //
52 // e.g. ArgsToString({"1", "2", "3"}) -> "(1, 2, 3)"; ArgsToString({}) -> "".
53 string ArgsToString(const std::vector<string>& args);
54 
55 // Returns the dataset op name.
56 //
57 // e.g. OpName("Map") -> "MapDataset".
58 string OpName(const string& dataset_type);
59 
60 // Returns the dataset op names.
61 //
62 // e.g. OpName(ConcatenateDatasetOp::kDatasetType, OpNameParams())
63 // -> "ConcatenateDataset"
64 //
65 // OpNameParams params;
66 // params.op_version = 2;
67 // OpName(ParallelInterleaveDatasetOp::kDatasetType, params)
68 // -> "ParallelInterleaveDatasetV2"
69 string OpName(const string& dataset_type, const OpNameParams& params);
70 
71 // Returns a human-readable debug string for this dataset in the format of
72 // "FooDatasetOp(arg1, arg2, ...)::Dataset".
73 //
74 // e.g. DatasetDebugString("Map") -> "MapDatasetOp::Dataset";
75 string DatasetDebugString(const string& dataset_type);
76 
77 // Returns a human-readable debug string for this dataset in the format of
78 // "FooDatasetOp(arg1, arg2, ...)::Dataset".
79 //
80 // e.g.
81 //  DatasetDebugStringParams range_params;
82 //  range_params.set_args(0, 10, 3);
83 //  DatasetDebugString(RangeDatasetOp::kDatasetType, range_params)
84 //  -> "RangeDatasetOp(0, 10, 3)::Dataset");
85 string DatasetDebugString(const string& dataset_type,
86                           const DatasetDebugStringParams& params);
87 
88 // Returns a string that identifies the sequence of iterators leading up to
89 // the iterator of this dataset.
90 //
91 // e.g. IteratorPrefix("Map", "Iterator::Range") -> "Iterator::Range::Map".
92 string IteratorPrefix(const string& dataset_type, const string& prefix);
93 
94 // Returns a string that identifies the sequence of iterators leading up to
95 // the iterator of this dataset.
96 //
97 // e.g.
98 // IteratorPrefixParams params;
99 // params.op_version = 2;
100 // IteratorPrefix(BatchDatasetOp::KDatasetType, "Iterator::Range", params) ->
101 // "Iterator::Range::BatchV2".
102 string IteratorPrefix(const string& dataset_type, const string& prefix,
103                       const IteratorPrefixParams& params);
104 
105 }  // namespace name_utils
106 }  // namespace data
107 }  // namespace tensorflow
108 
109 #endif  // TENSORFLOW_CORE_KERNELS_DATA_NAME_UTILS_H_
110