@@ -600,84 +600,87 @@ def test_true_rowvar(self):
600600 assert_allclose (result , expected )
601601
602602
603+ @testing .parameterize (
604+ * testing .product (
605+ {
606+ "func" : ("max" , "min" ),
607+ }
608+ )
609+ )
603610class TestMaxMin :
604- @pytest .mark .parametrize ("func" , ["max" , "min" ])
605611 @pytest .mark .parametrize ("axis" , [None , 0 , 1 , - 1 , 2 , - 2 , (1 , 2 ), (0 , - 2 )])
606612 @pytest .mark .parametrize ("keepdims" , [False , True ])
607613 @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_bool = True ))
608- def test_func (self , func , axis , keepdims , dtype ):
614+ def test_func (self , axis , keepdims , dtype ):
609615 a = numpy .arange (768 , dtype = dtype ).reshape ((4 , 4 , 6 , 8 ))
610616 ia = dpnp .array (a )
611617
612- expected = getattr (numpy , func )(a , axis = axis , keepdims = keepdims )
613- result = getattr (dpnp , func )(ia , axis = axis , keepdims = keepdims )
618+ expected = getattr (numpy , self . func )(a , axis = axis , keepdims = keepdims )
619+ result = getattr (dpnp , self . func )(ia , axis = axis , keepdims = keepdims )
614620 assert_dtype_allclose (result , expected )
615621
616- @pytest .mark .parametrize ("func" , ["max" , "min" ])
617622 @pytest .mark .parametrize ("axis" , [None , 0 , 1 , - 1 ])
618623 @pytest .mark .parametrize ("keepdims" , [False , True ])
619- def test_bool (self , func , axis , keepdims ):
624+ def test_bool (self , axis , keepdims ):
620625 a = numpy .arange (2 , dtype = numpy .bool_ )
621626 a = numpy .tile (a , (2 , 2 ))
622627 ia = dpnp .array (a )
623628
624- expected = getattr (numpy , func )(a , axis = axis , keepdims = keepdims )
625- result = getattr (dpnp , func )(ia , axis = axis , keepdims = keepdims )
629+ expected = getattr (numpy , self . func )(a , axis = axis , keepdims = keepdims )
630+ result = getattr (dpnp , self . func )(ia , axis = axis , keepdims = keepdims )
626631 assert_dtype_allclose (result , expected )
627632
628- @pytest .mark .parametrize ("func" , ["max" , "min" ])
629- def test_out (self , func ):
633+ def test_out (self ):
630634 a = numpy .arange (12 , dtype = numpy .float32 ).reshape ((2 , 2 , 3 ))
631635 ia = dpnp .array (a )
632636
633637 # out is dpnp_array
634- expected = getattr (numpy , func )(a , axis = 0 )
638+ expected = getattr (numpy , self . func )(a , axis = 0 )
635639 dpnp_out = dpnp .empty (expected .shape , dtype = expected .dtype )
636- result = getattr (dpnp , func )(ia , axis = 0 , out = dpnp_out )
640+ result = getattr (dpnp , self . func )(ia , axis = 0 , out = dpnp_out )
637641 assert dpnp_out is result
638642 assert_allclose (result , expected )
639643
640644 # out is usm_ndarray
641645 dpt_out = dpt .empty (expected .shape , dtype = expected .dtype )
642- result = getattr (dpnp , func )(ia , axis = 0 , out = dpt_out )
646+ result = getattr (dpnp , self . func )(ia , axis = 0 , out = dpt_out )
643647 assert dpt_out is result .get_array ()
644648 assert_allclose (result , expected )
645649
646650 # output is numpy array -> Error
647651 result = numpy .empty_like (expected )
648652 with pytest .raises (TypeError ):
649- getattr (dpnp , func )(ia , axis = 0 , out = result )
653+ getattr (dpnp , self . func )(ia , axis = 0 , out = result )
650654
651655 # output has incorrect shape -> Error
652656 result = dpnp .array (numpy .zeros ((4 , 2 )))
653657 with pytest .raises (ValueError ):
654- getattr (dpnp , func )(ia , axis = 0 , out = result )
658+ getattr (dpnp , self . func )(ia , axis = 0 , out = result )
655659
656660 @pytest .mark .usefixtures ("suppress_complex_warning" )
657- @pytest .mark .parametrize ("func" , ["max" , "min" ])
658661 @pytest .mark .parametrize ("arr_dt" , get_all_dtypes (no_none = True ))
659662 @pytest .mark .parametrize ("out_dt" , get_all_dtypes (no_none = True ))
660- def test_out_dtype (self , func , arr_dt , out_dt ):
663+ def test_out_dtype (self , arr_dt , out_dt ):
664+ # if out_dt is unsigned, input cannot be signed otherwise overflow occurs
661665 low = 0 if dpnp .issubdtype (out_dt , dpnp .unsignedinteger ) else - 10
662666 a = generate_random_numpy_array ((2 , 2 , 3 ), dtype = arr_dt , low = low )
663667 out = numpy .zeros_like (a , shape = (2 , 3 ), dtype = out_dt )
664668 ia , iout = dpnp .array (a ), dpnp .array (out )
665669
666- result = getattr (dpnp , func )(ia , out = iout , axis = 1 )
667- expected = getattr (numpy , func )(a , out = out , axis = 1 )
670+ result = getattr (dpnp , self . func )(ia , out = iout , axis = 1 )
671+ expected = getattr (numpy , self . func )(a , out = out , axis = 1 )
668672 assert_dtype_allclose (result , expected )
669673 assert result is iout
670674
671- @pytest .mark .parametrize ("func" , ["max" , "min" ])
672- def test_error (self , func ):
675+ def test_error (self ):
673676 ia = dpnp .arange (5 )
674677 # where is not supported
675678 with pytest .raises (NotImplementedError ):
676- getattr (dpnp , func )(ia , where = False )
679+ getattr (dpnp , self . func )(ia , where = False )
677680
678681 # initial is not supported
679682 with pytest .raises (NotImplementedError ):
680- getattr (dpnp , func )(ia , initial = 6 )
683+ getattr (dpnp , self . func )(ia , initial = 6 )
681684
682685
683686class TestMean :
0 commit comments