@@ -521,34 +521,39 @@ def set_case(self):
521521 self .op_type = "square"
522522 self .dtype = self .in_type
523523 self .init_config ()
524+ if self .dtype == np .uint16 :
525+ # bfloat16 actually
526+ self .x = convert_float_to_uint16 (self .tmp_x )
527+ else :
528+ self .x = self .tmp_x .astype (self .dtype )
524529 out = np .square (self .x )
525530
526531 self .attrs = {'use_xpu' : True }
527532 self .inputs = {'X' : OpTest .np_dtype_to_base_dtype (self .x )}
528533 self .outputs = {'Out' : out }
529534
530535 def init_config (self ):
531- self .x = np .random .uniform (- 1 , 1 , [11 , 17 ]). astype ( self . dtype )
536+ self .tmp_x = np .random .uniform (- 1 , 1 , [11 , 17 ])
532537
533538 class XPUTestSquare_ZeroDim (XPUTestSquare ):
534539 def init_config (self ):
535- self .x = np .random .uniform (- 2 , 2 , []). astype ( self . dtype )
540+ self .tmp_x = np .random .uniform (- 2 , 2 , [])
536541
537542 class XPUTestSquare2 (XPUTestSquare ):
538543 def init_config (self ):
539- self .x = np .random .uniform (- 2 , 2 , [100 ]). astype ( self . dtype )
544+ self .tmp_x = np .random .uniform (- 2 , 2 , [100 ])
540545
541546 class XPUTestSquare3 (XPUTestSquare ):
542547 def init_config (self ):
543- self .x = np .random .uniform (- 2 , 2 , [1 , 15 , 19 ]). astype ( self . dtype )
548+ self .tmp_x = np .random .uniform (- 2 , 2 , [1 , 15 , 19 ])
544549
545550 class XPUTestSquare4 (XPUTestSquare ):
546551 def init_config (self ):
547- self .x = np .random .uniform (- 2 , 2 , [100 , 10 ]). astype ( self . dtype )
552+ self .tmp_x = np .random .uniform (- 2 , 2 , [100 , 10 ])
548553
549554 class XPUTestSquare5 (XPUTestSquare ):
550555 def init_config (self ):
551- self .x = np .random .uniform (- 2 , 2 , [1 , 2 , 5 , 17 ]). astype ( self . dtype )
556+ self .tmp_x = np .random .uniform (- 2 , 2 , [1 , 2 , 5 , 17 ])
552557
553558
554559support_types = get_xpu_op_support_types ('square' )
@@ -1297,38 +1302,35 @@ def set_case(self):
12971302 self .dtype = self .in_type
12981303
12991304 self .init_config ()
1305+ if self .dtype == np .uint16 :
1306+ # bfloat16 actually
1307+ self .x = convert_float_to_uint16 (self .tmp_x )
1308+ else :
1309+ self .x = self .tmp_x .astype (self .dtype )
13001310 out = np .sin (self .x )
13011311
13021312 self .inputs = {'X' : self .x }
13031313 self .outputs = {'Out' : out }
13041314 self .attrs = {'use_xpu' : True }
13051315
13061316 def init_config (self ):
1307- self .x = np .random .uniform (- np .pi , np .pi , [11 , 17 ]).astype (
1308- self .dtype
1309- )
1317+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [11 , 17 ])
13101318
13111319 class XPUTestSin_ZeroDim (XPUTestSinBase ):
13121320 def init_config (self ):
1313- self .x = np .random .uniform (- np .pi , np .pi , []). astype ( self . dtype )
1321+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [])
13141322
13151323 class XPUTestSin2 (XPUTestSinBase ):
13161324 def init_config (self ):
1317- self .x = np .random .uniform (- np .pi , np .pi , [1024 , 8 ]).astype (
1318- self .dtype
1319- )
1325+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [1024 , 8 ])
13201326
13211327 class XPUTestSin3 (XPUTestSinBase ):
13221328 def init_config (self ):
1323- self .x = np .random .uniform (- np .pi , np .pi , [4 , 512 , 15 , 15 ]).astype (
1324- self .dtype
1325- )
1329+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [4 , 512 , 15 , 15 ])
13261330
13271331 class XPUTestSin4 (XPUTestSinBase ):
13281332 def init_config (self ):
1329- self .x = np .random .uniform (- np .pi , np .pi , [4 , 256 , 22 , 22 ]).astype (
1330- self .dtype
1331- )
1333+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [4 , 256 , 22 , 22 ])
13321334
13331335
13341336support_types = get_xpu_op_support_types ('sin' )
@@ -1347,38 +1349,35 @@ def set_case(self):
13471349 self .dtype = self .in_type
13481350
13491351 self .init_config ()
1352+ if self .dtype == np .uint16 :
1353+ # bfloat16 actually
1354+ self .x = convert_float_to_uint16 (self .tmp_x )
1355+ else :
1356+ self .x = self .tmp_x .astype (self .dtype )
13501357 out = np .cos (self .x )
13511358
13521359 self .inputs = {'X' : self .x }
13531360 self .outputs = {'Out' : out }
13541361 self .attrs = {'use_xpu' : True }
13551362
13561363 def init_config (self ):
1357- self .x = np .random .uniform (- np .pi , np .pi , [11 , 17 ]).astype (
1358- self .dtype
1359- )
1364+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [11 , 17 ])
13601365
13611366 class XPUTestCos_ZeroDim (XPUTestCosBase ):
13621367 def init_config (self ):
1363- self .x = np .random .uniform (- np .pi , np .pi , []). astype ( self . dtype )
1368+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [])
13641369
13651370 class XPUTestCos2 (XPUTestCosBase ):
13661371 def init_config (self ):
1367- self .x = np .random .uniform (- np .pi , np .pi , [1024 , 8 ]).astype (
1368- self .dtype
1369- )
1372+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [1024 , 8 ])
13701373
13711374 class XPUTestCos3 (XPUTestCosBase ):
13721375 def init_config (self ):
1373- self .x = np .random .uniform (- np .pi , np .pi , [4 , 512 , 15 , 15 ]).astype (
1374- self .dtype
1375- )
1376+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [4 , 512 , 15 , 15 ])
13761377
13771378 class XPUTestCos4 (XPUTestCosBase ):
13781379 def init_config (self ):
1379- self .x = np .random .uniform (- np .pi , np .pi , [4 , 256 , 22 , 22 ]).astype (
1380- self .dtype
1381- )
1380+ self .tmp_x = np .random .uniform (- np .pi , np .pi , [4 , 256 , 22 , 22 ])
13821381
13831382
13841383support_types = get_xpu_op_support_types ('cos' )
0 commit comments