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_less_op.py 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. class Net(nn.Cell):
  22. def __init__(self):
  23. super(Net, self).__init__()
  24. self.ops = P.Less()
  25. def construct(self, x, y):
  26. return self.ops(x, y)
  27. @pytest.mark.level0
  28. @pytest.mark.platform_x86_cpu_training
  29. @pytest.mark.env_onecard
  30. def test_net():
  31. x0_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32)
  32. y0_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32)
  33. x1_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32)
  34. y1_np = np.random.randint(1, 5, (2, 1, 4, 4)).astype(np.float32)
  35. x2_np = np.random.randint(1, 5, (2, 1, 1, 4)).astype(np.float32)
  36. y2_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32)
  37. x3_np = np.random.randint(1, 5, 1).astype(np.float32)
  38. y3_np = np.random.randint(1, 5, 1).astype(np.float32)
  39. x4_np = np.array(768).astype(np.float32)
  40. y4_np = np.array(3072.5).astype(np.float32)
  41. x0 = Tensor(x0_np)
  42. y0 = Tensor(y0_np)
  43. x1 = Tensor(x1_np)
  44. y1 = Tensor(y1_np)
  45. x2 = Tensor(x2_np)
  46. y2 = Tensor(y2_np)
  47. x3 = Tensor(x3_np)
  48. y3 = Tensor(y3_np)
  49. x4 = Tensor(x4_np)
  50. y4 = Tensor(y4_np)
  51. context.set_context(mode=context.GRAPH_MODE, device_target='CPU')
  52. net = Net()
  53. out = net(x0, y0).asnumpy()
  54. expect = x0_np < y0_np
  55. assert np.all(out == expect)
  56. assert out.shape == expect.shape
  57. out = net(x1, y1).asnumpy()
  58. expect = x1_np < y1_np
  59. assert np.all(out == expect)
  60. assert out.shape == expect.shape
  61. out = net(x2, y2).asnumpy()
  62. expect = x2_np < y2_np
  63. assert np.all(out == expect)
  64. assert out.shape == expect.shape
  65. out = net(x3, y3).asnumpy()
  66. expect = x3_np < y3_np
  67. assert np.all(out == expect)
  68. assert out.shape == expect.shape
  69. out = net(x4, y4).asnumpy()
  70. expect = x4_np < y4_np
  71. assert np.all(out == expect)
  72. assert out.shape == expect.shape