Skip to content

Commit

Permalink
Convert Vec<f32> to flat ocaml float arrays
Browse files Browse the repository at this point in the history
This fixes a bug where `Vec<f32>`s create in rust would be converted to
arrays of boxed floats in ocaml.
  • Loading branch information
gridbugs authored and zshipko committed Mar 29, 2024
1 parent ce61049 commit 64f9bab
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ unsafe impl<V: 'static + ToValue> ToValue for Vec<V> {
fn to_value(&self, rt: &Runtime) -> Value {
let len = self.len();

if core::any::TypeId::of::<f64>() == core::any::TypeId::of::<V>() && sys::FLAT_FLOAT_ARRAY {
if (core::any::TypeId::of::<f32>() == core::any::TypeId::of::<V>()
|| core::any::TypeId::of::<f64>() == core::any::TypeId::of::<V>())
&& sys::FLAT_FLOAT_ARRAY
{
let mut arr = unsafe { Value::alloc_double_array(len) };
for (i, v) in self.iter().enumerate() {
unsafe {
Expand Down

0 comments on commit 64f9bab

Please sign in to comment.