As part of a larger problem, I am trying to define an array inside an array as follows:
import Data.Array.Repa type Arr = Array DIM2 Int arr = force $ fromList (Z :. 5 :. 5) [1..25] :: Arr combined :: Arr combined = arr `deepSeqArray` traverse arr (\_ -> Z :. 4 :. 4 :: DIM2) (\f (Z :. x :. y) -> let reg = force $ extract f (x,y) (2,2) in reg `deepSeqArray` sumAll reg) extract :: (DIM2 -> Int) -> (Int,Int) -> (Int,Int) -> Arr extract lookup (x0,y0) (width,height) = fromFunction bounds $ \sh -> offset lookup sh where bounds = Z :. width :. height offset :: (DIM2 -> Int) -> DIM2 -> Int offset f (Z :. x :. y) = f (Z :. x + x0 :. y + y0) main = print combined
The extract function uses fromFunction and the search function provided to it, but it can also use traverse and arr ! ... arr ! ... for the same effect. Despite using force and deepSeqArray everywhere as early as possible, the console is populated with a message here, followed by the correct result:
Data.Array.Repa: Performing nested parallel computing sequentially. You probably called the function "force" while another instance was already running. This can happen if the second version has been suspended due to lazy pricing. Use 'deepSeqArray' to ensure that each array will be fully evaluated before you click on 'next'.
Until I created a version with lists for comparing speeds, performance suffers in greater productivity.
Is this just a consequence of the definition of nested arrays, and therefore, should I restructure my program for an internal or external definition, which should be a list? Is my extract function terrible and cause problems?
The tips from this question were useful to achieve this, but I have not yet scanned the compiled code.
source share