• 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 #include "tensorflow/core/kernels/data/name_utils.h"
16 
17 #include "absl/strings/str_join.h"
18 
19 namespace tensorflow {
20 namespace data {
21 namespace name_utils {
22 
23 ABSL_CONST_INIT const char kDelimiter[] = "::";
24 ABSL_CONST_INIT const char kDefaultDatasetDebugStringPrefix[] = "";
25 
26 constexpr char kDataset[] = "Dataset";
27 constexpr char kOp[] = "Op";
28 constexpr char kVersion[] = "V";
29 
OpName(const string & dataset_type)30 string OpName(const string& dataset_type) {
31   return OpName(dataset_type, OpNameParams());
32 }
33 
OpName(const string & dataset_type,const OpNameParams & params)34 string OpName(const string& dataset_type, const OpNameParams& params) {
35   if (params.op_version == 1) {
36     return strings::StrCat(dataset_type, kDataset);
37   }
38   return strings::StrCat(dataset_type, kDataset, kVersion, params.op_version);
39 }
40 
ArgsToString(const std::vector<string> & args)41 string ArgsToString(const std::vector<string>& args) {
42   if (args.empty()) {
43     return "";
44   }
45   return strings::StrCat("(", absl::StrJoin(args, ", "), ")");
46 }
47 
DatasetDebugString(const string & dataset_type)48 string DatasetDebugString(const string& dataset_type) {
49   return DatasetDebugString(dataset_type, DatasetDebugStringParams());
50 }
51 
DatasetDebugString(const string & dataset_type,const DatasetDebugStringParams & params)52 string DatasetDebugString(const string& dataset_type,
53                           const DatasetDebugStringParams& params) {
54   OpNameParams op_name_params;
55   op_name_params.op_version = params.op_version;
56   string op_name = OpName(dataset_type, op_name_params);
57   return strings::StrCat(op_name, kOp, ArgsToString(params.args), kDelimiter,
58                          params.dataset_prefix, kDataset);
59 }
60 
IteratorPrefix(const string & dataset_type,const string & prefix)61 string IteratorPrefix(const string& dataset_type, const string& prefix) {
62   return IteratorPrefix(dataset_type, prefix, IteratorPrefixParams());
63 }
64 
IteratorPrefix(const string & dataset_type,const string & prefix,const IteratorPrefixParams & params)65 string IteratorPrefix(const string& dataset_type, const string& prefix,
66                       const IteratorPrefixParams& params) {
67   if (params.op_version == 1) {
68     return strings::StrCat(prefix, kDelimiter, params.dataset_prefix,
69                            dataset_type);
70   }
71   return strings::StrCat(prefix, kDelimiter, params.dataset_prefix,
72                          dataset_type, kVersion, params.op_version);
73 }
74 
75 }  // namespace name_utils
76 }  // namespace data
77 }  // namespace tensorflow
78