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 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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. from mindspore import ops
  19. from mindspore.ops import functional as F
  20. from mindspore.ops import operations as P
  21. from mindspore.ops.operations import _grad_ops as G
  22. import mindspore.ops.composite as C
  23. import mindspore.nn as nn
  24. from mindspore import Tensor
  25. from mindspore.common import dtype as mstype
  26. from mindspore.common.parameter import Parameter
  27. from ..ut_filter import non_graph_engine
  28. from mindspore.common.api import _executor
  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. # one input is scalar, and another is Tensor(float32)
  73. ('TensorAdd0', {
  74. 'block': (P.TensorAdd(), {'exception': TypeError, 'error_keywords': ['TensorAdd']}),
  75. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  76. 'skip': ['backward']}),
  77. # input two tensors, but element types are not same
  78. ('TensorAdd1', {
  79. 'block': (P.TensorAdd(), {'exception': TypeError, 'error_keywords': ['TensorAdd']}),
  80. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  81. 'skip': ['backward']}),
  82. # input two tensors, their shapes do not match
  83. ('TensorAdd2', {
  84. 'block': (P.TensorAdd(), {'exception': ValueError, 'error_keywords': ['TensorAdd']}),
  85. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  86. 'skip': ['backward']}),
  87. # check input Tensor(bool_)
  88. ('AssignAdd', {
  89. 'block': (AssignAddNet(), {'exception': TypeError, 'error_keywords': ['AssignAdd']}),
  90. 'desc_inputs': [Tensor(np.ones([1]).astype(np.bool_), mstype.bool_)],
  91. 'skip': ['backward']}),
  92. # check input Tensor(bool_)
  93. ('AssignSub', {
  94. 'block': (AssignSubNet(), {'exception': TypeError, 'error_keywords': ['AssignSub']}),
  95. 'desc_inputs': [Tensor(np.ones([1]).astype(np.bool_), mstype.bool_)],
  96. 'skip': ['backward']}),
  97. # type of axis is float, not int
  98. ('ReduceMean1', {
  99. 'block': (ReduceNet(P.ReduceMean, keep_dims=True, axis=5.0),
  100. {'exception': TypeError, 'error_keywords': ['ReduceMean']}),
  101. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  102. 'skip': ['backward']}),
  103. # axis is out of range
  104. ('ReduceMean2', {
  105. 'block': (ReduceNet(P.ReduceMean, keep_dims=True, axis=5),
  106. {'exception': ValueError, 'error_keywords': ['ReduceMean']}),
  107. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  108. 'skip': ['backward']}),
  109. # type of axis is float, not int
  110. ('ReduceSum1', {
  111. 'block': (ReduceNet(P.ReduceSum, keep_dims=True, axis=5.0),
  112. {'exception': TypeError, 'error_keywords': ['ReduceSum']}),
  113. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  114. 'skip': ['backward']}),
  115. # axis is out of range
  116. ('ReduceSum2', {
  117. 'block': (ReduceNet(P.ReduceSum, keep_dims=True, axis=5),
  118. {'exception': ValueError, 'error_keywords': ['ReduceSum']}),
  119. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  120. 'skip': ['backward']}),
  121. # type of axis is float, not int
  122. ('ReduceAll1', {
  123. 'block': (ReduceNet(P.ReduceAll, keep_dims=True, axis=5.0),
  124. {'exception': TypeError, 'error_keywords': ['ReduceAll']}),
  125. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool_))],
  126. 'skip': ['backward']}),
  127. # axis is out of range
  128. ('ReduceAll2', {
  129. 'block': (ReduceNet(P.ReduceAll, keep_dims=True, axis=5),
  130. {'exception': ValueError, 'error_keywords': ['ReduceAll']}),
  131. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool_))],
  132. 'skip': ['backward']}),
  133. # type of axis is float, not int
  134. ('ReduceMax1', {
  135. 'block': (ReduceNet(P.ReduceMax, keep_dims=True, axis=5.0),
  136. {'exception': TypeError, 'error_keywords': ['ReduceMax']}),
  137. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  138. 'skip': ['backward']}),
  139. # axis is out of range
  140. ('ReduceMax2', {
  141. 'block': (ReduceNet(P.ReduceMax, keep_dims=True, axis=5),
  142. {'exception': ValueError, 'error_keywords': ['ReduceMax']}),
  143. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  144. 'skip': ['backward']}),
  145. # type of axis is float, not int
  146. ('ReduceMin1', {
  147. 'block': (ReduceNet(P.ReduceMin, keep_dims=True, axis=5.0),
  148. {'exception': TypeError, 'error_keywords': ['ReduceMin']}),
  149. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  150. 'skip': ['backward']}),
  151. # axis is out of range
  152. ('ReduceMin2', {
  153. 'block': (ReduceNet(P.ReduceMin, keep_dims=True, axis=5),
  154. {'exception': ValueError, 'error_keywords': ['ReduceMin']}),
  155. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  156. 'skip': ['backward']}),
  157. # type of axis is float, not int
  158. ('ReduceProd1', {
  159. 'block': (ReduceNet(P.ReduceProd, keep_dims=True, axis=5.0),
  160. {'exception': TypeError, 'error_keywords': ['ReduceProd']}),
  161. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  162. 'skip': ['backward']}),
  163. # axis is out of range
  164. ('ReduceProd2', {
  165. 'block': (ReduceNet(P.ReduceProd, keep_dims=True, axis=5),
  166. {'exception': ValueError, 'error_keywords': ['ReduceProd']}),
  167. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))],
  168. 'skip': ['backward']}),
  169. # type of x is Tensor(bool)
  170. ('CumProd1', {
  171. 'block': (CumProdNet(),
  172. {'exception': TypeError, 'error_keywords': ['CumProd']}),
  173. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool)), 1],
  174. 'skip': ['backward']}),
  175. # type of axis in float, not int
  176. ('CumProd2', {
  177. 'block': (CumProdNet(),
  178. {'exception': TypeError, 'error_keywords': ['CumProd']}),
  179. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32)), 5.0],
  180. 'skip': ['backward']}),
  181. # type of x and y are Tensor(uint32)
  182. ('MatMul1', {
  183. 'block': (P.MatMul(),
  184. {'exception': TypeError, 'error_keywords': ['MatMul']}),
  185. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.uint32)), Tensor(np.ones([3, 2]).astype(np.uint32))],
  186. 'skip': ['backward']}),
  187. # type of x and y not match
  188. ('MatMul2', {
  189. 'block': (P.MatMul(),
  190. {'exception': TypeError, 'error_keywords': ['MatMul']}),
  191. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.int32))],
  192. 'skip': ['backward']}),
  193. # shape of x and y not match
  194. ('MatMul3', {
  195. 'block': (P.MatMul(),
  196. {'exception': ValueError, 'error_keywords': ['MatMul']}),
  197. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.float32)), Tensor(np.ones([2, 3]).astype(np.float32))],
  198. 'skip': ['backward']}),
  199. # dims of x and y are less than 3
  200. ('BatchMatMul1', {
  201. 'block': (P.BatchMatMul(),
  202. {'exception': ValueError, 'error_keywords': ['BatchMatMul']}),
  203. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32)), Tensor(np.ones([3, 2]).astype(np.int32))],
  204. 'skip': ['backward']}),
  205. # type of x is Tensor(bool)
  206. ('CumSum1', {
  207. 'block': (CumSumNet(axis=1),
  208. {'exception': TypeError, 'error_keywords': ['CumSum']}),
  209. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool))],
  210. 'skip': ['backward']}),
  211. # type of axis in float, not int
  212. ('CumSum2', {
  213. 'block': (CumSumNet(axis=1.0),
  214. {'exception': TypeError, 'error_keywords': ['CumSum']}),
  215. 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.bool))],
  216. 'skip': ['backward']}),
  217. # intput is not tuple or list
  218. ('AddN1', {
  219. 'block': (P.AddN(),
  220. {'exception': TypeError, 'error_keywords': ['AddN']}),
  221. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.uint32))],
  222. 'skip': ['backward']}),
  223. # type not match
  224. ('AddN2', {
  225. 'block': (P.AddN(),
  226. {'exception': TypeError, 'error_keywords': ['AddN']}),
  227. 'desc_inputs': [(Tensor(np.ones([2, 3]).astype(np.uint32)), Tensor(np.ones([3, 2]).astype(np.int32)))],
  228. 'skip': ['backward']}),
  229. # shape not match
  230. ('AddN3', {
  231. 'block': (P.AddN(),
  232. {'exception': ValueError, 'error_keywords': ['AddN']}),
  233. 'desc_inputs': [(Tensor(np.ones([2, 3]).astype(np.int32)), Tensor(np.ones([3, 2]).astype(np.int32)))],
  234. 'skip': ['backward']}),
  235. # input is Tensor(bool)
  236. ('Neg1', {
  237. 'block': (P.Neg(),
  238. {'exception': TypeError, 'error_keywords': ['Neg']}),
  239. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  240. 'skip': ['backward']}),
  241. # one input is scalar, and another is Tensor(float32)
  242. ('Sub0', {
  243. 'block': (P.Sub(), {'exception': TypeError, 'error_keywords': ['Sub']}),
  244. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  245. 'skip': ['backward']}),
  246. # input two tensors, but element types are not same
  247. ('Sub1', {
  248. 'block': (P.Sub(), {'exception': TypeError, 'error_keywords': ['Sub']}),
  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. ('Sub2', {
  253. 'block': (P.Sub(), {'exception': ValueError, 'error_keywords': ['Sub']}),
  254. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  255. 'skip': ['backward']}),
  256. # one input is scalar, and another is Tensor(float32)
  257. ('Mul0', {
  258. 'block': (P.Mul(), {'exception': TypeError, 'error_keywords': ['Mul']}),
  259. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  260. 'skip': ['backward']}),
  261. # input two tensors, but element types are not same
  262. ('Mul1', {
  263. 'block': (P.Mul(), {'exception': TypeError, 'error_keywords': ['Mul']}),
  264. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  265. 'skip': ['backward']}),
  266. # input two tensors, their shapes do not match
  267. ('Mul2', {
  268. 'block': (P.Mul(), {'exception': ValueError, 'error_keywords': ['Mul']}),
  269. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  270. 'skip': ['backward']}),
  271. # input is Tensor(bool)
  272. ('Square1', {
  273. 'block': (P.Square(),
  274. {'exception': TypeError, 'error_keywords': ['Square']}),
  275. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  276. 'skip': ['backward']}),
  277. # input is Tensor(bool)
  278. ('Rsqrt1', {
  279. 'block': (P.Rsqrt(),
  280. {'exception': TypeError, 'error_keywords': ['Rsqrt']}),
  281. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  282. 'skip': ['backward']}),
  283. # input is Tensor(bool)
  284. ('Sqrt1', {
  285. 'block': (P.Sqrt(),
  286. {'exception': TypeError, 'error_keywords': ['Sqrt']}),
  287. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  288. 'skip': ['backward']}),
  289. # input is not Tensor
  290. ('Reciprocal1', {
  291. 'block': (P.Reciprocal(),
  292. {'exception': TypeError, 'error_keywords': ['Reciprocal']}),
  293. 'desc_inputs': [5.0],
  294. 'skip': ['backward']}),
  295. # input x is Tensor(bool)
  296. ('Pow1', {
  297. 'block': (P.Pow(),
  298. {'exception': TypeError, 'error_keywords': ['Pow']}),
  299. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_)), 2.0],
  300. 'skip': ['backward']}),
  301. # input is not Tensor
  302. ('Exp1', {
  303. 'block': (P.Exp(),
  304. {'exception': TypeError, 'error_keywords': ['Exp']}),
  305. 'desc_inputs': [5.0],
  306. 'skip': ['backward']}),
  307. # input is not Tensor
  308. ('Log1', {
  309. 'block': (P.Log(),
  310. {'exception': TypeError, 'error_keywords': ['Log']}),
  311. 'desc_inputs': [5.0],
  312. 'skip': ['backward']}),
  313. # one input is scalar, and another is Tensor(float32)
  314. ('Minimum0', {
  315. 'block': (P.Minimum(), {'exception': TypeError, 'error_keywords': ['Minimum']}),
  316. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  317. 'skip': ['backward']}),
  318. # input two tensors, but element types are not same
  319. ('Minimum1', {
  320. 'block': (P.Minimum(), {'exception': TypeError, 'error_keywords': ['Minimum']}),
  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. ('Minimum2', {
  325. 'block': (P.Minimum(), {'exception': ValueError, 'error_keywords': ['Minimum']}),
  326. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  327. 'skip': ['backward']}),
  328. # one input is scalar, and another is Tensor(float32)
  329. ('Maximum0', {
  330. 'block': (P.Maximum(), {'exception': TypeError, 'error_keywords': ['Maximum']}),
  331. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  332. 'skip': ['backward']}),
  333. # input two tensors, but element types are not same
  334. ('Maximum1', {
  335. 'block': (P.Maximum(), {'exception': TypeError, 'error_keywords': ['Maximum']}),
  336. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  337. 'skip': ['backward']}),
  338. # input two tensors, their shapes do not match
  339. ('Maximum2', {
  340. 'block': (P.Maximum(), {'exception': ValueError, 'error_keywords': ['Maximum']}),
  341. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  342. 'skip': ['backward']}),
  343. # one input is scalar, and another is Tensor(float32)
  344. ('RealDiv0', {
  345. 'block': (P.RealDiv(), {'exception': TypeError, 'error_keywords': ['RealDiv']}),
  346. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  347. 'skip': ['backward']}),
  348. # input two tensors, but element types are not same
  349. ('RealDiv1', {
  350. 'block': (P.RealDiv(), {'exception': TypeError, 'error_keywords': ['RealDiv']}),
  351. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  352. 'skip': ['backward']}),
  353. # input two tensors, their shapes do not match
  354. ('RealDiv2', {
  355. 'block': (P.RealDiv(), {'exception': ValueError, 'error_keywords': ['RealDiv']}),
  356. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  357. 'skip': ['backward']}),
  358. # one input is scalar, and another is Tensor(float32)
  359. ('Div0', {
  360. 'block': (P.Div(), {'exception': TypeError, 'error_keywords': ['Div']}),
  361. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  362. 'skip': ['backward']}),
  363. # input two tensors, but element types are not same
  364. ('Div1', {
  365. 'block': (P.Div(), {'exception': TypeError, 'error_keywords': ['Div']}),
  366. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  367. 'skip': ['backward']}),
  368. # input two tensors, their shapes do not match
  369. ('Div2', {
  370. 'block': (P.Div(), {'exception': ValueError, 'error_keywords': ['Div']}),
  371. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  372. 'skip': ['backward']}),
  373. # one input is scalar, and another is Tensor(float32)
  374. ('FloorDiv0', {
  375. 'block': (P.FloorDiv(), {'exception': TypeError, 'error_keywords': ['FloorDiv']}),
  376. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  377. 'skip': ['backward']}),
  378. # input two tensors, but element types are not same
  379. ('FloorDiv1', {
  380. 'block': (P.FloorDiv(), {'exception': TypeError, 'error_keywords': ['FloorDiv']}),
  381. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  382. 'skip': ['backward']}),
  383. # input two tensors, their shapes do not match
  384. ('FloorDiv2', {
  385. 'block': (P.FloorDiv(), {'exception': ValueError, 'error_keywords': ['FloorDiv']}),
  386. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  387. 'skip': ['backward']}),
  388. # input x is Tensor(int32), not Tensor(float)
  389. ('Floor1', {
  390. 'block': (P.Floor(),
  391. {'exception': TypeError, 'error_keywords': ['Floor']}),
  392. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32))],
  393. 'skip': ['backward']}),
  394. # one input is scalar, and another is Tensor(float32)
  395. ('FloorMod0', {
  396. 'block': (P.FloorMod(), {'exception': TypeError, 'error_keywords': ['FloorMod']}),
  397. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  398. 'skip': ['backward']}),
  399. # input two tensors, but element types are not same
  400. ('FloorMod1', {
  401. 'block': (P.FloorMod(), {'exception': TypeError, 'error_keywords': ['FloorMod']}),
  402. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  403. 'skip': ['backward']}),
  404. # input two tensors, their shapes do not match
  405. ('FFloorMod2', {
  406. 'block': (P.FloorMod(), {'exception': ValueError, 'error_keywords': ['FloorMod']}),
  407. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  408. 'skip': ['backward']}),
  409. # input x is Tensor(int32), not Tensor(float)
  410. ('Acosh1', {
  411. 'block': (P.Acosh(),
  412. {'exception': TypeError, 'error_keywords': ['Acosh']}),
  413. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.bool_))],
  414. 'skip': ['backward']}),
  415. # input is not tensor
  416. ('Equal0', {
  417. 'block': (P.Equal(), {'exception': TypeError, 'error_keywords': ['Equal']}),
  418. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  419. 'skip': ['backward']}),
  420. # type of x and y not match
  421. ('Equal1', {
  422. 'block': (P.Equal(), {'exception': TypeError, 'error_keywords': ['Equal']}),
  423. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  424. 'skip': ['backward']}),
  425. # shape of x and y not match
  426. ('Equal2', {
  427. 'block': (P.Equal(), {'exception': ValueError, 'error_keywords': ['Equal']}),
  428. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  429. 'skip': ['backward']}),
  430. # input is not tensor
  431. ('EqualCount0', {
  432. 'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
  433. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  434. 'skip': ['backward']}),
  435. # type of x and y not match
  436. ('EqualCount1', {
  437. 'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
  438. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  439. 'skip': ['backward']}),
  440. # shape of x and y not match
  441. # input is not tensor
  442. ('NotEqual0', {
  443. 'block': (P.NotEqual(), {'exception': TypeError, 'error_keywords': ['NotEqual']}),
  444. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  445. 'skip': ['backward']}),
  446. # type of x and y not match
  447. ('NotEqual1', {
  448. 'block': (P.NotEqual(), {'exception': TypeError, 'error_keywords': ['NotEqual']}),
  449. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  450. 'skip': ['backward']}),
  451. # shape of x and y not match
  452. ('NotEqual2', {
  453. 'block': (P.NotEqual(), {'exception': ValueError, 'error_keywords': ['NotEqual']}),
  454. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  455. 'skip': ['backward']}),
  456. # input is not tensor
  457. ('Greater0', {
  458. 'block': (P.Greater(), {'exception': TypeError, 'error_keywords': ['Greater']}),
  459. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  460. 'skip': ['backward']}),
  461. # type of x and y not match
  462. ('Greater1', {
  463. 'block': (P.Greater(), {'exception': TypeError, 'error_keywords': ['Greater']}),
  464. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  465. 'skip': ['backward']}),
  466. # shape of x and y not match
  467. ('Greater2', {
  468. 'block': (P.Greater(), {'exception': ValueError, 'error_keywords': ['Greater']}),
  469. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  470. 'skip': ['backward']}),
  471. # input is not tensor
  472. ('GreaterEqual0', {
  473. 'block': (P.GreaterEqual(), {'exception': TypeError, 'error_keywords': ['GreaterEqual']}),
  474. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  475. 'skip': ['backward']}),
  476. # type of x and y not match
  477. ('GreaterEqual1', {
  478. 'block': (P.GreaterEqual(), {'exception': TypeError, 'error_keywords': ['GreaterEqual']}),
  479. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  480. 'skip': ['backward']}),
  481. # shape of x and y not match
  482. ('GreaterEqual2', {
  483. 'block': (P.GreaterEqual(), {'exception': ValueError, 'error_keywords': ['GreaterEqual']}),
  484. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  485. 'skip': ['backward']}),
  486. # input is not tensor
  487. ('Less0', {
  488. 'block': (P.Less(), {'exception': TypeError, 'error_keywords': ['Less']}),
  489. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  490. 'skip': ['backward']}),
  491. # type of x and y not match
  492. ('Less1', {
  493. 'block': (P.Less(), {'exception': TypeError, 'error_keywords': ['Less']}),
  494. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  495. 'skip': ['backward']}),
  496. # shape of x and y not match
  497. ('Less2', {
  498. 'block': (P.Less(), {'exception': ValueError, 'error_keywords': ['Less']}),
  499. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  500. 'skip': ['backward']}),
  501. # input is not tensor
  502. ('LessEqual0', {
  503. 'block': (P.LessEqual(), {'exception': TypeError, 'error_keywords': ['LessEqual']}),
  504. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  505. 'skip': ['backward']}),
  506. # type of x and y not match
  507. ('LessEqual1', {
  508. 'block': (P.LessEqual(), {'exception': TypeError, 'error_keywords': ['LessEqual']}),
  509. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  510. 'skip': ['backward']}),
  511. # shape of x and y not match
  512. ('LessEqual2', {
  513. 'block': (P.LessEqual(), {'exception': ValueError, 'error_keywords': ['LessEqual']}),
  514. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
  515. 'skip': ['backward']}),
  516. # input x is not Tensor(bool)
  517. ('LogicalNot1', {
  518. 'block': (P.LogicalNot(),
  519. {'exception': TypeError, 'error_keywords': ['LogicalNot']}),
  520. 'desc_inputs': [Tensor(np.ones([2, 3]).astype(np.int32))],
  521. 'skip': ['backward']}),
  522. # type of x and y not match
  523. ('LogicalAnd1', {
  524. 'block': (P.LogicalAnd(), {'exception': TypeError, 'error_keywords': ['LogicalAnd']}),
  525. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.bool_))],
  526. 'skip': ['backward']}),
  527. # shape of x and y not match
  528. ('LogicalAnd2', {
  529. 'block': (P.LogicalAnd(), {'exception': ValueError, 'error_keywords': ['LogicalAnd']}),
  530. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_)), Tensor(np.ones([3, 2]).astype(np.bool_))],
  531. 'skip': ['backward']}),
  532. # type of x and y not match
  533. ('LogicalOr1', {
  534. 'block': (P.LogicalOr(), {'exception': TypeError, 'error_keywords': ['LogicalOr']}),
  535. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.bool_))],
  536. 'skip': ['backward']}),
  537. # shape of x and y not match
  538. ('LogicalOr2', {
  539. 'block': (P.LogicalOr(), {'exception': ValueError, 'error_keywords': ['LogicalOr']}),
  540. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_)), Tensor(np.ones([3, 2]).astype(np.bool_))],
  541. 'skip': ['backward']}),
  542. # input is not tensor
  543. ('NPUGetFloatStatus0', {
  544. 'block': (P.NPUGetFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUGetFloatStatus']}),
  545. 'desc_inputs': [5.0],
  546. 'skip': ['backward']}),
  547. # input is Tensor(int32), not Tensor(float32)
  548. ('NPUGetFloatStatus1', {
  549. 'block': (P.NPUGetFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUGetFloatStatus']}),
  550. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  551. 'skip': ['backward']}),
  552. # dims is not 1
  553. ('NPUGetFloatStatus2', {
  554. 'block': (P.NPUGetFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUGetFloatStatus']}),
  555. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  556. 'skip': ['backward']}),
  557. # shape[0] is not 8
  558. ('NPUGetFloatStatus3', {
  559. 'block': (P.NPUGetFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUGetFloatStatus']}),
  560. 'desc_inputs': [Tensor(np.ones([3]).astype(np.float32))],
  561. 'skip': ['backward']}),
  562. # input is not tensor
  563. ('NPUClearFloatStatus0', {
  564. 'block': (P.NPUClearFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUClearFloatStatus']}),
  565. 'desc_inputs': [5.0],
  566. 'skip': ['backward']}),
  567. # input is Tensor(int32), not Tensor(float32)
  568. ('NPUClearFloatStatus1', {
  569. 'block': (P.NPUClearFloatStatus(), {'exception': TypeError, 'error_keywords': ['NPUClearFloatStatus']}),
  570. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  571. 'skip': ['backward']}),
  572. # dims is not 1
  573. ('NPUClearFloatStatus2', {
  574. 'block': (P.NPUClearFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUClearFloatStatus']}),
  575. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  576. 'skip': ['backward']}),
  577. # shape[0] is not 8
  578. ('NPUClearFloatStatus3', {
  579. 'block': (P.NPUClearFloatStatus(), {'exception': ValueError, 'error_keywords': ['NPUClearFloatStatus']}),
  580. 'desc_inputs': [Tensor(np.ones([3]).astype(np.float32))],
  581. 'skip': ['backward']}),
  582. # input is not tensor
  583. ('Cos0', {
  584. 'block': (P.Cos(), {'exception': TypeError, 'error_keywords': ['Cos']}),
  585. 'desc_inputs': [5.0],
  586. 'skip': ['backward']}),
  587. # input is Tensor(bool)
  588. ('Cos1', {
  589. 'block': (P.Cos(), {'exception': TypeError, 'error_keywords': ['Cos']}),
  590. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  591. 'skip': ['backward']}),
  592. # input is not tensor
  593. ('ACos0', {
  594. 'block': (P.ACos(), {'exception': TypeError, 'error_keywords': ['ACos']}),
  595. 'desc_inputs': [5.0],
  596. 'skip': ['backward']}),
  597. # input is Tensor(bool)
  598. ('ACos1', {
  599. 'block': (P.ACos(), {'exception': TypeError, 'error_keywords': ['ACos']}),
  600. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  601. 'skip': ['backward']}),
  602. # input is not tensor
  603. ('Sin0', {
  604. 'block': (P.Sin(), {'exception': TypeError, 'error_keywords': ['Sin']}),
  605. 'desc_inputs': [5.0],
  606. 'skip': ['backward']}),
  607. # input is Tensor(bool)
  608. ('Sin1', {
  609. 'block': (P.Sin(), {'exception': TypeError, 'error_keywords': ['Sin']}),
  610. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  611. 'skip': ['backward']}),
  612. # input is not tensor
  613. ('NMSWithMask0', {
  614. 'block': (P.NMSWithMask(), {'exception': TypeError, 'error_keywords': ['NMSWithMask']}),
  615. 'desc_inputs': [5.0],
  616. 'skip': ['backward']}),
  617. # input is not Tensor(float16) or Tensor(float32)
  618. ('NMSWithMask1', {
  619. 'block': (P.NMSWithMask(), {'exception': TypeError, 'error_keywords': ['NMSWithMask']}),
  620. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  621. 'skip': ['backward']}),
  622. # dims is not 2
  623. ('NMSWithMask2', {
  624. 'block': (P.NMSWithMask(), {'exception': ValueError, 'error_keywords': ['NMSWithMask']}),
  625. 'desc_inputs': [Tensor(np.ones([3, 4, 2]).astype(np.float32))],
  626. 'skip': ['backward']}),
  627. # shape[1] is not 5
  628. ('NMSWithMask3', {
  629. 'block': (P.NMSWithMask(), {'exception': ValueError, 'error_keywords': ['NMSWithMask']}),
  630. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.float32))],
  631. 'skip': ['backward']}),
  632. # input is not tensor
  633. ('Abs0', {
  634. 'block': (P.Abs(), {'exception': TypeError, 'error_keywords': ['Abs']}),
  635. 'desc_inputs': [5.0],
  636. 'skip': ['backward']}),
  637. # input is Tensor(bool)
  638. ('Abs1', {
  639. 'block': (P.Abs(), {'exception': TypeError, 'error_keywords': ['Abs']}),
  640. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  641. 'skip': ['backward']}),
  642. # input is not tensor
  643. ('Sign0', {
  644. 'block': (P.Sign(), {'exception': TypeError, 'error_keywords': ['Sign']}),
  645. 'desc_inputs': [5.0],
  646. 'skip': ['backward']}),
  647. # input is Tensor(bool)
  648. ('Sign1', {
  649. 'block': (P.Sign(), {'exception': TypeError, 'error_keywords': ['Sign']}),
  650. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  651. 'skip': ['backward']}),
  652. # input is not tensor
  653. ('Round0', {
  654. 'block': (P.Round(), {'exception': TypeError, 'error_keywords': ['Round']}),
  655. 'desc_inputs': [5.0],
  656. 'skip': ['backward']}),
  657. # input is Tensor(bool)
  658. ('Round1', {
  659. 'block': (P.Round(), {'exception': TypeError, 'error_keywords': ['Round']}),
  660. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  661. 'skip': ['backward']}),
  662. # one input is scalar, and another is Tensor(float32)
  663. ('Atan20', {
  664. 'block': (P.Atan2(), {'exception': TypeError, 'error_keywords': ['Atan2']}),
  665. 'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
  666. 'skip': ['backward']}),
  667. # input two tensors, but element types are not same
  668. ('Atan21', {
  669. 'block': (P.Atan2(), {'exception': TypeError, 'error_keywords': ['Atan2']}),
  670. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  671. 'skip': ['backward']}),
  672. # input two tensors, their shapes do not match
  673. ('Atan22', {
  674. 'block': (P.Atan2(), {'exception': ValueError, 'error_keywords': ['Atan2']}),
  675. 'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float32))],
  676. 'skip': ['backward']}),
  677. ]
  678. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  679. def test_check_exception():
  680. return raise_set