diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index 5f4f9ad4d21..881c0415bbe 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -1945,6 +1945,38 @@ FunctionBlockPtr Parser::ParseFor(const FunctionBlockPtr &block, const py::objec return ParseForUnroll(block, node); } +AnfNodePtr Parser::ConvertInterpretIterNodeToList(const FunctionBlockPtr &block, const AnfNodePtr &iter_node, + const py::object iter_obj) { + // For interpret iter_node, convert it to list. xs --> list(xs). + py::object iter_id = python_adapter::GetPyObjAttr(iter_obj, "id"); + if (!py::isinstance(iter_id)) { + // If variable is assigned, for example: + // xs = np.array([1, 2, 3, 4]) + // for x in xs + const std::string &iter_id_str = iter_id.cast(); + return MakeInterpretNode(block, iter_node, "list(" + iter_id_str + ")"); + } + // If variable is not assigned, for example: + // for x in np.array([1, 2, 3, 4]) + const auto &interpret_iter_node = + IsPrimitiveCNode(iter_node, prim::kPrimPyInterpret) ? iter_node : HandleInterpret(block, iter_node, iter_obj); + constexpr size_t script_index = 1; + auto iter_cnode = interpret_iter_node->cast(); + MS_EXCEPTION_IF_NULL(iter_cnode); + auto iter_cnode_inputs = iter_cnode->inputs(); + auto iter_script_input = iter_cnode_inputs[script_index]; + if (!IsValueNode