forked from mindspore-Ecosystem/mindspore
!27642 Before resolve getitem, check if the index is ValueNode.
Merge pull request !27642 from 张清华/opt_cell_list_getattr2
This commit is contained in:
commit
40b10cad65
|
@ -69,9 +69,9 @@ AnfNodePtr Resolver::operator()(const OptimizerPtr &optimizer, const AnfNodePtr
|
||||||
if (is_getattr_getitem) {
|
if (is_getattr_getitem) {
|
||||||
constexpr size_t resolve_index = 1;
|
constexpr size_t resolve_index = 1;
|
||||||
auto resolve_node = getitem_cnode->input(resolve_index);
|
auto resolve_node = getitem_cnode->input(resolve_index);
|
||||||
if (IsPrimitiveCNode(resolve_node, prim::kPrimResolve)) {
|
constexpr size_t position_index = 2;
|
||||||
constexpr size_t position_index = 2;
|
auto index_node = getitem_cnode->input(position_index);
|
||||||
auto index_node = getitem_cnode->input(position_index);
|
if (IsPrimitiveCNode(resolve_node, prim::kPrimResolve) && index_node->isa<ValueNode>()) {
|
||||||
auto [name_space, symbol] = parse::GetNamespaceAndSymbol(resolve_node);
|
auto [name_space, symbol] = parse::GetNamespaceAndSymbol(resolve_node);
|
||||||
auto py_item = parse::GetItemObjectFromSequence(name_space, symbol, resolve_node, index_node);
|
auto py_item = parse::GetItemObjectFromSequence(name_space, symbol, resolve_node, index_node);
|
||||||
return parse::ResolveCellWithAttr(optimizer->manager(), py_item, resolve_node, attr);
|
return parse::ResolveCellWithAttr(optimizer->manager(), py_item, resolve_node, attr);
|
||||||
|
|
|
@ -331,7 +331,12 @@ py::object GetItemObjectFromSequence(const NameSpacePtr &name_space, const Symbo
|
||||||
|
|
||||||
const std::string fn = PYTHON_MOD_GET_ITEM_FROM_SEQUENCE;
|
const std::string fn = PYTHON_MOD_GET_ITEM_FROM_SEQUENCE;
|
||||||
const std::string module = "mindspore._extends.parse.parser";
|
const std::string module = "mindspore._extends.parse.parser";
|
||||||
int index = GetValueNode<Int64ImmPtr>(index_node)->value();
|
auto imm_value = GetValueNode<Int64ImmPtr>(index_node);
|
||||||
|
if (imm_value == nullptr) {
|
||||||
|
MS_LOG(EXCEPTION) << "Expect a int64 value node, node: " << node->DebugString()
|
||||||
|
<< ", index_node: " << index_node->DebugString();
|
||||||
|
}
|
||||||
|
int index = imm_value->value();
|
||||||
MS_LOG(DEBUG) << "obj: " << py::str(obj) << ", index: " << index;
|
MS_LOG(DEBUG) << "obj: " << py::str(obj) << ", index: " << index;
|
||||||
py::object item_obj = parse::python_adapter::GetPyFn(module, fn)(obj, py::int_(index));
|
py::object item_obj = parse::python_adapter::GetPyFn(module, fn)(obj, py::int_(index));
|
||||||
return item_obj;
|
return item_obj;
|
||||||
|
|
Loading…
Reference in New Issue