@@ -542,6 +542,70 @@ def test_clip():
542
542
{'min' : - 1.0 , 'max' : 1.0 })
543
543
544
544
545
+
546
+ def test_round ():
547
+ _test_onnx_op_elementwise ((2 , 4 , 5 , 6 ), np .round , {}, 'float32' , 'Round' , {})
548
+
549
+
550
+ def _test_finite_ops (inshape , outfunc , npargs , dtype , opname , kwargs ):
551
+ indata = np .random .choice (a = [np .nan , np .inf , - np .inf , 0.5 , 1.0 , 0 ], size = inshape ).astype (dtype )
552
+
553
+ outdata = outfunc (indata , ** npargs )
554
+ y = helper .make_node (opname , ['in' ], ['out' ], ** kwargs )
555
+
556
+ graph = helper .make_graph ([y ],
557
+ opname + '_test' ,
558
+ inputs = [helper .make_tensor_value_info ("in" ,
559
+ TensorProto .FLOAT , list (indata .shape ))],
560
+ outputs = [helper .make_tensor_value_info ("out" ,
561
+ TensorProto .BOOL , list (outdata .shape ))])
562
+
563
+ model = helper .make_model (graph , producer_name = opname + '_test' )
564
+
565
+ for target , ctx in ctx_list ():
566
+ tvm_out = get_tvm_output (
567
+ model , indata , target , ctx , outdata .shape , dtype )
568
+
569
+ tvm .testing .assert_allclose (outdata , tvm_out )
570
+
571
+
572
+ def test_isinf ():
573
+ _test_finite_ops ((2 , 4 , 5 , 6 ), np .isinf , {}, 'float32' , 'IsInf' , {})
574
+
575
+
576
+ def test_isnan ():
577
+ _test_finite_ops ((2 , 4 , 5 , 6 ), np .isnan , {}, 'float32' , 'IsNaN' , {})
578
+
579
+
580
+ def verify_gather_nd (in_shape , indices , dtype ):
581
+ x = np .random .uniform (size = in_shape ).astype (dtype )
582
+ indices = np .array (indices , dtype = "int32" )
583
+ out_np = topi .testing .gather_nd_python (x , indices )
584
+
585
+ y = helper .make_node ("GatherND" , ['in' , 'indices' ], ['out' ])
586
+
587
+ graph = helper .make_graph ([y ],
588
+ 'gather_test' ,
589
+ inputs = [helper .make_tensor_value_info ("in" ,
590
+ TensorProto .FLOAT , list (in_shape )),
591
+ helper .make_tensor_value_info ("indices" ,
592
+ TensorProto .INT32 , list (indices .shape ))],
593
+ outputs = [helper .make_tensor_value_info ("out" ,
594
+ TensorProto .FLOAT , list (out_np .shape ))])
595
+ model = helper .make_model (graph , producer_name = 'gather_test' )
596
+
597
+ for target , ctx in ctx_list ():
598
+ tvm_out = get_tvm_output (
599
+ model , [x , indices ], target , ctx , out_np .shape )
600
+ tvm .testing .assert_allclose (out_np , tvm_out )
601
+
602
+
603
+ def test_gather_nd ():
604
+ verify_gather_nd ((2 , 2 ), [[0 ,0 ],[1 ,1 ]], 'int32' )
605
+ verify_gather_nd ((3 , 3 , 3 ), [[0 ,1 ],[1 ,0 ]] , 'float32' )
606
+ verify_gather_nd ((4 , 3 , 5 , 6 ), [[2 , 1 , 0 , 0 ]], 'float32' )
607
+
608
+
545
609
def test_onehot ():
546
610
indices_shape = [10 ]
547
611
indices_array = np .random .randint (
@@ -2379,11 +2443,15 @@ def verify_topk(input_dims, K, axis=-1):
2379
2443
test_slice ()
2380
2444
test_floor ()
2381
2445
test_ceil ()
2446
+ test_round ()
2447
+ test_isinf ()
2448
+ test_isnan ()
2382
2449
test_clip ()
2383
2450
test_onehot ()
2384
2451
test_matmul ()
2385
2452
test_batch_matmul ()
2386
2453
test_gather ()
2454
+ test_gather_nd ()
2387
2455
test_lrn ()
2388
2456
test_instance_norm ()
2389
2457
test_upsample ()
0 commit comments