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_identity_is.py 1.6 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2021 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. """ test syntax for logic expression """
  16. import mindspore.nn as nn
  17. from mindspore import context
  18. context.set_context(mode=context.GRAPH_MODE)
  19. class IdentityIs(nn.Cell):
  20. def __init__(self, x, y):
  21. super(IdentityIs, self).__init__()
  22. self.x = x
  23. self.y = y
  24. def construct(self):
  25. in_v = self.x is self.y
  26. return in_v
  27. def test_ms_syntax_operator_int_is_int():
  28. net = IdentityIs(1, 2)
  29. ret = net()
  30. print(ret)
  31. def test_ms_syntax_operator_int_is_none():
  32. net = IdentityIs(1, None)
  33. ret = net()
  34. print(ret)
  35. def test_ms_syntax_operator_int_is_true():
  36. net = IdentityIs(1, True)
  37. ret = net()
  38. print(ret)
  39. def test_ms_syntax_operator_bool_is_none():
  40. net = IdentityIs(True, None)
  41. ret = net()
  42. print(ret)
  43. def test_ms_syntax_operator_bool_is_false():
  44. net = IdentityIs(True, False)
  45. ret = net()
  46. print(ret)