Changes between Version 21 and Version 22 of DataParallel/Regular
 Timestamp:
 Jan 19, 2010 12:33:05 PM (5 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

DataParallel/Regular
v21 v22 293 293 not be a two dimensional array anymore, since each row might potentially have a different length. 294 294 Therefore, we restrict the class of functions that can be mapped over subarrays to functions where 295 the shape of the argument determines the shape of the result. All `mappable` functions can be implemented296 such that they abstract over the exact dimensionality of their argument, and have the type295 the shape of the argument determines the shape of the result. All `mappable` (for the lack of a better term) 296 functions can be implemented such that they abstract over the exact dimensionality of their argument, and have the type 297 297 {{{ 298 298 f::(A.Shape dim, U.Elt e, U.Elt e') => … … 306 306 an even index: 307 307 {{{ 308 selectEven :: (A.Shape dim, U.Elt e) => DArray (dim :*: Int) e > DArray (dim :*: Int) e309 selectEven (DArray (sh :*: n ) f =308 selectEvenInd:: (A.Shape dim, U.Elt e) => DArray (dim :*: Int) e > DArray (dim :*: Int) e 309 selectEvenInd (DArray (sh :*: n ) f = 310 310 DArray (sh :*: n `div` 2) (\(sh :*: n) > f (sh :*: 2*n) 311 }}} 312 In this case `dim` could simply be unit, if and `selectEven` extracts all elements with an even index, or it could 313 be any other shape, and thus 314 {{{ 315 map selectEvenInd = selectEvenInd 316 }}} 317 where `selectEvenInd` on the left and righthand side of the equation are two different instances of the function. Now, lets 318 try and write function `selectEvenElems`, which selects all even elements from an array. To determine the shape of the 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 onedimensional 321 array, the result is a singular array, which then can be converted to a scalar using `toScalar`. The necessary application of `toScalar`, 322 however, also restricts `sh`, which can now only be unit, and therefore the whole operation `selectEvenElems` is restricted to onedimensional 323 arrays, and not mappable. 324 {{{ 325 selectEvenElems (DArray (sh :*: n) f) = DArray (sh :*: newSize) <......> 326 where 327 newSize = toScalar $ fold (+) 0 $ map (\x > if (even x) then 1 else 0) arr  (1) 311 328 }}} 312 329