Changes between Version 21 and Version 22 of DataParallel/Regular


Ignore:
Timestamp:
Jan 19, 2010 12:33:05 PM (5 years ago)
Author:
gckeller
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DataParallel/Regular

    v21 v22  
    293293not be a two dimensional array anymore, since each row might potentially have a different length.  
    294294Therefore, we restrict the class of functions that can be mapped over sub-arrays to functions where  
    295 the shape of the argument determines the shape of the result. All `mappable` functions can be implemented 
    296 such that they abstract over the exact dimensionality of their argument, and have the type 
     295the shape of the argument determines the shape of the result. All `mappable` (for the lack of a better term)  
     296functions can be implemented such that they abstract over the exact dimensionality of their argument, and have the type 
    297297{{{ 
    298298f::(A.Shape dim, U.Elt e, U.Elt e') =>  
     
    306306an even index: 
    307307{{{ 
    308   selectEven:: (A.Shape dim, U.Elt e) => DArray (dim :*: Int) e -> DArray (dim :*: Int) e  
    309   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 = 
    310310     DArray (sh :*: n `div` 2) (\(sh :*: n) -> f (sh :*: 2*n) 
     311}}} 
     312In this case `dim` could simply be unit, if and `selectEven` extracts all elements with an even index, or it could 
     313be any other shape, and thus 
     314{{{ 
     315  map selectEvenInd = selectEvenInd 
     316}}} 
     317where `selectEvenInd` on the left and right-hand side of the equation are two different instances of the function. Now, lets 
     318try and write function `selectEvenElems`, which selects all even elements from an array.  To determine the shape of the 
     319result, it is not sufficient to look  at the shape of the argument. Instead, we have to calculate the new size by counting the 
     320even elements in the array (1) using `fold`. The function `fold` is mappable, and returns an array. If the argument is a one-dimensional 
     321array, the result is a singular array, which then can be converted to a scalar using `toScalar`.  The necessary application of `toScalar`, 
     322however, also restricts `sh`, which can now only be unit, and therefore the whole operation `selectEvenElems` is restricted to one-dimensional 
     323arrays, 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) 
    311328}}} 
    312329