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_sequence_assign.py 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 enumerate"""
  16. import mindspore.nn as nn
  17. from mindspore import Tensor
  18. from mindspore import context
  19. context.set_context(mode=context.GRAPH_MODE)
  20. def test_list_index_1D():
  21. class Net(nn.Cell):
  22. def __init__(self):
  23. super(Net, self).__init__()
  24. def construct(self):
  25. list_ = [[1], [2, 2], [3, 3, 3]]
  26. list_[0] = [100]
  27. return list_
  28. net = Net()
  29. out = net()
  30. assert out[0] == [100]
  31. assert out[1] == [2, 2]
  32. assert out[2] == [3, 3, 3]
  33. def test_list_index_2D():
  34. class Net(nn.Cell):
  35. def __init__(self):
  36. super(Net, self).__init__()
  37. def construct(self):
  38. list_ = [[1], [2, 2], [3, 3, 3]]
  39. list_[1][0] = 200
  40. list_[1][1] = 201
  41. return list_
  42. net = Net()
  43. out = net()
  44. assert out[0] == [1]
  45. assert out[1] == [200, 201]
  46. assert out[2] == [3, 3, 3]
  47. def test_list_index_3D():
  48. class Net(nn.Cell):
  49. def __init__(self):
  50. super(Net, self).__init__()
  51. def construct(self):
  52. list_ = [[1], [2, 2], [[3, 3, 3]]]
  53. list_[2][0][0] = 300
  54. list_[2][0][1] = 301
  55. list_[2][0][2] = 302
  56. return list_
  57. net = Net()
  58. out = net()
  59. assert out[0] == [1]
  60. assert out[1] == [2, 2]
  61. assert out[2] == [[300, 301, 302]]
  62. def test_list_index_1D_parameter():
  63. class Net(nn.Cell):
  64. def __init__(self):
  65. super(Net, self).__init__()
  66. def construct(self, x):
  67. list_ = [x]
  68. list_[0] = 100
  69. return list_
  70. net = Net()
  71. net(Tensor(0))
  72. def test_list_index_2D_parameter():
  73. class Net(nn.Cell):
  74. def __init__(self):
  75. super(Net, self).__init__()
  76. def construct(self, x):
  77. list_ = [[x, x]]
  78. list_[0][0] = 100
  79. return list_
  80. net = Net()
  81. net(Tensor(0))
  82. def test_list_index_3D_parameter():
  83. class Net(nn.Cell):
  84. def __init__(self):
  85. super(Net, self).__init__()
  86. def construct(self, x):
  87. list_ = [[[x, x]]]
  88. list_[0][0][0] = 100
  89. return list_
  90. net = Net()
  91. net(Tensor(0))