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