Kirika/vector/shared.go
DataHoarder 514a88aec1
Some checks failed
continuous-integration/drone/push Build is failing
Update to Go 1.20
2023-04-09 13:10:30 +02:00

23 lines
609 B
Go

package vector
import (
"golang.org/x/exp/slices"
"runtime"
"unsafe"
)
func Int8ToBytes(data []int8) (buf []byte) {
defer runtime.KeepAlive(data)
return slices.Clone(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(data))), len(data)))
}
func Int16ToBytes(data []int16) (buf []byte) {
defer runtime.KeepAlive(data)
return slices.Clone(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(data))), len(data)*2))
}
func Float32ToBytes(data []float32) (buf []byte) {
defer runtime.KeepAlive(data)
return slices.Clone(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(data))), len(data)*4))
}