MCPcopy
hub / github.com/dgraph-io/dgraph / BytesAsFloatArray

Function BytesAsFloatArray

types/value.go:21–32  ·  view source on GitHub ↗

BytesAsFloatArray(encoded) converts encoded into a []float32. If len(encoded) % 4 is not 0, it will ignore any trailing bytes, and simply convert 4 bytes at a time to generate the float64 entries. Current implementation assuming littleEndian encoding

(encoded []byte)

Source from the content-addressed store, hash-verified

19// float64 entries.
20// Current implementation assuming littleEndian encoding
21func BytesAsFloatArray(encoded []byte) []float32 {
22 resultLen := len(encoded) / 4
23 if resultLen == 0 {
24 return []float32{}
25 }
26 retVal := make([]float32, resultLen)
27 for i := range resultLen {
28 retVal[i] = *(*float32)(unsafe.Pointer(&encoded[0]))
29 encoded = encoded[4:]
30 }
31 return retVal
32}
33
34// FloatArrayAsBytes(v) will create a byte array encoding
35// v using LittleEndian format. This is sort of the inverse

Callers 5

TypeValFromFunction · 0.92
toListMethod · 0.92
addIndexMutationsMethod · 0.92
ConvertFunction · 0.70

Calls

no outgoing calls

Tested by 1