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 29 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
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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 x is Tensor(bool)
  258. ('Pow1', {
  259. 'block': (P.Pow(),
  260. {'exception': TypeError, 'error_keywords': ['Pow']}),
  261. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_)), 2.0],
  262. 'skip': ['backward']}),
  263. # input is not Tensor
  264. ('Exp1', {
  265. 'block': (P.Exp(),
  266. {'exception': TypeError, 'error_keywords': ['Exp']}),
  267. 'desc_inputs': [5.0],
  268. 'skip': ['backward']}),
  269. # input is not Tensor
  270. ('Log1', {
  271. 'block': (P.Log(),
  272. {'exception': TypeError, 'error_keywords': ['Log']}),
  273. 'desc_inputs': [5.0],
  274. 'skip': ['backward']}),
  275. # input two tensors, their shapes do not match
  276. ('Minimum2', {
  277. 'block': (P.Minimum(), {'exception': ValueError, 'error_keywords': ['Minimum']}),
  278. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  279. 'skip': ['backward']}),
  280. # input two tensors, their shapes do not match
  281. ('Maximum2', {
  282. 'block': (P.Maximum(), {'exception': ValueError, 'error_keywords': ['Maximum']}),
  283. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  284. 'skip': ['backward']}),
  285. # input two tensors, their shapes do not match
  286. ('RealDiv2', {
  287. 'block': (P.RealDiv(), {'exception': ValueError, 'error_keywords': ['RealDiv']}),
  288. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  289. 'skip': ['backward']}),
  290. # input two tensors, their shapes do not match
  291. ('Div2', {
  292. 'block': (P.Div(), {'exception': ValueError, 'error_keywords': ['Div']}),
  293. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  294. 'skip': ['backward']}),
  295. # input two tensors, their shapes do not match
  296. ('FloorDiv2', {
  297. 'block': (P.FloorDiv(), {'exception': ValueError, 'error_keywords': ['FloorDiv']}),
  298. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  299. 'skip': ['backward']}),
  300. # input x is Tensor(int32), not Tensor(float)
  301. ('Floor1', {
  302. 'block': (P.Floor(),
  303. {'exception': TypeError, 'error_keywords': ['Floor']}),
  304. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32))],
  305. 'skip': ['backward']}),
  306. # input two tensors, their shapes do not match
  307. ('FFloorMod2', {
  308. 'block': (P.FloorMod(), {'exception': ValueError, 'error_keywords': ['FloorMod']}),
  309. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  310. 'skip': ['backward']}),
  311. # input x is Tensor(int32), not Tensor(float)
  312. ('Acosh1', {
  313. 'block': (P.Acosh(),
  314. {'exception': TypeError, 'error_keywords': ['Acosh']}),
  315. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  316. 'skip': ['backward']}),
  317. # shape of x and y not match
  318. ('Equal2', {
  319. 'block': (P.Equal(), {'exception': ValueError, 'error_keywords': ['Equal']}),
  320. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  321. 'skip': ['backward']}),
  322. # input is not tensor
  323. ('EqualCount0', {
  324. 'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
  325. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  326. 'skip': ['backward']}),
  327. # type of x and y not match
  328. ('EqualCount1', {
  329. 'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
  330. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  331. 'skip': ['backward']}),
  332. # shape of x and y not match
  333. # shape of x and y not match
  334. ('NotEqual2', {
  335. 'block': (P.NotEqual(), {'exception': ValueError, 'error_keywords': ['NotEqual']}),
  336. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  337. 'skip': ['backward']}),
  338. # shape of x and y not match
  339. ('Greater2', {
  340. 'block': (P.Greater(), {'exception': ValueError, 'error_keywords': ['Greater']}),
  341. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  342. 'skip': ['backward']}),
  343. # shape of x and y not match
  344. ('GreaterEqual2', {
  345. 'block': (P.GreaterEqual(), {'exception': ValueError, 'error_keywords': ['GreaterEqual']}),
  346. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  347. 'skip': ['backward']}),
  348. # shape of x and y not match
  349. ('Less2', {
  350. 'block': (P.Less(), {'exception': ValueError, 'error_keywords': ['Less']}),
  351. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  352. 'skip': ['backward']}),
  353. # shape of x and y not match
  354. ('LessEqual2', {
  355. 'block': (P.LessEqual(), {'exception': ValueError, 'error_keywords': ['LessEqual']}),
  356. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  357. 'skip': ['backward']}),
  358. # input x is not Tensor(bool)
  359. ('LogicalNot1', {
  360. 'block': (P.LogicalNot(),
  361. {'exception': TypeError, 'error_keywords': ['LogicalNot']}),
  362. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32))],
  363. 'skip': ['backward']}),
  364. # type of x and y not match
  365. ('LogicalAnd1', {
  366. 'block': (P.LogicalAnd(), {'exception': TypeError, 'error_keywords': ['LogicalAnd']}),
  367. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.bool_))],
  368. 'skip': ['backward']}),
  369. # shape of x and y not match
  370. ('LogicalAnd2', {
  371. 'block': (P.LogicalAnd(), {'exception': ValueError, 'error_keywords': ['LogicalAnd']}),
  372. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_)), Tensor(np.ones([3, 2]).astype(np.bool_))],
  373. 'skip': ['backward']}),
  374. # type of x and y not match
  375. ('LogicalOr1', {
  376. 'block': (P.LogicalOr(), {'exception': TypeError, 'error_keywords': ['LogicalOr']}),
  377. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.bool_))],
  378. 'skip': ['backward']}),
  379. # shape of x and y not match
  380. ('LogicalOr2', {
  381. 'block': (P.LogicalOr(), {'exception': ValueError, 'error_keywords': ['LogicalOr']}),
  382. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_)), Tensor(np.ones([3, 2]).astype(np.bool_))],
  383. 'skip': ['backward']}),
  384. # input is not tensor
  385. ('NPUGetFloatStatus0', {
  386. 'block': (P.NPUGetFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUGetFloatStatus']}),
  387. 'desc_inputs': [5.0],
  388. 'skip': ['backward']}),
  389. # input is Tensor(int32), not Tensor(float32)
  390. ('NPUGetFloatStatus1', {
  391. 'block': (P.NPUGetFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUGetFloatStatus']}),
  392. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  393. 'skip': ['backward']}),
  394. # dims is not 1
  395. ('NPUGetFloatStatus2', {
  396. 'block': (P.NPUGetFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUGetFloatStatus']}),
  397. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  398. 'skip': ['backward']}),
  399. # shape[0] is not 8
  400. ('NPUGetFloatStatus3', {
  401. 'block': (P.NPUGetFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUGetFloatStatus']}),
  402. 'desc_inputs': [Tensor(np.ones([3]).astype(np.float32))],
  403. 'skip': ['backward']}),
  404. # input is not tensor
  405. ('NPUClearFloatStatus0', {
  406. 'block': (P.NPUClearFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUClearFloatStatus']}),
  407. 'desc_inputs': [5.0],
  408. 'skip': ['backward']}),
  409. # input is Tensor(int32), not Tensor(float32)
  410. ('NPUClearFloatStatus1', {
  411. 'block': (P.NPUClearFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUClearFloatStatus']}),
  412. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  413. 'skip': ['backward']}),
  414. # dims is not 1
  415. ('NPUClearFloatStatus2', {
  416. 'block': (P.NPUClearFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUClearFloatStatus']}),
  417. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  418. 'skip': ['backward']}),
  419. # shape[0] is not 8
  420. ('NPUClearFloatStatus3', {
  421. 'block': (P.NPUClearFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUClearFloatStatus']}),
  422. 'desc_inputs': [Tensor(np.ones([3]).astype(np.float32))],
  423. 'skip': ['backward']}),
  424. # input is not tensor
  425. ('Cos0', {
  426. 'block': (P.Cos(), {'exception': TypeError, 'error_keywords': ['Cos']}),
  427. 'desc_inputs': [5.0],
  428. 'skip': ['backward']}),
  429. # input is Tensor(bool)
  430. ('Cos1', {
  431. 'block': (P.Cos(), {'exception': TypeError, 'error_keywords': ['Cos']}),
  432. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  433. 'skip': ['backward']}),
  434. # input is not tensor
  435. ('ACos0', {
  436. 'block': (P.ACos(), {'exception': TypeError, 'error_keywords': ['ACos']}),
  437. 'desc_inputs': [5.0],
  438. 'skip': ['backward']}),
  439. # input is Tensor(bool)
  440. ('ACos1', {
  441. 'block': (P.ACos(), {'exception': TypeError, 'error_keywords': ['ACos']}),
  442. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  443. 'skip': ['backward']}),
  444. # input is not tensor
  445. ('Sin0', {
  446. 'block': (P.Sin(), {'exception': TypeError, 'error_keywords': ['Sin']}),
  447. 'desc_inputs': [5.0],
  448. 'skip': ['backward']}),
  449. # input is Tensor(bool)
  450. ('Sin1', {
  451. 'block': (P.Sin(), {'exception': TypeError, 'error_keywords': ['Sin']}),
  452. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  453. 'skip': ['backward']}),
  454. # input is not tensor
  455. ('NMSWithMask0', {
  456. 'block': (P.NMSWithMask(), {'exception': TypeError, 'error_keywords': ['NMSWithMask']}),
  457. 'desc_inputs': [5.0],
  458. 'skip': ['backward']}),
  459. # input is not Tensor(float16) or Tensor(float32)
  460. ('NMSWithMask1', {
  461. 'block': (P.NMSWithMask(), {'exception': TypeError, 'error_keywords': ['NMSWithMask']}),
  462. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  463. 'skip': ['backward']}),
  464. # dims is not 2
  465. ('NMSWithMask2', {
  466. 'block': (P.NMSWithMask(), {'exception': ValueError, 'error_keywords': ['NMSWithMask']}),
  467. 'desc_inputs': [Tensor(np.ones([3, 4, 2]).astype(np.float32))],
  468. 'skip': ['backward']}),
  469. # shape[1] is not 5
  470. ('NMSWithMask3', {
  471. 'block': (P.NMSWithMask(), {'exception': ValueError, 'error_keywords': ['NMSWithMask']}),
  472. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.float32))],
  473. 'skip': ['backward']}),
  474. # input is not tensor
  475. ('Abs0', {
  476. 'block': (P.Abs(), {'exception': TypeError, 'error_keywords': ['Abs']}),
  477. 'desc_inputs': [5.0],
  478. 'skip': ['backward']}),
  479. # input is Tensor(bool)
  480. ('Abs1', {
  481. 'block': (P.Abs(), {'exception': TypeError, 'error_keywords': ['Abs']}),
  482. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  483. 'skip': ['backward']}),
  484. # input is not tensor
  485. ('Sign0', {
  486. 'block': (P.Sign(), {'exception': TypeError, 'error_keywords': ['Sign']}),
  487. 'desc_inputs': [5.0],
  488. 'skip': ['backward']}),
  489. # input is Tensor(bool)
  490. ('Sign1', {
  491. 'block': (P.Sign(), {'exception': TypeError, 'error_keywords': ['Sign']}),
  492. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  493. 'skip': ['backward']}),
  494. # input is not tensor
  495. ('Round0', {
  496. 'block': (P.Round(), {'exception': TypeError, 'error_keywords': ['Round']}),
  497. 'desc_inputs': [5.0],
  498. 'skip': ['backward']}),
  499. # input is Tensor(bool)
  500. ('Round1', {
  501. 'block': (P.Round(), {'exception': TypeError, 'error_keywords': ['Round']}),
  502. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  503. 'skip': ['backward']}),
  504. # input two tensors, their shapes do not match
  505. ('Atan22', {
  506. 'block': (P.Atan2(), {'exception': ValueError, 'error_keywords': ['Atan2']}),
  507. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  508. 'skip': ['backward']}),
  509. ]
  510. test_case_math_ops = [
  511. # input two tensors, but element types are not same
  512. ('TensorAdd1', {
  513. 'block': P.TensorAdd(),
  514. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  515. 'skip': ['backward']}),
  516. # input two tensors, but element types are not same
  517. ('Sub1', {
  518. 'block': P.Sub(),
  519. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  520. 'skip': ['backward']}),
  521. # input two tensors, but element types are not same
  522. ('Mul1', {
  523. 'block': P.Mul(),
  524. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  525. 'skip': ['backward']}),
  526. # input two tensors, but element types are not same
  527. ('Minimum1', {
  528. 'block': P.Minimum(),
  529. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  530. 'skip': ['backward']}),
  531. # input two tensors, but element types are not same
  532. ('Maximum1', {
  533. 'block': P.Maximum(),
  534. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  535. 'skip': ['backward']}),
  536. # input two tensors, but element types are not same
  537. ('RealDiv1', {
  538. 'block': P.RealDiv(),
  539. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  540. 'skip': ['backward']}),
  541. # input two tensors, but element types are not same
  542. ('Div1', {
  543. 'block': P.Div(),
  544. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  545. 'skip': ['backward']}),
  546. # input two tensors, but element types are not same
  547. ('FloorDiv1', {
  548. 'block': P.FloorDiv(),
  549. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  550. 'skip': ['backward']}),
  551. # input two tensors, but element types are not same
  552. ('FloorMod1', {
  553. 'block': P.FloorMod(),
  554. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  555. 'skip': ['backward']}),
  556. # type of x and y not match
  557. ('Equal1', {
  558. 'block': P.Equal(),
  559. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  560. 'skip': ['backward']}),
  561. # type of x and y not match
  562. ('NotEqual1', {
  563. 'block': P.NotEqual(),
  564. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  565. 'skip': ['backward']}),
  566. # type of x and y not match
  567. ('Greater1', {
  568. 'block': P.Greater(),
  569. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  570. 'skip': ['backward']}),
  571. # type of x and y not match
  572. ('GreaterEqual1', {
  573. 'block': P.GreaterEqual(),
  574. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  575. 'skip': ['backward']}),
  576. # type of x and y not match
  577. ('Less1', {
  578. 'block': P.Less(),
  579. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  580. 'skip': ['backward']}),
  581. # type of x and y not match
  582. ('LessEqual1', {
  583. 'block': P.LessEqual(),
  584. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  585. 'skip': ['backward']}),
  586. # input two tensors, but element types are not same
  587. ('Atan21', {
  588. 'block': P.Atan2(),
  589. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  590. 'skip': ['backward']}),
  591. ]
  592. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  593. def test_check_exception():
  594. return raise_set
  595. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  596. def test_exec():
  597. import mindspore.context as context
  598. context.set_context(mode=context.GRAPH_MODE)
  599. return functools.reduce(lambda x, y: x + y, [test_case_math_ops])