Re: [Haskell-cafe] Undocumented cost-centres (.\) using auto-all, and SCC pragma not being honored

2012-02-16 Thread Dan Maftei
On Wed, Feb 15, 2012 at 9:51 PM, Thomas Schilling
nomin...@googlemail.comwrote:

 On 15 February 2012 16:17, Dan Maftei ninestrayc...@gmail.com wrote:
 
  1 When profiling my code with -auto-all, my .prof file names some
 sub-expressions with a backslash. Cf. below. What are these?
 
   e_step
e_step.ewords
e_step.\
 e_step.\.\
  e_step.update_counts
e_step.fwords
 

 Yup, those are anonymous functions.


Thank you. I'm still curious why other (named) expressions don't show up.
I'm running the profiler again now and they DO. Odd...



 
  2. A related question: I tried using the SCC pragma instead of auto-all.
 I added it to all seven expressions inside the let, and to the nested
 folds. However, only two showed up in the .prof file! How come?

 It would be helpful if you pasted the code.  I think SCC pragmas
 around lambdas get ignored and you should put them inside.  (It may be
 the other way around, though.)


 God this is embarrassing... it's horrible code, I don't know monads yet
and EM makes more sense in an imperative paradigm, but I felt like pushing
the envelope and failed miserably lol. Anyways:

e_step ttable (fsentence, esentence) (counts, totals) =
  let
ewords = {-# SCC ewords -#} T.words esentence
fwords = {-# SCC fwords -#} T.words fsentence
-- calculate s-total(e) map

sTotal = {-# SCC sTotal -#} foldr (update_sTotal fwords) M.empty
ewords
update_sTotal fwords e sTotal = {-# SCC update_sTotal -#}
  foldr (\f sTotal -
  M.insertWith (+) e (getProb f e ttable) sTotal)
  sTotal fwords
-- helpers for updating counts

update_counts counts e f sTotal = {-# SCC update_counts -#}
  let !adding = (getProb f e ttable) / (sTotal M.! e)
  in M.insertWith (M.unionWith (+)) f (M.singleton e adding) counts
update_totals totals e f sTotal = {-# SCC update_totals -#}
  let !adding = (getProb f e ttable) / (sTotal M.! e)
  in M.insertWith' (+) f adding totals
  in {-# SCC folds -#}
   -- update counts by iterating over words

   foldr (\f (!counts, !totals) -
   foldr (\e (!counts, !totals) -
   let !newCounts = update_counts counts e f sTotal
   !newTotals = update_totals totals e f sTotal
   in (newCounts, newTotals))
   (counts, totals) ewords)
   (counts, totals) fwords
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Undocumented cost-centres (.\) using auto-all, and SCC pragma not being honored

2012-02-15 Thread Dan Maftei

 1 When profiling my code with -auto-all, my .prof file names some
sub-expressions with a backslash. Cf. below. What are these?

 e_step
  e_step.ewords
  e_step.\
   e_step.\.\
e_step.update_counts
  e_step.fwords

My e_step function binds seven expressions inside a let, then uses them in
two ugly nested folds. (Yes, very hackish)  As you can see, three such
expressions are named explicitly (ewords, fwords, and update_counts). But
where are the rest? Further, perhaps the backslashes have something to do
with the lambda expressions I am using in the two nested folds?

2. A related question: I tried using the SCC pragma instead of auto-all. I
added it to all seven expressions inside the let, and to the nested folds.
However, only two showed up in the .prof file! How come?

Thanks
ninestraycats
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Undocumented cost-centres (.\) using auto-all, and SCC pragma not being honored

2012-02-15 Thread Thomas Schilling
On 15 February 2012 16:17, Dan Maftei ninestrayc...@gmail.com wrote:

 1 When profiling my code with -auto-all, my .prof file names some 
 sub-expressions with a backslash. Cf. below. What are these?

      e_step
       e_step.ewords
       e_step.\
        e_step.\.\
         e_step.update_counts
       e_step.fwords

 My e_step function binds seven expressions inside a let, then uses them in 
 two ugly nested folds. (Yes, very hackish)  As you can see, three such 
 expressions are named explicitly (ewords, fwords, and update_counts). But 
 where are the rest? Further, perhaps the backslashes have something to do 
 with the lambda expressions I am using in the two nested folds?

Yup, those are anonymous functions.


 2. A related question: I tried using the SCC pragma instead of auto-all. I 
 added it to all seven expressions inside the let, and to the nested folds. 
 However, only two showed up in the .prof file! How come?

It would be helpful if you pasted the code.  I think SCC pragmas
around lambdas get ignored and you should put them inside.  (It may be
the other way around, though.)



 Thanks
 ninestraycats

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




--
Push the envelope. Watch it bend.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe