[Jprogramming] Performance of exact keyed aggregate
Roger Hui
rhui000 at shaw.ca
Sat Sep 29 03:05:18 HKT 2007
Since it's not really important in the scheme of things
and since the slow expression is curious (i.e. odd i.e. strange),
I am not inclined to spend the time to investigate.
Do you understand what x:@+/ does? In x+y if
one argument is float the other argument is converted
to float if necessary before the addition. Therefore,
on floating point a,b,c,d
x:@+/ a,b,c,d
a x:@+ b x:@+ c x:@+ d
x: a + fx x: b + fx x: c + d
where fx is x:^:_1, converting extended precision
to float. That is, the x: gets you nothing. That you
got the right answer using x:@+/ means one of
the following:
a. coincidence; or
b. extended precision is not needed, whence
+/ works just as well; or
c. n is created to be extended precision, whence
+/ works just as well.
----- Original Message -----
From: "mike_liz.day at tiscali.co.uk" <mike_liz.day at tiscali.co.uk>
Date: Friday, September 28, 2007 11:46
Subject: Re: [Jprogramming] Performance of exact keyed aggregate
To: programming at jsoftware.com, programming at jsoftware.com
>
> Thanks ...
>
> Well, I did get the right result using
> (v (</.) i)(x:@+/@:{)every <n
> while i had to kill
> v (x:@+//.) n
> so I'd still like thoughts on why the
> latter indexed version performs
> much better than the former. Raul
> seems to agree that it should work...
>
> I'm not on a J machine right now, so
> can't test the variant phrases.
>
> Thanks, Mike
>
> Original Message:
> -----------------
> From: Roger Hui rhui000 at shaw.ca
> Date: Fri, 28 Sep 2007 10:56:37 -0700
> To: programming at jsoftware.com
> Subject: Re: [Jprogramming] Performance of exact keyed aggregate
>
>
> If you need exact integer results the expression should be
> v +//. x: n (or just v +//. n with n created to be
> extended precision).
> v x:@+//. n is a curious phrase and does not achieve the
> intent
> expressed in your msg.
>
>
>
> ----- Original Message -----
> From: Mike Day <mike_liz.day at tiscali.co.uk>
> Date: Friday, September 28, 2007 3:07
> Subject: [Jprogramming] Performance of exact keyed aggregate
> To: Programming forum <programming at jsoftware.com>
>
> > Given values v, counts n:
> > v,:n
> > 1 2 1 2 1 2 1
> 2 1
> > 20 30 40 30 40 20 40 30 40
> >
> > We can sum the counts keyed by value
> > v (+//.) n
> > 180 110
> > since
> > v (</.) n
> > +--------------+-----------+
> > |20 40 40 40 40|30 30 20 30|
> > +--------------+-----------+
> >
> > However my actual values for count get very large,
> > ie up to 2^50 or more, and I needed exact integer results
> > so used
> > v (x:@+//.) n
> > 180 110
> >
> > but this got very slow.
> >
> > However once I used the indices i of the counts
> > i,v,:n
> > 0 1 2 1 2 0 2
> > 1 2
> > 1 2 1 2 1 2 1
> > 2 1
> > 20 30 40 30 40 20 40 30 40
> >
> > the more indirect derivation
> > (v (</.) i)
> > +---------+-------+
> > |0 2 2 2 2|1 1 0 1|
> > +---------+-------+
> > (v (</.) i)(x:@+/@:{)every <n
> > 180 110
> >
> > is much quicker.
> >
> > Any ideas why the circumlocution is faster than
> > the more obvious approach? (I don't know how
> > much because the slow version never finished.)
> >
> > Not really important in the scheme of things -
> > just a day lost in a Mathschallenge solution!
> > I hope that's not a give-away.
> -----------------------------------------------------------------
> -----
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> -----------------------------------------------------------------
> ---
> mail2web.com Enhanced email for the mobile individual based on
> Microsoft®Exchange - http://link.mail2web.com/Personal/EnhancedEmail
>
>
> -----------------------------------------------------------------
> -----
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list