@@ -559,6 +559,212 @@ def test_op_layer_normalization_big_eps(self):
559559 atol = 1e-4 ,
560560 )
561561
562+ def test_op_range_float (self ):
563+ model = oh .make_model (
564+ oh .make_graph (
565+ [oh .make_node ("Range" , ["start" , "limit" , "delta" ], ["Z" ])],
566+ "dummy" ,
567+ [
568+ oh .make_tensor_value_info ("start" , TFLOAT , []),
569+ oh .make_tensor_value_info ("limit" , TFLOAT , []),
570+ oh .make_tensor_value_info ("delta" , TFLOAT , []),
571+ ],
572+ [oh .make_tensor_value_info ("Z" , TFLOAT , ["a" ])],
573+ ),
574+ ir_version = 9 ,
575+ opset_imports = [oh .make_opsetid ("" , 18 )],
576+ )
577+ self ._finalize_test (
578+ model ,
579+ torch .tensor (2.1 , dtype = torch .float32 ),
580+ torch .tensor (5.1 , dtype = torch .float32 ),
581+ torch .tensor (1 , dtype = torch .float32 ),
582+ )
583+
584+ def test_op_range_int64 (self ):
585+ model = oh .make_model (
586+ oh .make_graph (
587+ [oh .make_node ("Range" , ["start" , "limit" , "delta" ], ["Z" ])],
588+ "dummy" ,
589+ [
590+ oh .make_tensor_value_info ("start" , TINT64 , []),
591+ oh .make_tensor_value_info ("limit" , TINT64 , []),
592+ oh .make_tensor_value_info ("delta" , TINT64 , []),
593+ ],
594+ [oh .make_tensor_value_info ("Z" , TINT64 , ["a" ])],
595+ ),
596+ ir_version = 9 ,
597+ opset_imports = [oh .make_opsetid ("" , 18 )],
598+ )
599+ self ._finalize_test (
600+ model ,
601+ torch .tensor (2 , dtype = torch .int64 ),
602+ torch .tensor (5 , dtype = torch .int64 ),
603+ torch .tensor (1 , dtype = torch .int64 ),
604+ )
605+
606+ def test_op_range_int64_h2 (self ):
607+ model = oh .make_model (
608+ oh .make_graph (
609+ [oh .make_node ("Range" , ["start" , "limit" , "delta" ], ["Z" ])],
610+ "dummy" ,
611+ [
612+ oh .make_tensor_value_info ("start" , TINT64 , []),
613+ oh .make_tensor_value_info ("limit" , TINT64 , []),
614+ oh .make_tensor_value_info ("delta" , TINT64 , []),
615+ ],
616+ [oh .make_tensor_value_info ("Z" , TINT64 , ["a" ])],
617+ ),
618+ ir_version = 9 ,
619+ opset_imports = [oh .make_opsetid ("" , 18 )],
620+ )
621+ self ._finalize_test (
622+ model ,
623+ torch .tensor (2 , dtype = torch .int64 ),
624+ torch .tensor (5 , dtype = torch .int64 ),
625+ torch .tensor (2 , dtype = torch .int64 ),
626+ )
627+
628+ def test_op_expand (self ):
629+ model = oh .make_model (
630+ oh .make_graph (
631+ [oh .make_node ("Expand" , ["X" , "shape" ], ["Y" ])],
632+ "dummy" ,
633+ [
634+ oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" , "c" , "d" ]),
635+ oh .make_tensor_value_info ("shape" , TINT64 , ["f" ]),
636+ ],
637+ [oh .make_tensor_value_info ("Y" , TFLOAT , ["aa" , "ba" , "ca" , "da" ])],
638+ ),
639+ ir_version = 9 ,
640+ opset_imports = [oh .make_opsetid ("" , 18 )],
641+ )
642+ self ._finalize_test (
643+ model ,
644+ torch .rand ((1 , 5 , 6 , 7 ), dtype = torch .float32 ),
645+ torch .tensor ([4 , 5 , 1 , 1 ], dtype = torch .int64 ),
646+ )
647+
648+ def test_op_unary_op (self ):
649+ model = oh .make_model (
650+ oh .make_graph (
651+ [
652+ oh .make_node ("Cos" , ["X" ], ["nx" ]),
653+ oh .make_node ("Sin" , ["nx" ], ["t" ]),
654+ oh .make_node ("Exp" , ["t" ], ["u" ]),
655+ oh .make_node ("Log" , ["u" ], ["Z" ]),
656+ ],
657+ "dummy" ,
658+ [oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" ])],
659+ [oh .make_tensor_value_info ("Z" , TFLOAT , ["a" , "b" ])],
660+ ),
661+ ir_version = 9 ,
662+ opset_imports = [oh .make_opsetid ("" , 18 )],
663+ )
664+ onnx .checker .check_model (model )
665+ self ._finalize_test (model , torch .abs (torch .rand (3 , 4 , dtype = torch .float32 )), atol = 1e-6 )
666+
667+ def test_op_pow_op (self ):
668+ model = oh .make_model (
669+ oh .make_graph (
670+ [oh .make_node ("Pow" , ["X" , "Y" ], ["Z" ])],
671+ "dummy" ,
672+ [
673+ oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" ]),
674+ oh .make_tensor_value_info ("Y" , TFLOAT , ["a" , "b" ]),
675+ ],
676+ [oh .make_tensor_value_info ("Z" , TFLOAT , ["a" , "b" ])],
677+ ),
678+ ir_version = 9 ,
679+ opset_imports = [oh .make_opsetid ("" , 18 )],
680+ )
681+ onnx .checker .check_model (model )
682+ self ._finalize_test (
683+ model ,
684+ torch .abs (torch .rand (3 , 4 , 5 , dtype = torch .float32 )),
685+ torch .abs (torch .rand (3 , 4 , 5 , dtype = torch .float32 )),
686+ atol = 1e-7 ,
687+ )
688+
689+ def test_op_pow_op_int (self ):
690+ model = oh .make_model (
691+ oh .make_graph (
692+ [oh .make_node ("Pow" , ["X" , "Y" ], ["Z" ])],
693+ "dummy" ,
694+ [
695+ oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" ]),
696+ oh .make_tensor_value_info ("Y" , TINT64 , ["a" , "b" ]),
697+ ],
698+ [oh .make_tensor_value_info ("Z" , TFLOAT , ["a" , "b" ])],
699+ ),
700+ ir_version = 9 ,
701+ opset_imports = [oh .make_opsetid ("" , 18 )],
702+ )
703+ onnx .checker .check_model (model )
704+ self ._finalize_test (
705+ model ,
706+ torch .rand (3 , 4 , 5 , dtype = torch .float32 ),
707+ torch .tensor ([2 ], dtype = torch .int64 ),
708+ atol = 1e-7 ,
709+ )
710+
711+ def test_op_sqrt_op (self ):
712+ model = oh .make_model (
713+ oh .make_graph (
714+ [oh .make_node ("Sqrt" , ["X" ], ["Z" ])],
715+ "dummy" ,
716+ [oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" ])],
717+ [oh .make_tensor_value_info ("Z" , TFLOAT , ["a" , "b" ])],
718+ ),
719+ ir_version = 9 ,
720+ opset_imports = [oh .make_opsetid ("" , 18 )],
721+ )
722+ onnx .checker .check_model (model )
723+ self ._finalize_test (model , torch .abs (torch .rand (3 , 4 , dtype = torch .float32 )), atol = 1e-6 )
724+
725+ def test_op_split_op (self ):
726+ model = oh .make_model (
727+ oh .make_graph (
728+ [oh .make_node ("Split" , ["X" ], ["Z1" , "Z2" ], axis = 1 , num_outputs = 2 )],
729+ "dummy" ,
730+ [oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" ])],
731+ [
732+ oh .make_tensor_value_info ("Z1" , TFLOAT , ["a" , "b1" ]),
733+ oh .make_tensor_value_info ("Z2" , TFLOAT , ["a" , "b2" ]),
734+ ],
735+ ),
736+ ir_version = 9 ,
737+ opset_imports = [oh .make_opsetid ("" , 18 )],
738+ )
739+ onnx .checker .check_model (model )
740+ self ._finalize_test (model , torch .rand (3 , 5 , dtype = torch .float32 ), use_ort = True )
741+ self ._finalize_test (model , torch .rand (3 , 6 , dtype = torch .float32 ), use_ort = True )
742+
743+ def test_op_split_op_sizes (self ):
744+ model = oh .make_model (
745+ oh .make_graph (
746+ [oh .make_node ("Split" , ["X" , "split" ], ["Z1" , "Z2" ], axis = 1 )],
747+ "dummy" ,
748+ [
749+ oh .make_tensor_value_info ("X" , TFLOAT , ["a" , "b" ]),
750+ oh .make_tensor_value_info ("split" , TINT64 , [2 ]),
751+ ],
752+ [
753+ oh .make_tensor_value_info ("Z1" , TFLOAT , ["a" , "b1" ]),
754+ oh .make_tensor_value_info ("Z2" , TFLOAT , ["a" , "b2" ]),
755+ ],
756+ ),
757+ ir_version = 9 ,
758+ opset_imports = [oh .make_opsetid ("" , 18 )],
759+ )
760+ onnx .checker .check_model (model )
761+ self ._finalize_test (
762+ model ,
763+ torch .rand (3 , 5 , dtype = torch .float32 ),
764+ torch .tensor ([2 , 3 ], dtype = torch .int64 ),
765+ use_ort = True ,
766+ )
767+
562768
563769if __name__ == "__main__" :
564770 unittest .main (verbosity = 2 )
0 commit comments