!25644 [Fallback] Support builtin type

Merge pull request !25644 from huangbingjian/fallback_set
This commit is contained in:
i-robot 2021-10-30 10:01:52 +00:00 committed by Gitee
commit 45882752ba
2 changed files with 9 additions and 12 deletions

View File

@ -1,6 +1,6 @@
# This is the Python adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
#
# Copyright 2020 Huawei Technologies Co., Ltd
# Copyright 2020-2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -517,6 +517,8 @@ def eval_script(exp_str, params):
obj = eval(exp_str, global_params, local_params)
if obj is None:
raise ValueError(f"When call 'eval', the result is none. exp_str: '{exp_str}'")
if isinstance(obj, set):
obj = tuple(obj)
return obj
@ -611,8 +613,10 @@ class Parser:
def is_unsupported_builtin_type(self, value_type):
"""To check if not supported builtin type"""
logger.debug(f"value_type: {value_type}, {type([])}, {type(())}.")
return value_type in (list, tuple)
unsupported_builtin_type = (list, tuple, set, dict, slice, bool, int, float, str)
is_unsupported = value_type in unsupported_builtin_type
logger.debug(f"value_type: {value_type}, unsupported builtin type: {is_unsupported}.")
return is_unsupported
def is_supported_namespace_module(self, value):
"""To check if the module is allowed to support."""

View File

@ -73,7 +73,6 @@ def test_fallback_bin():
assert foo() == '0b11'
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_bool():
"""
Feature: JIT Fallback
@ -114,7 +113,6 @@ def test_fallback_complex():
assert foo() == (1 + 2j)
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_dict():
"""
Feature: JIT Fallback
@ -141,7 +139,6 @@ def test_fallback_divmod():
assert foo() == (3, 1)
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_float():
"""
Feature: JIT Fallback
@ -183,7 +180,6 @@ def test_fallback_hex():
assert foo() == '0xff'
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_int():
"""
Feature: JIT Fallback
@ -289,7 +285,6 @@ def test_fallback_round():
assert foo() == 1
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_set():
"""
Feature: JIT Fallback
@ -300,10 +295,9 @@ def test_fallback_set():
def foo():
x = set([1, 2, 1])
return x
print(foo())
assert list(foo()) == [1, 2]
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_slice():
"""
Feature: JIT Fallback
@ -315,7 +309,7 @@ def test_fallback_slice():
slice_x = slice(5)
arr = range(10)
return arr[slice_x]
print(foo())
assert list(foo()) == [0, 1, 2, 3, 4]
def test_fallback_sorted():
@ -331,7 +325,6 @@ def test_fallback_sorted():
assert list(foo()) == [1, 2, 3, 4, 5]
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_fallback_str():
"""
Feature: JIT Fallback