Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the source code for <code>now</code>:</p> <pre><code>now arr = do arr `deepSeqArray` return () return arr </code></pre> <p>So it's really just a monadic version of <code>deepSeqArray</code>. You can use either of these to force evaluation, rather than hanging on to a thunk. This "evalulation" is different than the "computation" forced when <code>computeP</code> is called. </p> <p>In your code, <code>now</code> doesn't apply, since you're not in a monad. But in this context <code>deepSeqArray</code> wouldn't help either. Consider this situation:</p> <pre><code>x :: Array U Int Double x = ... y :: Array U Int Double y = computeUnboxedP $ map f x </code></pre> <p>Since <code>y</code> refers to <code>x</code>, we'd like to be sure <code>x</code> is computed before starting to compute <code>y</code>. If not, the available work won't be distributed correctly among the gang of threads. To get this to work out, it's better to write <code>y</code> as</p> <pre><code>y = deepSeqArray x . computeUnboxedP $ map f x </code></pre> <p>Now, for a delayed array, we have</p> <pre><code>deepSeqArray (ADelayed sh f) y = sh `deepSeq` f `seq` y </code></pre> <p>Rather than computing all the elements, this just makes sure the shape is computed, and reduces <code>f</code> to weak-head normal form.</p> <p>As for manifest vs delayed arrays, there are certainly time delayed arrays are preferable. </p> <pre><code>multiplyMM arr brr = [arr, brr] `deepSeqArrays` A.sumP (A.zipWith (*) arrRepl brrRepl) where trr = computeUnboxedP $ transpose2D brr arrRepl = trr `deepSeqArray` A.extend (Z :. All :. colsB :. All) arr brrRepl = trr `deepSeqArray` A.extend (Z :. rowsA :. All :. All) trr (Z :. _ :. rowsA) = extent arr (Z :. colsB :. _ ) = extent brr </code></pre> <p>Here "extend" generates a new array by copying the values across some set of new dimensions. In particular, this means that</p> <pre><code>arrRepl ! (Z :. i :. j :. k) == arrRepl ! (Z :. i :. j' :. k) </code></pre> <p>Thankfully, <code>extend</code> produces a delayed array, since it would be a waste to go through the trouble of all this copying.</p> <p>Delayed arrays also allow the possiblity of fusion, which is impossible if the array is manifest.</p> <p>Finally, <code>computeUnboxedP</code> is just <code>computeP</code> with a specialized type. Giving <code>computeUnboxedP</code> explicitly might allow GHC to optimize better, and makes the code a little clearer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload