| 2174 | } |
| 2175 | |
| 2176 | bool CheckInputsOk(PyObject* seq, int start_index, |
| 2177 | const tensorflow::OpDef& op_def) { |
| 2178 | for (int i = 0; i < op_def.input_arg_size(); i++) { |
| 2179 | PyObject* item = PyTuple_GET_ITEM(seq, i + start_index); |
| 2180 | if (!op_def.input_arg(i).number_attr().empty() || |
| 2181 | !op_def.input_arg(i).type_list_attr().empty()) { |
| 2182 | // This item should be a seq input. |
| 2183 | if (!PySequence_Check(item)) { |
| 2184 | VLOG(1) << "Falling back to slow path for Op \"" << op_def.name() |
| 2185 | << "\", Input \"" << op_def.input_arg(i).name() |
| 2186 | << "\" since we expected a sequence, but got " |
| 2187 | << item->ob_type->tp_name; |
| 2188 | return false; |
| 2189 | } |
| 2190 | tensorflow::Safe_PyObjectPtr fast_item( |
| 2191 | PySequence_Fast(item, "Could not parse sequence.")); |
| 2192 | if (fast_item.get() == nullptr) { |
| 2193 | return false; |
| 2194 | } |
| 2195 | for (Py_ssize_t j = 0; j < PySequence_Fast_GET_SIZE(fast_item.get()); |
| 2196 | j++) { |
| 2197 | PyObject* inner_item = PySequence_Fast_GET_ITEM(fast_item.get(), j); |
| 2198 | if (!CheckOneInput(inner_item)) { |
| 2199 | VLOG(1) << "Falling back to slow path for Op \"" << op_def.name() |
| 2200 | << "\", Input \"" << op_def.input_arg(i).name() |
| 2201 | << "\", Index " << j |
| 2202 | << " since we expected an EagerTensor/ResourceVariable, " |
| 2203 | "but got " |
| 2204 | << inner_item->ob_type->tp_name; |
| 2205 | return false; |
| 2206 | } |
| 2207 | } |
| 2208 | } else if (!CheckOneInput(item)) { |
| 2209 | VLOG(1) |
| 2210 | << "Falling back to slow path for Op \"" << op_def.name() |
| 2211 | << "\", Input \"" << op_def.input_arg(i).name() |
| 2212 | << "\" since we expected an EagerTensor/ResourceVariable, but got " |
| 2213 | << item->ob_type->tp_name; |
| 2214 | return false; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | return true; |
| 2219 | } |
| 2220 | |
| 2221 | tensorflow::DataType MaybeGetDType(PyObject* item) { |
| 2222 | if (EagerTensor_CheckExact(item) || CheckResourceVariable(item)) { |
no test coverage detected