1 Star 0 Fork 1

王布衣 / num

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
construct.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-23 13:40 . 优化非私有的repeat函数
package functions
import (
"gitee.com/quant1x/num/internal/constraints"
"gitee.com/quant1x/num/vectors"
)
type Number interface {
constraints.Float | constraints.Integer
}
func Zeros_Go[T constraints.Float](x []T, n int) {
Repeat_Go(x, 0, n)
}
func Ones_Go[T constraints.Float](x []T, n int) {
Repeat_Go(x, 1, n)
}
func Repeat_Go[T constraints.Float](x []T, a T, n int) {
vectors.Repeat(x, a, n)
}
func v1Repeat_Go[T constraints.Float](x []T, a T, n int) {
for i := 0; i < n; i++ {
x[i] = a
}
}
func Range_Go[T constraints.Float](x []T, a T, n int) {
for i := 0; i < n; i++ {
x[i] = a
a += 1
}
}
func Gather_Go[T constraints.Float](dst, x []T, idx []int) {
for i := 0; i < len(idx); i++ {
dst[i] = x[idx[i]]
}
}
func Scatter_Go[T constraints.Float](dst, x []T, idx []int) {
for i := 0; i < len(idx); i++ {
dst[idx[i]] = x[i]
}
}
func Clone_Go[T constraints.Float](x, y []T) {
copy(x, y)
}
func Clone_Go_Loop[T constraints.Float](x, y []T) {
for i := 0; i < len(x); i++ {
x[i] = y[i]
}
}
func FromNumber_Go[T constraints.Float, F Number](x []T, y []F) {
for i := 0; i < len(y); i++ {
x[i] = T(y[i])
}
}
func ToNumber_Go[T Number, F constraints.Float](x []T, y []F) {
for i := 0; i < len(y); i++ {
x[i] = T(y[i])
}
}
func FromBool_Go[T constraints.Float](x []T, y []bool) {
for i := 0; i < len(y); i++ {
if y[i] {
x[i] = 1
} else {
x[i] = 0
}
}
}
func ToBool_Go[F constraints.Float](x []bool, y []F) {
for i := 0; i < len(y); i++ {
if y[i] != 0 {
x[i] = true
} else {
x[i] = false
}
}
}
Go
1
https://gitee.com/quant1x/num.git
git@gitee.com:quant1x/num.git
quant1x
num
num
v0.2.9

搜索帮助

53164aa7 5694891 3bd8fe86 5694891