I’m writing a program that generates images, which I would like to bring into a Repa array. I’m currently using the type:
data Colour = Colour Double Double Double
to represent pixels, and I have a (probably inefficient but functional) function which converts a Colour into a DIM1 array:
colourToRepa :: Colour -> Array U DIM1 Double
colourToRepa (Colour r g b) = R.fromListUnboxed (Z :. (3::Int)) [r,g,b]
An image in my program at the moment is just a [Colour] value with a (Int, Int) representing dimensions.
I can use this to build a Array V DIM2 Colour easily enough, but is there a way (using colourToRepa or otherwise) to expand this array into a Array U DIM3 Double?
With lists I could just use map but Repa’s map preserves the shape of the array (I want to go from a DIM2 to a DIM3).
Remember that shapes are stored separately to data in repa, so you would be reshaping the array from DIM1 to DIM3, without changing the extent of the array.
We have a DIM1 (flat) array:
It’s extent is:
Using reshape we can ‘cast’ the shape of the array from 1D to 3D:
And its type changes: