Encoding/decoding arrays of floats with Bytes

Encoding/decoding arrays of floats

Hello! I am exploring the use of Futhark to do computationally intensive tasks on behalf of an Elm client. The kind of computation involves 2D arrays of float32’s. Call such an array a. Then a typical computation has the form a -> f(a). Futhark is a typed functional language that compiles code for the GPU. It can compute f(a) very quickly.

I’ve rigged up a Python server which hosts the Futhark code and maintains the array a as part of its state. When the server receives a GET request, it sends a string representation of a (bad) and then updates a using f. See this GitHub repo for code and a detailed README.

What is needed next is a fast way to send arrays of f32’s back and forth between Elm and Python. Once this is done, the client can give a visual display of the array. See this Example for a pure Elm version (press the ‘Step’ or ‘Ready’ buttons to advance the state).

The kind of computation is always at least O(N^2), where the array is NxN, so one reaches the limits of what Elm/Javascript can do pretty quickly. Futhark’s performance is amazing.

To summarize: what is needed for this project to proceed is a way to send arrays of float32s back and forth between Elm and Python.

I am not a big fan of promoting my own library, but this could be an interesting case for using protocol buffers. For basic objects the library does not come near the speed of JSON, but for huge arrays it can make the difference (unfortunately my benchmarking is still a work-in-progress).
You’ll just need to define a .proto file and generate both Elm and Python code from it. Let me know if you need any help or further explanation.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.