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