1/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15#ifndef TENSORFLOW_CORE_DATA_NAME_UTILS_H_
16#define TENSORFLOW_CORE_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
23namespace tensorflow {
24namespace data {
25namespace name_utils {
26
27extern const char kDelimiter[];
28extern const char kDefaultDatasetDebugStringPrefix[];
29
30struct OpNameParams {
31 int op_version = 1;
32};
33
34struct DatasetDebugStringParams {
35 template <typename... T>
36 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
45struct 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({}) -> "".
53string ArgsToString(const std::vector<string>& args);
54
55// Returns the dataset op name.
56//
57// e.g. OpName("Map") -> "MapDataset".
58string 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"
69string 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";
75string 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");
85string 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".
92string 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".
102string 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_DATA_NAME_UTILS_H_
110