r-lib / rray

Simple Arrays
https://rray.r-lib.org
GNU General Public License v3.0
129 stars 12 forks source link

Single precision floats #217

Open dselivanov opened 5 years ago

dselivanov commented 5 years ago

It would be useful to add single precision floats to the package. The idea is that we can use R's integer vectors (always 32 bit) to store float32 numbers (same done in https://github.com/wrathematics/float pkg).

I'm not that familiar with codebase for rray, so I'm curious on how much effort do you think it will take? My hypothesis is that it should not take too much - xtensor is templated library, so in theory most of the code for double could be reused.

DavisVaughan commented 5 years ago

I think the limitation might first happen with the xtensor-r bindings. I think xtensor should be able to handle it since it is templated, but xtensor-r checks that the input is one of a few special cased types before creating the xtensor object https://github.com/QuantStack/xtensor-r/blob/master/include/xtensor-r/rcontainer.hpp#L144

dselivanov commented 5 years ago

Well, int32_t should be fine. The issue is how to reinterpret int32_t* as float*. If we could check some attribute of R object in order to understand that it is actually float32..