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_hypermap_specialize.py 2.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. """ test_hypermap_partial """
  16. import numpy as np
  17. import mindspore.common.dtype as mstype
  18. import mindspore.nn as nn
  19. from mindspore import Tensor, context
  20. from mindspore.common.api import ms_function
  21. from mindspore.ops import composite as C
  22. from mindspore.ops import functional as F
  23. from mindspore.ops import operations as P
  24. context.set_context(mode=context.GRAPH_MODE)
  25. def test_hypermap_specialize_param():
  26. class Net(nn.Cell):
  27. """ Net definition """
  28. def __init__(self):
  29. super(Net, self).__init__()
  30. self.mul = P.Mul()
  31. def construct(self, x, y):
  32. ret = self.mul(x, y)
  33. return ret
  34. factor1 = Tensor(5, dtype=mstype.int32)
  35. x = Tensor(np.ones([1]).astype(np.int32))
  36. y = Tensor(np.ones([2]).astype(np.int32))
  37. net = Net()
  38. hypermap = C.HyperMap()
  39. @ms_function
  40. def hypermap_specialize_param():
  41. ret1 = hypermap(F.partial(net, factor1), (x, y))
  42. # List will be converted to Tuple in SimlifyDataStructurePass.
  43. ret2 = hypermap(F.partial(net, factor1), [x, y])
  44. return ret1, ret2
  45. expected_ret = (Tensor(np.full(1, 5).astype(np.int32)), Tensor(np.full(2, 5).astype(np.int32)))
  46. ret = hypermap_specialize_param()
  47. assert ret == (expected_ret, expected_ret)