代码拉取完成,页面将自动刷新
package stat
// Diff 元素的第一个离散差
//
// First discrete difference of element.
// Calculates the difference of a {klass} element compared with another
// element in the {klass} (default is element in previous row).
func Diff[T Number](s []T, param any) []T {
blocks := Rolling[T](s, param)
var d []T
var front = typeDefault[T]()
for _, block := range blocks {
vs := block
vl := len(block)
if vl == 0 {
d = append(d, typeDefault[T]())
continue
}
vf := vs[0]
vc := vs[vl-1]
if DTypeIsNaN(Any2DType(vc)) || DTypeIsNaN(Any2DType(front)) {
front = vf
d = append(d, typeDefault[T]())
continue
}
diff := vc - front
d = append(d, diff)
front = vf
}
return d
}
func Diff2[T BaseType](s []T, param any) []T {
var d any
switch vs := any(s).(type) {
case []float32:
d = Diff(vs, param)
case []float64:
d = Diff(vs, param)
case []int:
d = Diff(vs, param)
case []int8:
d = Diff(vs, param)
case []int16:
d = Diff(vs, param)
case []int32:
d = Diff(vs, param)
case []int64:
d = Diff(vs, param)
//case []uint, []uint8, []uint16, []uint32, []uint64, []uintptr:
// d = xv
default:
// 其它类型原样返回
panic(Throw(any(s)))
}
return d.([]T)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。