1

I have a list of 3D coordinates (x,y,z) that specify a scalar value (rho) at each location, which I have loaded into a repa array:

a :: Array D DIM1 (Int, Int, Int, Double)

i.e. each array element is a 4-tuple, representing (x,y,z,rho). Also, I'm not tied to using repa.

I would like to transform this into a DIM3 array, with each location containing the appropriate rho value (or a default value, or perhaps an interpolated value).

I can't think of a way to do this with traverse (at least not efficiently), because traverse uses indices from the new array, not the source array. Is it possible at all with repa, or do I need to use a different array library (even a mutable one)?

  • 1
    Why is it a 1D array in the first place? Where does the data come from? – Tobias Brandt Jul 01 '15 at 18:07
  • The data comes from a CSV file, with one (x,y,z,rho) tuple per line. (In theory it would come from an HDF5 file, but I couldn't find good enough Haskell support for HDF5; the record format would be the same in any case). I parse it with Data.Csv and Data.ByteString.Lex.Fractional into a Vector of Vectors, which is then loaded into a repa array. There is probably a better/faster way. – Edward Lilley Jul 01 '15 at 21:09
  • I realise that it might be better to store the table using a proper sparse array implementation. Is there a good Haskell sparse array library that supports parallelism, and can cope with ~millions of elements? – Edward Lilley Jul 01 '15 at 21:35
  • Did you manage to find a solution? – idontgetoutmuch Jul 05 '15 at 14:53
  • Not really. I decided that a) indexing into a 1D Vector would be better (which I tried & it basically worked, but is awkward because it all has to go through custom indexing and de-indexing functions); but also that b) I'm approaching this problem (i.e. manipulating a list of sparsely sampled points that represent Voronoi cells from the output of a fluid dynamics simulation) the wrong way, and should rethink the whole thing. Unfortunately, everyone else in this research group uses IDL, so I'm basically forced to go along with that. – Edward Lilley Jul 05 '15 at 18:32
  • Actually I did come up with an idiomatic repa solution, using fromFunction, but it was a bit slow and memory-hungry. – Edward Lilley Jul 05 '15 at 19:42

0 Answers0