gitee.com/quant1x/num@v0.3.2/internal/functions/min_test.go (about)

     1  package functions
     2  
     3  import (
     4  	"gitee.com/quant1x/num/internal/rand"
     5  	"gitee.com/quant1x/pkg/testify/require"
     6  	"slices"
     7  	"testing"
     8  )
     9  
    10  func TestMin(t *testing.T) {
    11  	rand.Seed(2)
    12  	for i := 0; i < 1000; i++ {
    13  		size := 1 + (i / 5)
    14  		{
    15  			x := Random[float64](size)
    16  			r1 := Min_AVX2_F64(x)
    17  			r2 := Min_Go(x)
    18  			require.InDelta(t, r1, r2, 0.001)
    19  		}
    20  		{
    21  			x := Random[float32](size)
    22  			r1 := Min_AVX2_F32(x)
    23  			r2 := Min_Go(x)
    24  			require.InDelta(t, r1, r2, 0.001)
    25  		}
    26  		{
    27  			x := Random[float64](size)
    28  			r1 := ArgMin_AVX2_F64(x)
    29  			r2 := ArgMin_Go(x)
    30  			require.Equal(t, r1, r2)
    31  		}
    32  		{
    33  			x := Random[float32](size)
    34  			r1 := ArgMin_AVX2_F32(x)
    35  			r2 := ArgMin_Go(x)
    36  			require.Equal(t, r1, r2)
    37  		}
    38  	}
    39  }
    40  
    41  func TestMinimum(t *testing.T) {
    42  	rand.Seed(2)
    43  	for i := 0; i < 1000; i++ {
    44  		size := 1 + (i / 5)
    45  		{
    46  			x := Random[float64](size)
    47  			y := Random[float64](size)
    48  			x1 := slices.Clone(x)
    49  			Minimum_AVX2_F64(x, y)
    50  			Minimum_Go(x1, y)
    51  			require.InEpsilonSlice(t, x, x1, 0.001)
    52  		}
    53  		{
    54  			x := Random[float32](size)
    55  			y := Random[float32](size)
    56  			x1 := slices.Clone(x)
    57  			Minimum_AVX2_F32(x, y)
    58  			Minimum_Go(x1, y)
    59  			require.InDeltaSlice(t, x, x1, 0.001)
    60  		}
    61  		{
    62  			x := Random[float64](size)
    63  			a := rand.Float64()
    64  			x1 := slices.Clone(x)
    65  			MinimumNumber_AVX2_F64(x, a)
    66  			MinimumNumber_Go(x1, a)
    67  			require.InEpsilonSlice(t, x, x1, 0.001)
    68  		}
    69  		{
    70  			x := Random[float32](size)
    71  			a := rand.Float32()
    72  			x1 := slices.Clone(x)
    73  			MinimumNumber_AVX2_F32(x, a)
    74  			MinimumNumber_Go(x1, a)
    75  			require.InEpsilonSlice(t, x, x1, 0.001)
    76  		}
    77  	}
    78  }