| 185 | } |
| 186 | |
| 187 | string GenEagerPythonOp::FlattenInputs( |
| 188 | const std::vector<int>* input_indices, |
| 189 | std::vector<string>* output_sizes) const { |
| 190 | string inputs; |
| 191 | enum { STARTING, WAS_LIST_INPUT, WAS_SOLO_INPUT } inputs_state = STARTING; |
| 192 | const int n = input_indices != nullptr ? input_indices->size() |
| 193 | : op_def_.input_arg_size(); |
| 194 | for (int j = 0; j < n; ++j) { |
| 195 | const int i = input_indices ? (*input_indices)[j] : j; |
| 196 | const auto& arg(op_def_.input_arg(i)); |
| 197 | const bool is_list = |
| 198 | !arg.type_list_attr().empty() || !arg.number_attr().empty(); |
| 199 | if (is_list) { |
| 200 | if (inputs_state == WAS_SOLO_INPUT) { |
| 201 | strings::StrAppend(&inputs, "] + "); |
| 202 | } else if (inputs_state == WAS_LIST_INPUT) { |
| 203 | strings::StrAppend(&inputs, " + "); |
| 204 | } |
| 205 | strings::StrAppend(&inputs, "list(", param_names_[i].GetRenameTo(), ")"); |
| 206 | inputs_state = WAS_LIST_INPUT; |
| 207 | if (output_sizes != nullptr) { |
| 208 | if (!arg.number_attr().empty()) { |
| 209 | output_sizes->emplace_back(AttrVarName(arg.number_attr(), nullptr)); |
| 210 | } else { |
| 211 | output_sizes->emplace_back( |
| 212 | strings::StrCat("len(", param_names_[i].GetRenameTo(), ")")); |
| 213 | } |
| 214 | } |
| 215 | } else { |
| 216 | if (inputs_state == WAS_SOLO_INPUT) { |
| 217 | strings::StrAppend(&inputs, ", "); |
| 218 | } else if (inputs_state == WAS_LIST_INPUT) { |
| 219 | strings::StrAppend(&inputs, " + ["); |
| 220 | } else { |
| 221 | strings::StrAppend(&inputs, "["); |
| 222 | } |
| 223 | strings::StrAppend(&inputs, param_names_[i].GetRenameTo()); |
| 224 | inputs_state = WAS_SOLO_INPUT; |
| 225 | if (output_sizes != nullptr) output_sizes->emplace_back(); |
| 226 | } |
| 227 | } |
| 228 | if (inputs_state == STARTING) return "[]"; |
| 229 | if (inputs_state == WAS_SOLO_INPUT) { |
| 230 | strings::StrAppend(&inputs, "]"); |
| 231 | } |
| 232 | return inputs; |
| 233 | } |
| 234 | |
| 235 | string GenEagerPythonOp::Code() { |
| 236 | if (api_def_.visibility() == ApiDef::SKIP) { |
nothing calls this directly
no test coverage detected