[racket] (Math) Computing the mean is slow in Typed Racket

From: Neil Toronto (neil.toronto at gmail.com)
Date: Fri Feb 8 11:00:22 EST 2013

On 02/08/2013 03:19 AM, Laurent wrote:
>
> On Fri, Feb 8, 2013 at 10:56 AM, Jens Axel Søgaard
> <jensaxel at soegaard.net <mailto:jensaxel at soegaard.net>> wrote:
>
>     Try
>                 [xs  (if (list? xs) xs (sequence->list xs))])
>     and see what the new timings are.
>
>
> Perfect! I'm glad it was so simple.
>
> old mean:
> cpu time: 3621 real time: 3621 gc time: 2613
> 494936207/10000000
>
> new mean:
> cpu time: 564 real time: 563 gc time: 0
> 494936207/10000000
>
> my-mean:
> cpu time: 512 real time: 515 gc time: 132
> 494936207/10000000

Thanks for catching this!

> Had to explicitely cast xs to a list of reals:
> (cast (if (list? xs) xs (sequence->list xs))
>        (Listof Real))
>
> But shouldn't this patch be applied directly to sequence->list instead?

That's one option. Since lists are immutable, I can't think of why 
having `sequence->list' sometimes not make a copy would be bad.

It might also be a good idea to handle vectors specially.

Another option is to do something with Typed Racket to get rid of this 
type error, which makes the cast necessary:

   Type Checker: Expected (Listof Real), but got
   (U (Listof Real) (Pairof Any (Listof Any)))

I don't know why it does this, but there might be a good reason. Vincent?

Neil ⊥


Posted on the users mailing list.