From 3f2db725f9327976a54a1d27192ec2b9b315b7bc Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 13 Feb 2023 11:29:28 +0800 Subject: [PATCH] =?UTF-8?q?#I6EMN8=20=E5=AE=9E=E7=8E=B0=E9=99=A4=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stat/arithmetics_div.go | 20 ++++++++++++++++++++ stat/arithmetics_div_test.go | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 stat/arithmetics_div.go create mode 100644 stat/arithmetics_div_test.go diff --git a/stat/arithmetics_div.go b/stat/arithmetics_div.go new file mode 100644 index 0000000..c888304 --- /dev/null +++ b/stat/arithmetics_div.go @@ -0,0 +1,20 @@ +package stat + +import ( + "github.com/viterin/vek" + "github.com/viterin/vek/vek32" + "golang.org/x/exp/slices" +) + +// Div arithmetics 除法 +func Div[T Number](x []T, y any) []T { + return binaryOperations(x, y, vek32.Div, vek.Div, __div_go[T]) +} + +func __div_go[T Number](x, y []T) []T { + x = slices.Clone(x) + for i := 0; i < len(x); i++ { + x[i] /= y[i] + } + return x +} diff --git a/stat/arithmetics_div_test.go b/stat/arithmetics_div_test.go new file mode 100644 index 0000000..bd50109 --- /dev/null +++ b/stat/arithmetics_div_test.go @@ -0,0 +1,19 @@ +package stat + +import ( + "fmt" + "testing" +) + +func TestDiv(t *testing.T) { + f1 := []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + f2 := []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + d2 := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + d3 := []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + d4 := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + fmt.Println(Div(f1, f2)) + fmt.Println(Div(d2, float64(1))) + fmt.Println(Div(d3, int32(2))) + fmt.Println(Div(d4, int64(3))) + fmt.Println(Div(d4, int64(3))) +} -- Gitee