You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_fun_fun.py 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. import pytest
  16. import mindspore.context as context
  17. from mindspore import Tensor, ms_function
  18. from mindspore.common import dtype as mstype
  19. @ms_function
  20. def hof(x):
  21. def f(x):
  22. return x + 3
  23. def k(x):
  24. return x - 1
  25. def g(x):
  26. if x < 5:
  27. return f
  28. return k
  29. ret = g(x)(x)
  30. return ret
  31. @pytest.mark.level0
  32. @pytest.mark.platform_arm_ascend_training
  33. @pytest.mark.platform_x86_ascend_training
  34. @pytest.mark.env_onecard
  35. def test_fun_fun():
  36. context.set_context(mode=context.GRAPH_MODE)
  37. x = Tensor([10], mstype.int32)
  38. ret = hof(x)
  39. expect = Tensor([9], mstype.int32)
  40. assert ret == expect
  41. if __name__ == "__main__":
  42. test_fun_fun()