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