You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewFormatException("Data length of binary vector of type Float32 must be a multiple of 4 bytes.");
47
49
}
48
50
49
-
if(typeof(TItem)!=typeof(float))
50
-
{
51
-
thrownewNotSupportedException($"Expected float for Float32 vector type, but found {typeof(TItem)}.");
52
-
}
53
-
54
-
intcount=vectorDataBytes.Length/4;// 4 bytes per float
55
-
float[]floatArray=newfloat[count];
56
-
57
-
for(inti=0;i<count;i++)
58
-
{
59
-
// Each float32 is 4 bytes. So to extract the i-th float, we slice 4 bytes from offset i * 4. Use little-endian or big-endian decoding based on platform.
60
-
floatArray[i]=BitConverter.IsLittleEndian
61
-
?MemoryMarshal.Read<float>(vectorDataBytes.Span.Slice(i*4,4))// fast, unaligned read on little endian
62
-
:BinaryPrimitives.ReadSingleBigEndian(vectorDataBytes.Span.Slice(i*4,4));// correctly reassemble 4 bytes as big-endian float
63
-
}
64
-
51
+
varfloatArray=BitConverter.IsLittleEndian// We need not to use this condition here, just doing to keep the little endian logic intact
0 commit comments