1 Star 4 Fork 12

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ndarray_type.go 3.51 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-02-17 00:27 . !64#I6CC23实现KDJ指标
package stat
import (
"reflect"
"strings"
)
// Type is a convenience alias that can be used for a more type safe way of
// reason and use Series types.
type Type = reflect.Kind
// Supported Series Types
const (
SERIES_TYPE_INVAILD = reflect.Invalid // 无效类型
SERIES_TYPE_BOOL = reflect.Bool // 布尔类型
SERIES_TYPE_INT32 = reflect.Int32 // int64
SERIES_TYPE_INT64 = reflect.Int64 // int64
SERIES_TYPE_FLOAT32 = reflect.Float32 // float32
SERIES_TYPE_FLOAT64 = reflect.Float64 // float64
SERIES_TYPE_DTYPE = SERIES_TYPE_FLOAT64
SERIES_TYPE_STRING = reflect.String // string
)
var (
sKindInvalid = "invalid"
sKindBool = "bool"
sKindInt = "int"
sKindInt8 = "int8"
sKindInt16 = "int16"
sKindInt32 = "int32"
sKindInt64 = "int64"
sKindUint = "uint"
sKindUint8 = "uint8"
sKindUint16 = "uint16"
sKindUint32 = "uint32"
sKindUint64 = "uint64"
sKindUintptr = "uintptr"
sKindFloat32 = "float32"
sKindFloat64 = "float64"
sKindComplex64 = "complex64"
sKindComplex128 = "complex128"
sKindArray = "array"
sKindChan = "chan"
sKindFunc = "func"
sKindInterface = "interface"
sKindMap = "map"
sKindPointer = "ptr"
sKindSlice = "slice"
sKindString = "string"
sKindUnsafePointer = "unsafe.Pointer"
// 缓存Kind对应关系
mapKind = map[string]reflect.Kind{
sKindInvalid: reflect.Invalid,
sKindBool: reflect.Bool,
sKindInt: reflect.Int,
sKindInt8: reflect.Int8,
sKindInt16: reflect.Int16,
sKindInt32: reflect.Int32,
sKindInt64: reflect.Int64,
sKindUint: reflect.Uint,
sKindUint8: reflect.Uint8,
sKindUint16: reflect.Uint16,
sKindUint32: reflect.Uint32,
sKindUint64: reflect.Uint64,
sKindUintptr: reflect.Uintptr,
sKindFloat32: reflect.Float32,
sKindFloat64: reflect.Float64,
sKindComplex64: reflect.Complex64,
sKindComplex128: reflect.Complex128,
sKindArray: reflect.Array,
sKindChan: reflect.Chan,
sKindFunc: reflect.Func,
sKindInterface: reflect.Interface,
sKindMap: reflect.Map,
sKindPointer: reflect.Pointer,
sKindSlice: reflect.Slice,
sKindString: reflect.String,
sKindUnsafePointer: reflect.UnsafePointer,
}
)
// 初始化全局的私有变量
var (
rawBool bool = true
TypeBool = reflect.TypeOf([]bool{})
rawInt32 int32 = int32(0)
typeInt32 = reflect.TypeOf([]int32{})
rawInt64 int64 = int64(0)
TypeInt64 = reflect.TypeOf([]int64{})
rawFloat32 float32 = float32(0)
TypeFloat32 = reflect.TypeOf([]float32{})
rawFloat64 float64 = float64(0)
TypeFloat64 = reflect.TypeOf([]float64{})
TypeString = reflect.TypeOf([]string{})
)
// 从泛型检测出类型
func checkoutRawType(frame any) reflect.Kind {
ft := reflect.TypeOf(frame)
strType := ft.String()
pos := strings.LastIndexByte(strType, '[')
if pos < 0 {
return reflect.Invalid
}
strType = strType[pos+1:]
pos = strings.LastIndexByte(strType, ']')
if pos < 0 {
return reflect.Invalid
}
rawType := strings.TrimSpace(strType[:pos])
// 如果是0, 这个应该是个slice
if len(rawType) < 1 {
rawType = strings.TrimSpace(strType[pos+1:])
if len(rawType) < 1 {
return reflect.Invalid
}
}
if t, ok := mapKind[rawType]; ok {
return t
}
return reflect.Invalid
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.9.28

搜索帮助