Improve copying bytes into aligned memory area

This commit is contained in:
Clément Renault 2024-12-02 10:15:58 +01:00
parent 5df5eb2db2
commit f7f9a131e4
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -226,11 +226,10 @@ impl ArroySetVectors {
frame: &FrameGrantR<'_>,
vec: &'v mut Vec<f32>,
) -> &'v [f32] {
vec.clear();
Self::embeddings_bytes(frame).chunks_exact(mem::size_of::<f32>()).for_each(|bytes| {
let f = bytes.try_into().map(f32::from_ne_bytes).unwrap();
vec.push(f);
});
let embeddings_bytes = Self::embeddings_bytes(frame);
let embeddings_count = embeddings_bytes.len() / mem::size_of::<f32>();
vec.resize(embeddings_count, 0.0);
bytemuck::cast_slice_mut(vec.as_mut()).copy_from_slice(embeddings_bytes);
&vec[..]
}
}