• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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
16import numpy as np
17import pytest
18
19import mindspore.common.dtype as mstype
20import mindspore.context as context
21from mindspore.common.tensor import Tensor
22from mindspore.nn import Cell
23from mindspore.ops import operations as P
24from mindspore.ops.operations import _inner_ops as inner
25
26
27class Net(Cell):
28    def __init__(self, type0, type1):
29        super(Net, self).__init__()
30        self.Cast = P.Cast()
31        self.type0 = type0
32        self.type1 = type1
33
34    def construct(self, x0, x1):
35        output = (self.Cast(x0, self.type0),
36                  self.Cast(x1, self.type1))
37        return output
38
39
40class NetDynamic(Cell):
41    def __init__(self, type0, type1):
42        super(NetDynamic, self).__init__()
43        self.conv = inner.GpuConvertToDynamicShape()
44        self.Cast = P.Cast()
45        self.type0 = type0
46        self.type1 = type1
47
48    def construct(self, x0, x1):
49        x0_conv = self.conv(x0)
50        x1_conv = self.conv(x1)
51        output = (self.Cast(x0_conv, self.type0),
52                  self.Cast(x1_conv, self.type1))
53        return output
54
55
56@pytest.mark.level0
57@pytest.mark.platform_x86_gpu_training
58@pytest.mark.env_onecard
59def test_cast():
60    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
61    t0 = mstype.float16
62    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float16))
63    t1 = mstype.float32
64
65    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
66    net = Net(t0, t1)
67    output = net(x0, x1)
68    type0 = output[0].asnumpy().dtype
69    assert type0 == 'float16'
70    type1 = output[1].asnumpy().dtype
71    assert type1 == 'float32'
72
73
74@pytest.mark.level1
75@pytest.mark.platform_x86_gpu_training
76@pytest.mark.env_onecard
77def test_cast1():
78    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
79    t0 = mstype.float32
80    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
81    t1 = mstype.float32
82
83    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
84    net = Net(t0, t1)
85    output = net(x0, x1)
86    type0 = output[0].asnumpy().dtype
87    assert type0 == 'float32'
88    type1 = output[1].asnumpy().dtype
89    assert type1 == 'float32'
90
91@pytest.mark.level1
92@pytest.mark.platform_x86_gpu_training
93@pytest.mark.env_onecard
94def test_cast2():
95    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float16))
96    t0 = mstype.int32
97    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float16))
98    t1 = mstype.float64
99
100    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
101    net = Net(t0, t1)
102    output = net(x0, x1)
103    type0 = output[0].asnumpy().dtype
104    assert type0 == 'int32'
105    type1 = output[1].asnumpy().dtype
106    assert type1 == 'float64'
107
108@pytest.mark.level1
109@pytest.mark.platform_x86_gpu_training
110@pytest.mark.env_onecard
111def test_cast3():
112    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64))
113    t0 = mstype.int32
114    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
115    t1 = mstype.int32
116
117    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
118    net = Net(t0, t1)
119    output = net(x0, x1)
120    type0 = output[0].asnumpy().dtype
121    assert type0 == 'int32'
122    type1 = output[1].asnumpy().dtype
123    assert type1 == 'int32'
124
125@pytest.mark.level1
126@pytest.mark.platform_x86_gpu_training
127@pytest.mark.env_onecard
128def test_cast4():
129    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
130    t0 = mstype.float16
131    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
132    t1 = mstype.int8
133
134    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
135    net = Net(t0, t1)
136    output = net(x0, x1)
137    type0 = output[0].asnumpy().dtype
138    assert type0 == 'float16'
139    type1 = output[1].asnumpy().dtype
140    assert type1 == 'int8'
141
142@pytest.mark.level1
143@pytest.mark.platform_x86_gpu_training
144@pytest.mark.env_onecard
145def test_cast5():
146    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
147    t0 = mstype.uint8
148    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
149    t1 = mstype.bool_
150
151    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
152    net = Net(t0, t1)
153    output = net(x0, x1)
154    type0 = output[0].asnumpy().dtype
155    assert type0 == 'uint8'
156    type1 = output[1].asnumpy().dtype
157    assert type1 == 'bool'
158
159@pytest.mark.level1
160@pytest.mark.platform_x86_gpu_training
161@pytest.mark.env_onecard
162def test_cast6():
163    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
164    t0 = mstype.float64
165    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
166    t1 = mstype.float32
167
168    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
169    net = Net(t0, t1)
170    output = net(x0, x1)
171    type0 = output[0].asnumpy().dtype
172    assert type0 == 'float64'
173    type1 = output[1].asnumpy().dtype
174    assert type1 == 'float32'
175
176@pytest.mark.level1
177@pytest.mark.platform_x86_gpu_training
178@pytest.mark.env_onecard
179def test_cast7():
180    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
181    t0 = mstype.float32
182    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
183    t1 = mstype.float16
184
185    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
186    net = Net(t0, t1)
187    output = net(x0, x1)
188    type0 = output[0].asnumpy().dtype
189    assert type0 == 'float32'
190    type1 = output[1].asnumpy().dtype
191    assert type1 == 'float16'
192
193@pytest.mark.level1
194@pytest.mark.platform_x86_gpu_training
195@pytest.mark.env_onecard
196def test_cast8():
197    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
198    t0 = mstype.int32
199    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
200    t1 = mstype.int16
201
202    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
203    net = Net(t0, t1)
204    output = net(x0, x1)
205    type0 = output[0].asnumpy().dtype
206    assert type0 == 'int32'
207    type1 = output[1].asnumpy().dtype
208    assert type1 == 'int16'
209
210@pytest.mark.level1
211@pytest.mark.platform_x86_gpu_training
212@pytest.mark.env_onecard
213def test_cast9():
214    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
215    t0 = mstype.int64
216    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
217    t1 = mstype.float16
218
219    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
220    net = Net(t0, t1)
221    output = net(x0, x1)
222    type0 = output[0].asnumpy().dtype
223    assert type0 == 'int64'
224    type1 = output[1].asnumpy().dtype
225    assert type1 == 'float16'
226
227@pytest.mark.level0
228@pytest.mark.platform_x86_gpu_training
229@pytest.mark.env_onecard
230def test_cast10():
231    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
232    t0 = mstype.int8
233    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
234    t1 = mstype.float64
235
236    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
237    net = Net(t0, t1)
238    output = net(x0, x1)
239    type0 = output[0].asnumpy().dtype
240    assert type0 == 'int8'
241    type1 = output[1].asnumpy().dtype
242    assert type1 == 'float64'
243
244@pytest.mark.level1
245@pytest.mark.platform_x86_gpu_training
246@pytest.mark.env_onecard
247def test_cast11():
248    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
249    t0 = mstype.int16
250    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
251    t1 = mstype.int32
252
253    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
254    net = Net(t0, t1)
255    output = net(x0, x1)
256    type0 = output[0].asnumpy().dtype
257    assert type0 == 'int16'
258    type1 = output[1].asnumpy().dtype
259    assert type1 == 'int32'
260
261@pytest.mark.level1
262@pytest.mark.platform_x86_gpu_training
263@pytest.mark.env_onecard
264def test_cast12():
265    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.bool))
266    t0 = mstype.int64
267    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.uint8))
268    t1 = mstype.float32
269
270    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
271    net = Net(t0, t1)
272    output = net(x0, x1)
273    type0 = output[0].asnumpy().dtype
274    assert type0 == 'int64'
275    type1 = output[1].asnumpy().dtype
276    assert type1 == 'float32'
277
278@pytest.mark.level1
279@pytest.mark.platform_x86_gpu_training
280@pytest.mark.env_onecard
281def test_cast13():
282    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.uint8))
283    t0 = mstype.int32
284    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.uint8))
285    t1 = mstype.float16
286
287    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
288    net = Net(t0, t1)
289    output = net(x0, x1)
290    type0 = output[0].asnumpy().dtype
291    assert type0 == 'int32'
292    type1 = output[1].asnumpy().dtype
293    assert type1 == 'float16'
294
295@pytest.mark.level0
296@pytest.mark.platform_x86_gpu_training
297@pytest.mark.env_onecard
298def test_cast14():
299    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
300    t0 = mstype.float64
301    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
302    t1 = mstype.float32
303
304    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
305    net = Net(t0, t1)
306    output = net(x0, x1)
307    type0 = output[0].asnumpy().dtype
308    assert type0 == 'float64'
309    type1 = output[1].asnumpy().dtype
310    assert type1 == 'float32'
311
312@pytest.mark.level1
313@pytest.mark.platform_x86_gpu_training
314@pytest.mark.env_onecard
315def test_cast15():
316    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
317    t0 = mstype.float16
318    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
319    t1 = mstype.int32
320
321    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
322    net = Net(t0, t1)
323    output = net(x0, x1)
324    type0 = output[0].asnumpy().dtype
325    assert type0 == 'float16'
326    type1 = output[1].asnumpy().dtype
327    assert type1 == 'int32'
328
329@pytest.mark.level1
330@pytest.mark.platform_x86_gpu_training
331@pytest.mark.env_onecard
332def test_cast16():
333    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
334    t0 = mstype.float16
335    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64))
336    t1 = mstype.float64
337
338    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
339    net = Net(t0, t1)
340    output = net(x0, x1)
341    type0 = output[0].asnumpy().dtype
342    assert type0 == 'float16'
343    type1 = output[1].asnumpy().dtype
344    assert type1 == 'float64'
345
346@pytest.mark.level1
347@pytest.mark.platform_x86_gpu_training
348@pytest.mark.env_onecard
349def test_cast17():
350    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
351    t0 = mstype.float32
352    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
353    t1 = mstype.float16
354
355    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
356    net = Net(t0, t1)
357    output = net(x0, x1)
358    type0 = output[0].asnumpy().dtype
359    assert type0 == 'float32'
360    type1 = output[1].asnumpy().dtype
361    assert type1 == 'float16'
362
363@pytest.mark.level1
364@pytest.mark.platform_x86_gpu_training
365@pytest.mark.env_onecard
366def test_cast18():
367    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64))
368    t0 = mstype.float32
369    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64))
370    t1 = mstype.float16
371
372    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
373    net = Net(t0, t1)
374    output = net(x0, x1)
375    type0 = output[0].asnumpy().dtype
376    assert type0 == 'float32'
377    type1 = output[1].asnumpy().dtype
378    assert type1 == 'float16'
379
380@pytest.mark.level1
381@pytest.mark.platform_x86_gpu_training
382@pytest.mark.env_onecard
383def test_cast19():
384    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8))
385    t0 = mstype.bool_
386    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16))
387    t1 = mstype.bool_
388
389    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
390    net = Net(t0, t1)
391    output = net(x0, x1)
392    type0 = output[0].asnumpy().dtype
393    assert type0 == 'bool'
394    type1 = output[1].asnumpy().dtype
395    assert type1 == 'bool'
396
397@pytest.mark.level1
398@pytest.mark.platform_x86_gpu_training
399@pytest.mark.env_onecard
400def test_cast20():
401    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64))
402    t0 = mstype.bool_
403    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float16))
404    t1 = mstype.bool_
405
406    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
407    net = Net(t0, t1)
408    output = net(x0, x1)
409    type0 = output[0].asnumpy().dtype
410    assert type0 == 'bool'
411    type1 = output[1].asnumpy().dtype
412    assert type1 == 'bool'
413
414@pytest.mark.level1
415@pytest.mark.platform_x86_gpu_training
416@pytest.mark.env_onecard
417def test_cast21():
418    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
419    t0 = mstype.bool_
420    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
421    t1 = mstype.bool_
422
423    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
424    net = Net(t0, t1)
425    output = net(x0, x1)
426    type0 = output[0].asnumpy().dtype
427    assert type0 == 'bool'
428    type1 = output[1].asnumpy().dtype
429    assert type1 == 'bool'
430
431@pytest.mark.level1
432@pytest.mark.platform_x86_gpu_training
433@pytest.mark.env_onecard
434def test_cast22():
435    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.uint8))
436    t0 = mstype.bool_
437    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
438    t1 = mstype.bool_
439
440    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
441    net = Net(t0, t1)
442    output = net(x0, x1)
443    type0 = output[0].asnumpy().dtype
444    assert type0 == 'bool'
445    type1 = output[1].asnumpy().dtype
446    assert type1 == 'bool'
447
448@pytest.mark.level1
449@pytest.mark.platform_x86_gpu_training
450@pytest.mark.env_onecard
451def test_cast23():
452    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
453    t0 = mstype.float32
454    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
455    t1 = mstype.float16
456
457    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
458    net = Net(t0, t1)
459    output = net(x0, x1)
460    type0 = output[0].asnumpy().dtype
461    assert type0 == 'float32'
462    type1 = output[1].asnumpy().dtype
463    assert type1 == 'float16'
464
465@pytest.mark.level1
466@pytest.mark.platform_x86_gpu_training
467@pytest.mark.env_onecard
468def test_cast24():
469    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
470    t0 = mstype.int64
471    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
472    t1 = mstype.int32
473
474    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
475    net = Net(t0, t1)
476    output = net(x0, x1)
477    type0 = output[0].asnumpy().dtype
478    assert type0 == 'int64'
479    type1 = output[1].asnumpy().dtype
480    assert type1 == 'int32'
481
482@pytest.mark.level1
483@pytest.mark.platform_x86_gpu_training
484@pytest.mark.env_onecard
485def test_cast25():
486    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
487    t0 = mstype.int16
488    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64))
489    t1 = mstype.int8
490
491    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
492    net = Net(t0, t1)
493    output = net(x0, x1)
494    type0 = output[0].asnumpy().dtype
495    assert type0 == 'int16'
496    type1 = output[1].asnumpy().dtype
497    assert type1 == 'int8'
498
499@pytest.mark.level1
500@pytest.mark.platform_x86_gpu_training
501@pytest.mark.env_onecard
502def test_cast26():
503    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
504    t0 = mstype.int64
505    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32))
506    t1 = mstype.float64
507
508    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
509    net = Net(t0, t1)
510    output = net(x0, x1)
511    type0 = output[0].asnumpy().dtype
512    assert type0 == 'int64'
513    type1 = output[1].asnumpy().dtype
514    assert type1 == 'float64'
515
516@pytest.mark.level1
517@pytest.mark.platform_x86_gpu_training
518@pytest.mark.env_onecard
519def test_cast27():
520    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
521    t0 = mstype.float64
522    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
523    t1 = mstype.uint64
524
525    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
526    net = Net(t0, t1)
527    output = net(x0, x1)
528    type0 = output[0].asnumpy().dtype
529    assert type0 == 'float64'
530    type1 = output[1].asnumpy().dtype
531    assert type1 == 'uint64'
532
533@pytest.mark.level1
534@pytest.mark.platform_x86_gpu_training
535@pytest.mark.env_onecard
536def test_cast28():
537    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
538    t0 = mstype.int8
539    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
540    t1 = mstype.int16
541
542    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
543    net = Net(t0, t1)
544    output = net(x0, x1)
545    type0 = output[0].asnumpy().dtype
546    assert type0 == 'int8'
547    type1 = output[1].asnumpy().dtype
548    assert type1 == 'int16'
549
550@pytest.mark.level0
551@pytest.mark.platform_x86_gpu_training
552@pytest.mark.env_onecard
553def test_cast29():
554    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
555    t0 = mstype.int64
556    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
557    t1 = mstype.uint8
558
559    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
560    net = Net(t0, t1)
561    output = net(x0, x1)
562    type0 = output[0].asnumpy().dtype
563    assert type0 == 'int64'
564    type1 = output[1].asnumpy().dtype
565    assert type1 == 'uint8'
566
567@pytest.mark.level1
568@pytest.mark.platform_x86_gpu_training
569@pytest.mark.env_onecard
570def test_cast30():
571    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
572    t0 = mstype.uint16
573    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
574    t1 = mstype.uint32
575
576    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
577    net = Net(t0, t1)
578    output = net(x0, x1)
579    type0 = output[0].asnumpy().dtype
580    assert type0 == 'uint16'
581    type1 = output[1].asnumpy().dtype
582    assert type1 == 'uint32'
583
584@pytest.mark.level1
585@pytest.mark.platform_x86_gpu_training
586@pytest.mark.env_onecard
587def test_cast31():
588    x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
589    t0 = mstype.uint16
590    x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32))
591    t1 = mstype.uint32
592
593    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
594    net = NetDynamic(t0, t1)
595    output = net(x0, x1)
596    type0 = output[0].asnumpy().dtype
597    assert type0 == 'uint16'
598    type1 = output[1].asnumpy().dtype
599    assert type1 == 'uint32'
600
601
602@pytest.mark.level0
603@pytest.mark.platform_x86_gpu_training
604@pytest.mark.env_onecard
605def test_cast32():
606    np.random.seed(10)
607    x = np.random.uniform(-5, 5, (3, 2)).astype(np.float16)
608    x0 = Tensor(x)
609    t0 = mstype.int32
610    x1 = Tensor(x)
611    t1 = mstype.float64
612
613    context.set_context(mode=context.GRAPH_MODE, device_target='GPU')
614    net = Net(t0, t1)
615    output = net(x0, x1)
616    type0 = output[0].asnumpy().dtype
617    assert type0 == 'int32'
618    expected = x.astype(np.int32)
619    assert (output[0].asnumpy() == expected).all()
620    type1 = output[1].asnumpy().dtype
621    assert type1 == 'float64'
622