@@ -503,6 +503,25 @@ def test_const_fold_unsqueeze_with_const(self):
503
503
model_proto = helper .make_model (graph , producer_name = "onnx-tests" )
504
504
self .run_and_compare (["res" ], {"X" : np .random .randn (1 ).astype (np .float32 )}, model_proto ,
505
505
"Unsqueeze" , 0 )
506
+
507
+ def test_const_fold_cast_with_const (self ):
508
+ shape = (6 , 6 )
509
+ const_tensor = helper .make_tensor (name = 'const_tensor' , data_type = TensorProto .FLOAT , dims = shape ,
510
+ vals = np .random .randn (* shape ).flatten ().astype (np .float32 ))
511
+ node1 = helper .make_node ("Constant" , [], ["const" ], value = const_tensor )
512
+ node2 = helper .make_node ("Cast" , ["const" ], ["value1" ], to = TensorProto .INT64 )
513
+ node3 = helper .make_node ("Add" , ["value1" , "X" ], ["res" ])
514
+
515
+ graph = helper .make_graph (
516
+ [node1 , node2 , node3 ],
517
+ "test_const_fold_cast_with_const" ,
518
+ [helper .make_tensor_value_info ("X" , TensorProto .INT64 , shape )],
519
+ [helper .make_tensor_value_info ("res" , TensorProto .INT64 , shape )],
520
+ )
521
+
522
+ model_proto = helper .make_model (graph , producer_name = "onnx-tests" )
523
+ self .run_and_compare (["res" ], {"X" : np .random .randn (* shape ).astype (np .int64 )}, model_proto ,
524
+ "Cast" , 0 )
506
525
# Const Fold Optimizer Tests End
507
526
508
527
0 commit comments