GithubHelp home page GithubHelp logo

Handling of float arrays about ocaml-rs HOT 9 CLOSED

zshipko avatar zshipko commented on June 1, 2024
Handling of float arrays

from ocaml-rs.

Comments (9)

LaurentMazare avatar LaurentMazare commented on June 1, 2024 1

Ah thanks, not sure how I managed to miss this one but that looks like exactly what I would want :)

from ocaml-rs.

zshipko avatar zshipko commented on June 1, 2024 1

Just opened a PR: #89

from ocaml-rs.

zshipko avatar zshipko commented on June 1, 2024

I'm not opposed to adding a C file to ocaml-sys, I was trying to avoid it for a while but it's probably a better idea than rewriting the macros as Rust macros. This instance is a also little more complicated than the others since it depends on FLAT_FLOAT_ARRAY.

I made a branch with your proposed additions: https://github.com/zshipko/ocaml-rs/tree/float-array

This branch defines ocaml_sys::FLAT_FLOAT_ARRAY and adds sys/src/ocaml-sys.c which contains wrappers for Double_val, Store_double_val, Double_field and Store_double_field (see https://github.com/zshipko/ocaml-rs/blob/float-array/sys/src/mlvalues.rs#L143)

Does that work for you? Or did you have something else in mind?

from ocaml-rs.

LaurentMazare avatar LaurentMazare commented on June 1, 2024

That looks great and I think would fit my use case.
One thing I find a bit surprising is that there doesn't seem to be any function in mlvalues.h that would allocate a float array from the C side using the appropriate representation (i.e. with a Double_array_tag if FLAT_FLOAT_ARRAY is set and a 0 tag otherwise) but it feels that it's easy to do this on the Rust side using the newly added ocaml_sys::FLAT_FLOAT_ARRAY constant. Maybe it would be worth having some helper function for this?

from ocaml-rs.

zshipko avatar zshipko commented on June 1, 2024

It looks like there is CAMLextern value caml_alloc_float_array (mlsize_t len); in alloc.h, I will add that as well.

from ocaml-rs.

LaurentMazare avatar LaurentMazare commented on June 1, 2024

Thanks, I only plan on using the ocaml-sys bit that your PR is introducing, but maybe at some point you also want to use this in the ocaml-rs part when converting a Vec<f64> to an OCaml float array. It seems that currently this would result in an array of boxed floats and somehow the OCaml runtime manages to use it but I ran into some issues while doing the same thing with the new flambda backend.

from ocaml-rs.

zshipko avatar zshipko commented on June 1, 2024

Thanks, I will take a look at that before I merge this!

from ocaml-rs.

zshipko avatar zshipko commented on June 1, 2024

FYI, I just released ocamlsys` 0.23 with these changes

from ocaml-rs.

LaurentMazare avatar LaurentMazare commented on June 1, 2024

Great, thanks!

from ocaml-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.