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_isfinite_op.py 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 numpy as np
  16. import pytest
  17. import mindspore.context as context
  18. import mindspore.nn as nn
  19. from mindspore import Tensor
  20. from mindspore.ops import operations as P
  21. context.set_context(mode=context.GRAPH_MODE, device_target='CPU')
  22. class Net(nn.Cell):
  23. def __init__(self):
  24. super(Net, self).__init__()
  25. self.ops = P.IsFinite()
  26. def construct(self, x):
  27. return self.ops(x)
  28. @pytest.mark.level0
  29. @pytest.mark.platform_x86_cpu_training
  30. @pytest.mark.env_onecard
  31. def test_net():
  32. x0 = Tensor(np.array([np.log(-1), 0.4, np.log(0)]).astype(np.float16))
  33. x1 = Tensor(np.array([np.log(-1), 0.4, np.log(0)]).astype(np.float32))
  34. x2 = Tensor(np.array([np.log(-1), 0.4, np.log(0)]).astype(np.float64))
  35. x3 = Tensor(np.array([4, 1, -5]).astype(np.int8))
  36. x4 = Tensor(np.array([4, 1, -5]).astype(np.int16))
  37. x5 = Tensor(np.array([4, 1, -5]).astype(np.int32))
  38. x6 = Tensor(np.array([4, 1, -5]).astype(np.int64))
  39. x7 = Tensor(np.array([4, 1, -5]).astype(np.uint8))
  40. x8 = Tensor(np.array([4, 1, -5]).astype(np.uint16))
  41. x9 = Tensor(np.array([4, 1, -5]).astype(np.uint32))
  42. x10 = Tensor(np.array([4, 1, -5]).astype(np.uint64))
  43. x11 = Tensor(np.array([False, True, False]).astype(np.bool_))
  44. net = Net()
  45. out = net(x0).asnumpy()
  46. expect = [False, True, False]
  47. assert np.all(out == expect)
  48. out = net(x1).asnumpy()
  49. expect = [False, True, False]
  50. assert np.all(out == expect)
  51. out = net(x2).asnumpy()
  52. expect = [False, True, False]
  53. assert np.all(out == expect)
  54. out = net(x3).asnumpy()
  55. expect = [True, True, True]
  56. assert np.all(out == expect)
  57. out = net(x4).asnumpy()
  58. expect = [True, True, True]
  59. assert np.all(out == expect)
  60. out = net(x5).asnumpy()
  61. expect = [True, True, True]
  62. assert np.all(out == expect)
  63. out = net(x6).asnumpy()
  64. expect = [True, True, True]
  65. assert np.all(out == expect)
  66. out = net(x7).asnumpy()
  67. expect = [True, True, True]
  68. assert np.all(out == expect)
  69. out = net(x8).asnumpy()
  70. expect = [True, True, True]
  71. assert np.all(out == expect)
  72. out = net(x9).asnumpy()
  73. expect = [True, True, True]
  74. assert np.all(out == expect)
  75. out = net(x10).asnumpy()
  76. expect = [True, True, True]
  77. assert np.all(out == expect)
  78. out = net(x11).asnumpy()
  79. expect = [True, True, True]
  80. assert np.all(out == expect)