diff --git a/algorithms/avx2/bool.go b/algorithms/avx2/bool.go deleted file mode 100644 index c603649889d73a43a9ef89e1617a6149ed420869..0000000000000000000000000000000000000000 --- a/algorithms/avx2/bool.go +++ /dev/null @@ -1,7 +0,0 @@ -package avx2 - -import "github.com/viterin/vek" - -func ToBool(x []float64) []bool { - return vek.ToBool(x) -} diff --git a/formula/if.go b/formula/if.go new file mode 100644 index 0000000000000000000000000000000000000000..df67e9233d0b05c0aa53a055de2e8cb24903e474 --- /dev/null +++ b/formula/if.go @@ -0,0 +1,25 @@ +package formula + +import ( + "gitee.com/quant1x/pandas" + "gitee.com/quant1x/pandas/stat" +) + +// IF 序列布尔判断 return=A if S==True else B +func IF(S, A, B pandas.Series) pandas.Series { + return IFF(S, A, B) +} + +// IFF 序列布尔判断 return=A if S==True else B +func IFF(S, A, B pandas.Series) pandas.Series { + s := S.Float() + a := A.Float() + b := B.Float() + ret := stat.Where(s, a, b) + return pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", ret) +} + +// IFN 序列布尔判断 return=A if S==False else B +func IFN(S, A, B pandas.Series) pandas.Series { + return IFF(S, B, A) +} diff --git a/formula/if_test.go b/formula/if_test.go new file mode 100644 index 0000000000000000000000000000000000000000..b45acf2d6763800628fffcd81cb1b9b918a40a04 --- /dev/null +++ b/formula/if_test.go @@ -0,0 +1,28 @@ +package formula + +import ( + "fmt" + "gitee.com/quant1x/pandas" + "testing" +) + +func TestIF(t *testing.T) { + S := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{1, 1, 1}) + A := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{11, 12, 13}) + B := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{21, 22, 23}) + fmt.Println(IF(S, A, B)) +} + +func TestIFF(t *testing.T) { + S := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{1, 1, 1}) + A := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{11, 12, 13}) + B := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{21, 22, 23}) + fmt.Println(IFF(S, A, B)) +} + +func TestIFN(t *testing.T) { + S := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{1, 0, 1}) + A := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{11, 12, 13}) + B := pandas.NewSeries(pandas.SERIES_TYPE_FLOAT32, "", []float32{21, 22, 23}) + fmt.Println(IFN(S, A, B)) +}