From 39257912c0c7011bc0792f382a594a9a059973d5 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 13 Feb 2023 11:13:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=89=A9=E5=85=85=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stat/arithmetics_sub.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stat/arithmetics_sub.go b/stat/arithmetics_sub.go index c67aac5..237f5c1 100644 --- a/stat/arithmetics_sub.go +++ b/stat/arithmetics_sub.go @@ -7,11 +7,11 @@ import ( ) // Sub arithmetics 减法 -func Sub[T StatType](x []T, y any) []T { - return binaryOperations(x, y, vek32.Sub, vek.Sub, __sub[T]) +func Sub[T Number](x []T, y any) []T { + return binaryOperations(x, y, vek32.Sub, vek.Sub, __sub_go[T]) } -func __sub[T StatType](x, y []T) []T { +func __sub_go[T Number](x, y []T) []T { x = slices.Clone(x) for i := 0; i < len(x); i++ { x[i] -= y[i] -- Gitee From 354766f85f3f7eb7c0ed8d3b0dd59edf5eb8c997 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 13 Feb 2023 11:14:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?#I6EMN2=20=E5=AE=9E=E7=8E=B0add=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stat/arithmetics_add.go | 20 ++++++++++++++++++++ stat/arithmetics_add_test.go | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 stat/arithmetics_add.go create mode 100644 stat/arithmetics_add_test.go diff --git a/stat/arithmetics_add.go b/stat/arithmetics_add.go new file mode 100644 index 0000000..2ff2504 --- /dev/null +++ b/stat/arithmetics_add.go @@ -0,0 +1,20 @@ +package stat + +import ( + "github.com/viterin/vek" + "github.com/viterin/vek/vek32" + "golang.org/x/exp/slices" +) + +// Add arithmetics 加法 +func Add[T Number](x []T, y any) []T { + return binaryOperations(x, y, vek32.Add, vek.Add, __add_go[T]) +} + +func __add_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_add_test.go b/stat/arithmetics_add_test.go new file mode 100644 index 0000000..640125f --- /dev/null +++ b/stat/arithmetics_add_test.go @@ -0,0 +1,18 @@ +package stat + +import ( + "fmt" + "testing" +) + +func TestAdd(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(Add(f1, f2)) + fmt.Println(Add(d2, float64(1))) + fmt.Println(Add(d3, int32(2))) + fmt.Println(Add(d4, int64(3))) +} -- Gitee