Changes between Version 22 and Version 23 of DataParallel/Regular
 Timestamp:
 Jan 19, 2010 12:36:57 PM (8 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

DataParallel/Regular
v22 v23 318 318 try and write function `selectEvenElems`, which selects all even elements from an array. To determine the shape of the 319 319 result, it is not sufficient to look at the shape of the argument. Instead, we have to calculate the new size by counting the 320 even elements in the array (1)using `fold`. The function `fold` is mappable, and returns an array. If the argument is a onedimensional320 even elements in the array using `fold`. The function `fold` is mappable, and returns an array. If the argument is a onedimensional 321 321 array, the result is a singular array, which then can be converted to a scalar using `toScalar`. The necessary application of `toScalar`, 322 322 however, also restricts `sh`, which can now only be unit, and therefore the whole operation `selectEvenElems` is restricted to onedimensional … … 325 325 selectEvenElems (DArray (sh :*: n) f) = DArray (sh :*: newSize) <......> 326 326 where 327 newSize = toScalar $ fold (+) 0 $ map (\x > if (even x) then 1 else 0) arr  (1)327 newSize = toScalar $ fold (+) 0 $ map (\x > if (even x) then 1 else 0) arr 328 328 }}} 329 329