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_math_ops_check.py 28 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 ops """
  16. import functools
  17. import numpy as np
  18. import mindspore.nn as nn
  19. from mindspore import Tensor
  20. from mindspore.common import dtype as mstype
  21. from mindspore.common.parameter import Parameter
  22. from mindspore.ops import operations as P
  23. from ....mindspore_test_framework.mindspore_test import mindspore_test
  24. from ....mindspore_test_framework.pipeline.forward.compile_forward \
  25. import pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception, \
  26. pipeline_for_compile_forward_ge_graph_for_case_by_case_config
  27. class AssignAddNet(nn.Cell):
  28. def __init__(self,):
  29. super(AssignAddNet, self).__init__()
  30. self.op = P.AssignAdd()
  31. self.inputdata = Parameter(Tensor(np.zeros([1]).astype(np.bool_), mstype.bool_), name="assign_add1")
  32. def construct(self, x):
  33. self.op(self.inputdata, x)
  34. return self.inputdata
  35. class AssignSubNet(nn.Cell):
  36. def __init__(self,):
  37. super(AssignSubNet, self).__init__()
  38. self.op = P.AssignSub()
  39. self.inputdata = Parameter(Tensor(np.zeros([1]).astype(np.bool_), mstype.bool_), name="assign_sub1")
  40. def construct(self, x):
  41. self.op(self.inputdata, x)
  42. return self.inputdata
  43. class ReduceNet(nn.Cell):
  44. def __init__(self, op_class, keep_dims, axis):
  45. super(ReduceNet, self).__init__()
  46. self.axis = axis
  47. self.op = op_class(keep_dims=keep_dims)
  48. def construct(self, x):
  49. return self.op(x, self.axis)
  50. class CumProdNet(nn.Cell):
  51. def __init__(self):
  52. super(CumProdNet, self).__init__()
  53. self.op = P.CumProd()
  54. def construct(self, x, axis):
  55. return self.op(x, axis)
  56. class CumSumNet(nn.Cell):
  57. def __init__(self, axis):
  58. super(CumSumNet, self).__init__()
  59. self.axis = axis
  60. self.op = P.CumSum()
  61. def construct(self, x):
  62. return self.op(x, self.axis)
  63. raise_set = [
  64. # input two tensors, their shapes do not match
  65. ('TensorAdd2', {
  66. 'block': (P.TensorAdd(), {'exception': ValueError, 'error_keywords': ['TensorAdd']}),
  67. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  68. 'skip': ['backward']}),
  69. # check input Tensor(bool_)
  70. ('AssignAdd', {
  71. 'block': (AssignAddNet(), {'exception': TypeError, 'error_keywords': ['AssignAdd']}),
  72. 'desc_inputs': [Tensor(np.ones([1]).astype(np.bool_), mstype.bool_)],
  73. 'skip': ['backward']}),
  74. # check input Tensor(bool_)
  75. ('AssignSub', {
  76. 'block': (AssignSubNet(), {'exception': TypeError, 'error_keywords': ['AssignSub']}),
  77. 'desc_inputs': [Tensor(np.ones([1]).astype(np.bool_), mstype.bool_)],
  78. 'skip': ['backward']}),
  79. # type of axis is float, not int
  80. ('ReduceMean1', {
  81. 'block': (ReduceNet(P.ReduceMean, keep_dims=True, axis=5.0),
  82. {'exception': TypeError, 'error_keywords': ['ReduceMean']}),
  83. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  84. 'skip': ['backward']}),
  85. # axis is out of range
  86. ('ReduceMean2', {
  87. 'block': (ReduceNet(P.ReduceMean, keep_dims=True, axis=5),
  88. {'exception': ValueError, 'error_keywords': ['ReduceMean']}),
  89. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  90. 'skip': ['backward']}),
  91. # type of axis is float, not int
  92. ('ReduceSum1', {
  93. 'block': (ReduceNet(P.ReduceSum, keep_dims=True, axis=5.0),
  94. {'exception': TypeError, 'error_keywords': ['ReduceSum']}),
  95. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  96. 'skip': ['backward']}),
  97. # axis is out of range
  98. ('ReduceSum2', {
  99. 'block': (ReduceNet(P.ReduceSum, keep_dims=True, axis=5),
  100. {'exception': ValueError, 'error_keywords': ['ReduceSum']}),
  101. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  102. 'skip': ['backward']}),
  103. # type of axis is float, not int
  104. ('ReduceAll1', {
  105. 'block': (ReduceNet(P.ReduceAll, keep_dims=True, axis=5.0),
  106. {'exception': TypeError, 'error_keywords': ['ReduceAll']}),
  107. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool_))],
  108. 'skip': ['backward']}),
  109. # axis is out of range
  110. ('ReduceAll2', {
  111. 'block': (ReduceNet(P.ReduceAll, keep_dims=True, axis=5),
  112. {'exception': ValueError, 'error_keywords': ['ReduceAll']}),
  113. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool_))],
  114. 'skip': ['backward']}),
  115. # type of axis is float, not int
  116. ('ReduceMax1', {
  117. 'block': (ReduceNet(P.ReduceMax, keep_dims=True, axis=5.0),
  118. {'exception': TypeError, 'error_keywords': ['ReduceMax']}),
  119. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  120. 'skip': ['backward']}),
  121. # axis is out of range
  122. ('ReduceMax2', {
  123. 'block': (ReduceNet(P.ReduceMax, keep_dims=True, axis=5),
  124. {'exception': ValueError, 'error_keywords': ['ReduceMax']}),
  125. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  126. 'skip': ['backward']}),
  127. # type of axis is float, not int
  128. ('ReduceMin1', {
  129. 'block': (ReduceNet(P.ReduceMin, keep_dims=True, axis=5.0),
  130. {'exception': TypeError, 'error_keywords': ['ReduceMin']}),
  131. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  132. 'skip': ['backward']}),
  133. # axis is out of range
  134. ('ReduceMin2', {
  135. 'block': (ReduceNet(P.ReduceMin, keep_dims=True, axis=5),
  136. {'exception': ValueError, 'error_keywords': ['ReduceMin']}),
  137. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  138. 'skip': ['backward']}),
  139. # type of axis is float, not int
  140. ('ReduceProd1', {
  141. 'block': (ReduceNet(P.ReduceProd, keep_dims=True, axis=5.0),
  142. {'exception': TypeError, 'error_keywords': ['ReduceProd']}),
  143. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  144. 'skip': ['backward']}),
  145. # axis is out of range
  146. ('ReduceProd2', {
  147. 'block': (ReduceNet(P.ReduceProd, keep_dims=True, axis=5),
  148. {'exception': ValueError, 'error_keywords': ['ReduceProd']}),
  149. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  150. 'skip': ['backward']}),
  151. # type of x is Tensor(bool)
  152. ('CumProd1', {
  153. 'block': (CumProdNet(),
  154. {'exception': TypeError, 'error_keywords': ['CumProd']}),
  155. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool)), 1],
  156. 'skip': ['backward']}),
  157. # type of axis in float, not int
  158. ('CumProd2', {
  159. 'block': (CumProdNet(),
  160. {'exception': TypeError, 'error_keywords': ['CumProd']}),
  161. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32)), 5.0],
  162. 'skip': ['backward']}),
  163. # type of x and y are Tensor(uint32)
  164. ('MatMul1', {
  165. 'block': (P.MatMul(),
  166. {'exception': TypeError, 'error_keywords': ['MatMul']}),
  167. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.uint32)), Tensor(np.ones([3, 2]).astype(np.uint32))],
  168. 'skip': ['backward']}),
  169. # type of x and y not match
  170. ('MatMul2', {
  171. 'block': (P.MatMul(),
  172. {'exception': TypeError, 'error_keywords': ['MatMul']}),
  173. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.int32))],
  174. 'skip': ['backward']}),
  175. # shape of x and y not match
  176. ('MatMul3', {
  177. 'block': (P.MatMul(),
  178. {'exception': ValueError, 'error_keywords': ['MatMul']}),
  179. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.float32)), Tensor(np.ones([2, 3]).astype(np.float32))],
  180. 'skip': ['backward']}),
  181. # dims of x and y are less than 3
  182. ('BatchMatMul1', {
  183. 'block': (P.BatchMatMul(),
  184. {'exception': ValueError, 'error_keywords': ['BatchMatMul']}),
  185. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32)), Tensor(np.ones([3, 2]).astype(np.int32))],
  186. 'skip': ['backward']}),
  187. # type of x is Tensor(bool)
  188. ('CumSum1', {
  189. 'block': (CumSumNet(axis=1),
  190. {'exception': TypeError, 'error_keywords': ['CumSum']}),
  191. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool))],
  192. 'skip': ['backward']}),
  193. # type of axis in float, not int
  194. ('CumSum2', {
  195. 'block': (CumSumNet(axis=1.0),
  196. {'exception': TypeError, 'error_keywords': ['CumSum']}),
  197. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool))],
  198. 'skip': ['backward']}),
  199. # intput is not tuple or list
  200. ('AddN1', {
  201. 'block': (P.AddN(),
  202. {'exception': TypeError, 'error_keywords': ['AddN']}),
  203. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.uint32))],
  204. 'skip': ['backward']}),
  205. # type not match
  206. ('AddN2', {
  207. 'block': (P.AddN(),
  208. {'exception': TypeError, 'error_keywords': ['AddN']}),
  209. 'desc_inputs': [(Tensor(np.ones([2, 3]).astype(np.uint32)), Tensor(np.ones([3, 2]).astype(np.int32)))],
  210. 'skip': ['backward']}),
  211. # shape not match
  212. ('AddN3', {
  213. 'block': (P.AddN(),
  214. {'exception': ValueError, 'error_keywords': ['AddN']}),
  215. 'desc_inputs': [(Tensor(np.ones([2, 3]).astype(np.int32)), Tensor(np.ones([3, 2]).astype(np.int32)))],
  216. 'skip': ['backward']}),
  217. # input is Tensor(bool)
  218. ('Neg1', {
  219. 'block': (P.Neg(),
  220. {'exception': TypeError, 'error_keywords': ['Neg']}),
  221. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  222. 'skip': ['backward']}),
  223. # input two tensors, their shapes do not match
  224. ('Sub2', {
  225. 'block': (P.Sub(), {'exception': ValueError, 'error_keywords': ['Sub']}),
  226. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  227. 'skip': ['backward']}),
  228. # input two tensors, their shapes do not match
  229. ('Mul2', {
  230. 'block': (P.Mul(), {'exception': ValueError, 'error_keywords': ['Mul']}),
  231. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  232. 'skip': ['backward']}),
  233. # input is Tensor(bool)
  234. ('Square1', {
  235. 'block': (P.Square(),
  236. {'exception': TypeError, 'error_keywords': ['Square']}),
  237. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  238. 'skip': ['backward']}),
  239. # input is Tensor(bool)
  240. ('Rsqrt1', {
  241. 'block': (P.Rsqrt(),
  242. {'exception': TypeError, 'error_keywords': ['Rsqrt']}),
  243. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  244. 'skip': ['backward']}),
  245. # input is Tensor(bool)
  246. ('Sqrt1', {
  247. 'block': (P.Sqrt(),
  248. {'exception': TypeError, 'error_keywords': ['Sqrt']}),
  249. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  250. 'skip': ['backward']}),
  251. # input is not Tensor
  252. ('Reciprocal1', {
  253. 'block': (P.Reciprocal(),
  254. {'exception': TypeError, 'error_keywords': ['Reciprocal']}),
  255. 'desc_inputs': [5.0],
  256. 'skip': ['backward']}),
  257. # input is not Tensor
  258. ('Exp1', {
  259. 'block': (P.Exp(),
  260. {'exception': TypeError, 'error_keywords': ['Exp']}),
  261. 'desc_inputs': [5.0],
  262. 'skip': ['backward']}),
  263. # input is not Tensor
  264. ('Log1', {
  265. 'block': (P.Log(),
  266. {'exception': TypeError, 'error_keywords': ['Log']}),
  267. 'desc_inputs': [5.0],
  268. 'skip': ['backward']}),
  269. # input two tensors, their shapes do not match
  270. ('Minimum2', {
  271. 'block': (P.Minimum(), {'exception': ValueError, 'error_keywords': ['Minimum']}),
  272. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  273. 'skip': ['backward']}),
  274. # input two tensors, their shapes do not match
  275. ('Maximum2', {
  276. 'block': (P.Maximum(), {'exception': ValueError, 'error_keywords': ['Maximum']}),
  277. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  278. 'skip': ['backward']}),
  279. # input two tensors, their shapes do not match
  280. ('RealDiv2', {
  281. 'block': (P.RealDiv(), {'exception': ValueError, 'error_keywords': ['RealDiv']}),
  282. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  283. 'skip': ['backward']}),
  284. # input two tensors, their shapes do not match
  285. ('Div2', {
  286. 'block': (P.Div(), {'exception': ValueError, 'error_keywords': ['Div']}),
  287. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  288. 'skip': ['backward']}),
  289. # input two tensors, their shapes do not match
  290. ('FloorDiv2', {
  291. 'block': (P.FloorDiv(), {'exception': ValueError, 'error_keywords': ['FloorDiv']}),
  292. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  293. 'skip': ['backward']}),
  294. # input x is Tensor(int32), not Tensor(float)
  295. ('Floor1', {
  296. 'block': (P.Floor(),
  297. {'exception': TypeError, 'error_keywords': ['Floor']}),
  298. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32))],
  299. 'skip': ['backward']}),
  300. # input two tensors, their shapes do not match
  301. ('FFloorMod2', {
  302. 'block': (P.FloorMod(), {'exception': ValueError, 'error_keywords': ['FloorMod']}),
  303. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  304. 'skip': ['backward']}),
  305. # input x is Tensor(int32), not Tensor(float)
  306. ('Acosh1', {
  307. 'block': (P.Acosh(),
  308. {'exception': TypeError, 'error_keywords': ['Acosh']}),
  309. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  310. 'skip': ['backward']}),
  311. # shape of x and y not match
  312. ('Equal2', {
  313. 'block': (P.Equal(), {'exception': ValueError, 'error_keywords': ['Equal']}),
  314. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  315. 'skip': ['backward']}),
  316. # input is not tensor
  317. ('EqualCount0', {
  318. 'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
  319. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  320. 'skip': ['backward']}),
  321. # type of x and y not match
  322. ('EqualCount1', {
  323. 'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
  324. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  325. 'skip': ['backward']}),
  326. # shape of x and y not match
  327. # shape of x and y not match
  328. ('NotEqual2', {
  329. 'block': (P.NotEqual(), {'exception': ValueError, 'error_keywords': ['NotEqual']}),
  330. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  331. 'skip': ['backward']}),
  332. # shape of x and y not match
  333. ('Greater2', {
  334. 'block': (P.Greater(), {'exception': ValueError, 'error_keywords': ['Greater']}),
  335. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  336. 'skip': ['backward']}),
  337. # shape of x and y not match
  338. ('GreaterEqual2', {
  339. 'block': (P.GreaterEqual(), {'exception': ValueError, 'error_keywords': ['GreaterEqual']}),
  340. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  341. 'skip': ['backward']}),
  342. # shape of x and y not match
  343. ('Less2', {
  344. 'block': (P.Less(), {'exception': ValueError, 'error_keywords': ['Less']}),
  345. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  346. 'skip': ['backward']}),
  347. # shape of x and y not match
  348. ('LessEqual2', {
  349. 'block': (P.LessEqual(), {'exception': ValueError, 'error_keywords': ['LessEqual']}),
  350. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  351. 'skip': ['backward']}),
  352. # input x is not Tensor(bool)
  353. ('LogicalNot1', {
  354. 'block': (P.LogicalNot(),
  355. {'exception': TypeError, 'error_keywords': ['LogicalNot']}),
  356. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32))],
  357. 'skip': ['backward']}),
  358. # type of x and y not match
  359. ('LogicalAnd1', {
  360. 'block': (P.LogicalAnd(), {'exception': TypeError, 'error_keywords': ['LogicalAnd']}),
  361. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.bool_))],
  362. 'skip': ['backward']}),
  363. # shape of x and y not match
  364. ('LogicalAnd2', {
  365. 'block': (P.LogicalAnd(), {'exception': ValueError, 'error_keywords': ['LogicalAnd']}),
  366. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_)), Tensor(np.ones([3, 2]).astype(np.bool_))],
  367. 'skip': ['backward']}),
  368. # type of x and y not match
  369. ('LogicalOr1', {
  370. 'block': (P.LogicalOr(), {'exception': TypeError, 'error_keywords': ['LogicalOr']}),
  371. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.bool_))],
  372. 'skip': ['backward']}),
  373. # shape of x and y not match
  374. ('LogicalOr2', {
  375. 'block': (P.LogicalOr(), {'exception': ValueError, 'error_keywords': ['LogicalOr']}),
  376. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_)), Tensor(np.ones([3, 2]).astype(np.bool_))],
  377. 'skip': ['backward']}),
  378. # input is not tensor
  379. ('NPUGetFloatStatus0', {
  380. 'block': (P.NPUGetFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUGetFloatStatus']}),
  381. 'desc_inputs': [5.0],
  382. 'skip': ['backward']}),
  383. # input is Tensor(int32), not Tensor(float32)
  384. ('NPUGetFloatStatus1', {
  385. 'block': (P.NPUGetFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUGetFloatStatus']}),
  386. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  387. 'skip': ['backward']}),
  388. # dims is not 1
  389. ('NPUGetFloatStatus2', {
  390. 'block': (P.NPUGetFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUGetFloatStatus']}),
  391. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  392. 'skip': ['backward']}),
  393. # shape[0] is not 8
  394. ('NPUGetFloatStatus3', {
  395. 'block': (P.NPUGetFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUGetFloatStatus']}),
  396. 'desc_inputs': [Tensor(np.ones([3]).astype(np.float32))],
  397. 'skip': ['backward']}),
  398. # input is not tensor
  399. ('NPUClearFloatStatus0', {
  400. 'block': (P.NPUClearFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUClearFloatStatus']}),
  401. 'desc_inputs': [5.0],
  402. 'skip': ['backward']}),
  403. # input is Tensor(int32), not Tensor(float32)
  404. ('NPUClearFloatStatus1', {
  405. 'block': (P.NPUClearFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUClearFloatStatus']}),
  406. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  407. 'skip': ['backward']}),
  408. # dims is not 1
  409. ('NPUClearFloatStatus2', {
  410. 'block': (P.NPUClearFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUClearFloatStatus']}),
  411. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  412. 'skip': ['backward']}),
  413. # shape[0] is not 8
  414. ('NPUClearFloatStatus3', {
  415. 'block': (P.NPUClearFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUClearFloatStatus']}),
  416. 'desc_inputs': [Tensor(np.ones([3]).astype(np.float32))],
  417. 'skip': ['backward']}),
  418. # input is not tensor
  419. ('Cos0', {
  420. 'block': (P.Cos(), {'exception': TypeError, 'error_keywords': ['Cos']}),
  421. 'desc_inputs': [5.0],
  422. 'skip': ['backward']}),
  423. # input is Tensor(bool)
  424. ('Cos1', {
  425. 'block': (P.Cos(), {'exception': TypeError, 'error_keywords': ['Cos']}),
  426. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  427. 'skip': ['backward']}),
  428. # input is not tensor
  429. ('ACos0', {
  430. 'block': (P.ACos(), {'exception': TypeError, 'error_keywords': ['ACos']}),
  431. 'desc_inputs': [5.0],
  432. 'skip': ['backward']}),
  433. # input is Tensor(bool)
  434. ('ACos1', {
  435. 'block': (P.ACos(), {'exception': TypeError, 'error_keywords': ['ACos']}),
  436. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  437. 'skip': ['backward']}),
  438. # input is not tensor
  439. ('Sin0', {
  440. 'block': (P.Sin(), {'exception': TypeError, 'error_keywords': ['Sin']}),
  441. 'desc_inputs': [5.0],
  442. 'skip': ['backward']}),
  443. # input is Tensor(bool)
  444. ('Sin1', {
  445. 'block': (P.Sin(), {'exception': TypeError, 'error_keywords': ['Sin']}),
  446. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  447. 'skip': ['backward']}),
  448. # input is not tensor
  449. ('NMSWithMask0', {
  450. 'block': (P.NMSWithMask(), {'exception': TypeError, 'error_keywords': ['NMSWithMask']}),
  451. 'desc_inputs': [5.0],
  452. 'skip': ['backward']}),
  453. # input is not Tensor(float16) or Tensor(float32)
  454. ('NMSWithMask1', {
  455. 'block': (P.NMSWithMask(), {'exception': TypeError, 'error_keywords': ['NMSWithMask']}),
  456. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  457. 'skip': ['backward']}),
  458. # dims is not 2
  459. ('NMSWithMask2', {
  460. 'block': (P.NMSWithMask(), {'exception': ValueError, 'error_keywords': ['NMSWithMask']}),
  461. 'desc_inputs': [Tensor(np.ones([3, 4, 2]).astype(np.float32))],
  462. 'skip': ['backward']}),
  463. # shape[1] is not 5
  464. ('NMSWithMask3', {
  465. 'block': (P.NMSWithMask(), {'exception': ValueError, 'error_keywords': ['NMSWithMask']}),
  466. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.float32))],
  467. 'skip': ['backward']}),
  468. # input is not tensor
  469. ('Abs0', {
  470. 'block': (P.Abs(), {'exception': TypeError, 'error_keywords': ['Abs']}),
  471. 'desc_inputs': [5.0],
  472. 'skip': ['backward']}),
  473. # input is Tensor(bool)
  474. ('Abs1', {
  475. 'block': (P.Abs(), {'exception': TypeError, 'error_keywords': ['Abs']}),
  476. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  477. 'skip': ['backward']}),
  478. # input is not tensor
  479. ('Sign0', {
  480. 'block': (P.Sign(), {'exception': TypeError, 'error_keywords': ['Sign']}),
  481. 'desc_inputs': [5.0],
  482. 'skip': ['backward']}),
  483. # input is Tensor(bool)
  484. ('Sign1', {
  485. 'block': (P.Sign(), {'exception': TypeError, 'error_keywords': ['Sign']}),
  486. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  487. 'skip': ['backward']}),
  488. # input is not tensor
  489. ('Round0', {
  490. 'block': (P.Round(), {'exception': TypeError, 'error_keywords': ['Round']}),
  491. 'desc_inputs': [5.0],
  492. 'skip': ['backward']}),
  493. # input is Tensor(bool)
  494. ('Round1', {
  495. 'block': (P.Round(), {'exception': TypeError, 'error_keywords': ['Round']}),
  496. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  497. 'skip': ['backward']}),
  498. # input two tensors, their shapes do not match
  499. ('Atan22', {
  500. 'block': (P.Atan2(), {'exception': ValueError, 'error_keywords': ['Atan2']}),
  501. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  502. 'skip': ['backward']}),
  503. ]
  504. test_case_math_ops = [
  505. # input two tensors, but element types are not same
  506. ('TensorAdd1', {
  507. 'block': P.TensorAdd(),
  508. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  509. 'skip': ['backward']}),
  510. # input two tensors, but element types are not same
  511. ('Sub1', {
  512. 'block': P.Sub(),
  513. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  514. 'skip': ['backward']}),
  515. # input two tensors, but element types are not same
  516. ('Mul1', {
  517. 'block': P.Mul(),
  518. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  519. 'skip': ['backward']}),
  520. # input two tensors, but element types are not same
  521. ('Minimum1', {
  522. 'block': P.Minimum(),
  523. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  524. 'skip': ['backward']}),
  525. # input two tensors, but element types are not same
  526. ('Maximum1', {
  527. 'block': P.Maximum(),
  528. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  529. 'skip': ['backward']}),
  530. # input two tensors, but element types are not same
  531. ('RealDiv1', {
  532. 'block': P.RealDiv(),
  533. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  534. 'skip': ['backward']}),
  535. # input two tensors, but element types are not same
  536. ('Div1', {
  537. 'block': P.Div(),
  538. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  539. 'skip': ['backward']}),
  540. # input two tensors, but element types are not same
  541. ('FloorDiv1', {
  542. 'block': P.FloorDiv(),
  543. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  544. 'skip': ['backward']}),
  545. # input two tensors, but element types are not same
  546. ('FloorMod1', {
  547. 'block': P.FloorMod(),
  548. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  549. 'skip': ['backward']}),
  550. # type of x and y not match
  551. ('Equal1', {
  552. 'block': P.Equal(),
  553. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  554. 'skip': ['backward']}),
  555. # type of x and y not match
  556. ('NotEqual1', {
  557. 'block': P.NotEqual(),
  558. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  559. 'skip': ['backward']}),
  560. # type of x and y not match
  561. ('Greater1', {
  562. 'block': P.Greater(),
  563. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  564. 'skip': ['backward']}),
  565. # type of x and y not match
  566. ('GreaterEqual1', {
  567. 'block': P.GreaterEqual(),
  568. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  569. 'skip': ['backward']}),
  570. # type of x and y not match
  571. ('Less1', {
  572. 'block': P.Less(),
  573. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  574. 'skip': ['backward']}),
  575. # type of x and y not match
  576. ('LessEqual1', {
  577. 'block': P.LessEqual(),
  578. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  579. 'skip': ['backward']}),
  580. # input two tensors, but element types are not same
  581. ('Atan21', {
  582. 'block': P.Atan2(),
  583. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  584. 'skip': ['backward']}),
  585. ]
  586. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  587. def test_check_exception():
  588. return raise_set
  589. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  590. def test_exec():
  591. import mindspore.context as context
  592. context.set_context(mode=context.GRAPH_MODE)
  593. return functools.reduce(lambda x, y: x + y, [test_case_math_ops])