From 5b8859ed162999260d76a652253f9e8df3c921e5 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 13 Feb 2023 11:20:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?#I6EMN5=20=E5=AE=9E=E7=8E=B0=E4=B9=98?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stat/arithmetics_mul.go | 20 ++++++++++++++++++++ stat/arithmetics_mul_test.go | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 stat/arithmetics_mul.go create mode 100644 stat/arithmetics_mul_test.go diff --git a/stat/arithmetics_mul.go b/stat/arithmetics_mul.go new file mode 100644 index 0000000..509cce1 --- /dev/null +++ b/stat/arithmetics_mul.go @@ -0,0 +1,20 @@ +package stat + +import ( + "github.com/viterin/vek" + "github.com/viterin/vek/vek32" + "golang.org/x/exp/slices" +) + +// Mul arithmetics 乘法 +func Mul[T Number](x []T, y any) []T { + return binaryOperations(x, y, vek32.Mul, vek.Mul, __mul_go[T]) +} + +func __mul_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_mul_test.go b/stat/arithmetics_mul_test.go new file mode 100644 index 0000000..992b716 --- /dev/null +++ b/stat/arithmetics_mul_test.go @@ -0,0 +1,18 @@ +package stat + +import ( + "fmt" + "testing" +) + +func TestMul(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(Mul(f1, f2)) + fmt.Println(Mul(d2, float64(1))) + fmt.Println(Mul(d3, int32(2))) + fmt.Println(Mul(d4, int64(3))) +} -- Gitee From 27507826330d75721579c79e2ed7d9b72ef3bfbe Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 13 Feb 2023 11:21:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?#I6EMN5=20=E5=AE=9E=E7=8E=B0=E4=B9=98?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stat/arithmetics_mul_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/stat/arithmetics_mul_test.go b/stat/arithmetics_mul_test.go index 992b716..d383696 100644 --- a/stat/arithmetics_mul_test.go +++ b/stat/arithmetics_mul_test.go @@ -15,4 +15,5 @@ func TestMul(t *testing.T) { fmt.Println(Mul(d2, float64(1))) fmt.Println(Mul(d3, int32(2))) fmt.Println(Mul(d4, int64(3))) + fmt.Println(Mul(d4, int64(3))) } -- Gitee