From 9d856e6f9f065b1dacb6ae8ce8039118b168321f Mon Sep 17 00:00:00 2001 From: wangfeng Date: Fri, 3 Feb 2023 11:53:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BA=9F=E5=BC=83=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stat/where.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/stat/where.go b/stat/where.go index 929cd3e..a7d5253 100644 --- a/stat/where.go +++ b/stat/where.go @@ -2,7 +2,6 @@ package stat import ( "gitee.com/quant1x/pandas/algorithms/avx2" - "math" ) //func Where[T int64 | float64](condition any, params ...any) []T { @@ -18,39 +17,6 @@ import ( // params只支持两个默认值x和y, 如果condition为true返回x, 否则返回y // condition和param都可能是基础数据类型,也可能是一个slice, 并且长度可能不一致 // 直接写成序列版本, 可能更简单 -// func Where[T int64 | float64](condition []T, x, y []T) []T { -func Where1(condition []float64, x, y []float64) []float64 { - // 第一步, 找出最长的 - clen := len(condition) - xlen := len(x) - ylen := len(y) - // 第二步, 找出最大长度 - c := []float64{float64(clen), float64(xlen), float64(ylen)} - maxLength := int(avx2.Max(c)) - - // 对齐所有长度 - if clen < maxLength { - condition = align(condition, math.NaN(), maxLength) - } - if xlen < maxLength { - x = align(x, math.NaN(), maxLength) - } - if ylen < maxLength { - y = align(y, math.NaN(), maxLength) - } - // 初始化返回值 - d := make([]float64, maxLength) - for i := 0; i < maxLength; i++ { - // NaN也被认为是真 - if condition[i] != 0 { - d[i] = x[i] - } else { - d[i] = y[i] - } - } - return d -} - func Where[T StatType](condition []T, x, y []T) []T { // 第一步, 找出最长的 clen := len(condition) -- Gitee