@@ -360,7 +360,7 @@ def test_forward_concatenation():
360360# ---
361361
362362def _test_elemwise (math_op , data , fused_activation_function = None ):
363- """ One iteration of add """
363+ """ One iteration of elemwise """
364364
365365 assert len (data ) == 2
366366
@@ -457,6 +457,74 @@ def test_all_elemwise():
457457 _test_forward_elemwise (_test_maximum )
458458 _test_forward_elemwise (_test_minimum )
459459
460+ #######################################################################
461+ # Reduce
462+ # ------
463+
464+ def _test_reduce (math_op , data , keep_dims = None ):
465+ """ One iteration of reduce """
466+
467+ assert len (data ) == 2
468+
469+ # Test with tensor and constant
470+ with tf .Graph ().as_default ():
471+ in_data = array_ops .placeholder (shape = data [0 ].shape , dtype = data [0 ].dtype , name = 'in' )
472+ out = math_op (in_data , data [1 ], keep_dims )
473+ compare_tflite_with_tvm ([data [0 ]], ['in:0' ], [in_data ], [out ])
474+
475+
476+ #######################################################################
477+ # Reduce_min
478+ # ----------
479+
480+ def _test_reduce_min (data , keep_dims = None ):
481+ """ One iteration of reduce_min """
482+ return _test_reduce (math_ops .reduce_min , data , keep_dims )
483+
484+ #######################################################################
485+ # Reduce_max
486+ # ----------
487+
488+ def _test_reduce_max (data , keep_dims = None ):
489+ """ One iteration of reduce_max """
490+ return _test_reduce (math_ops .reduce_max , data , keep_dims )
491+
492+ #######################################################################
493+ # Reduce_mean
494+ # -----------
495+
496+ def _test_reduce_mean (data , keep_dims = None ):
497+ """ One iteration of reduce_mean """
498+ return _test_reduce (math_ops .reduce_mean , data , keep_dims )
499+
500+ #######################################################################
501+ # Reduce_prod
502+ # -----------
503+
504+ def _test_reduce_prod (data , keep_dims = None ):
505+ """ One iteration of reduce_prod """
506+ return _test_reduce (math_ops .reduce_prod , data , keep_dims )
507+
508+
509+ def _test_forward_reduce (testop ):
510+ """ Reduce """
511+ data0 = [np .random .rand (16 , 16 , 16 , 16 ).astype ("float32" ), None ]
512+ data1 = [np .random .rand (16 , 16 , 16 , 16 ).astype ("float32" ), np .array ([1 , 2 ], dtype = np .int32 )]
513+ testop (data0 )
514+ testop (data0 , keep_dims = False )
515+ testop (data0 , keep_dims = True )
516+ testop (data1 )
517+ testop (data1 , keep_dims = False )
518+ testop (data1 , keep_dims = True )
519+
520+
521+ def test_all_reduce ():
522+ _test_forward_reduce (_test_reduce_min )
523+ _test_forward_reduce (_test_reduce_max )
524+ _test_forward_reduce (_test_reduce_mean )
525+ _test_forward_reduce (_test_reduce_prod )
526+
527+
460528#######################################################################
461529# Squeeze
462530# -------
@@ -695,6 +763,9 @@ def test_forward_ssd_mobilenet_v1():
695763 # Elemwise
696764 test_all_elemwise ()
697765
766+ # Reduce
767+ test_all_reduce ()
768+
698769 # End to End
699770 test_forward_mobilenet_v1 ()
700771 test_forward_mobilenet_v2 ()
0 commit comments