1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
align.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-03-24 10:53 . 修订IFF公式, 支持入参是常量
package stat
import "github.com/mymmsc/gox/exception"
// Align Data alignment
//
// a 通常是默认值
func Align[T BaseType](x []T, a T, dLen int) []T {
d := []T{}
xLen := len(x)
if xLen == dLen {
return x
} else if xLen > dLen {
// 截断
d = make([]T, dLen)
copy(d, x[0:dLen])
} else {
// 扩展内存
d = make([]T, dLen)
copy(d, x)
//avx2.RepeatAll(d[xLen:], a)
for i := xLen; i < dLen; i++ {
d[i] = a
}
}
return d
}
// Align2Series any转换成series
func Align2Series(x any, N int) Series {
ds := []DType{}
switch v := x.(type) {
//case int:
// ds = Repeat(DType(v), N)
//case []int:
// _N := Slice2DType(v)
// //nd := _N[len(_N) - 1]
// ds = Align[DType](_N, DTypeNaN, N)
//case []DType:
// ds = Align(v, DTypeNaN, N)
//case []T:
// vd := Slice2DType(v)
// ds = Align[DType](vd, DTypeNaN, N)
case nil:
ds = Repeat[DType](DTypeNaN, N)
case /*nil, */ int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, float32, float64, bool, string:
ds = Repeat[DType](Any2DType(v), N)
case []int8, []uint8, []int16, []uint16, []int32, []uint32, []int64, []uint64, []int, []uint, []uintptr, []float32, []float64, []bool, []string:
vd := Slice2DType(v)
ds = Align[DType](vd, DTypeNaN, N)
case Series:
vd := v.DTypes()
ds = Align[DType](vd, DTypeNaN, N)
default:
panic(exception.New(1, "error window"))
}
return NDArray[DType](ds)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.9.26

搜索帮助

344bd9b3 5694891 D2dac590 5694891