Interestingly, I see almost no change in speed/space between (my) f2 and f3...
ts 'f2 1000 1000$9'
0.231313 2.20224e7
ts 'f3 1000 1000$9'
0.235067 2.0974e7
Well - I guess a million bytes in space saving is
nothing to sneeze at (used to be a lot of
memory...) so I applaud the optimization work you
have done!
Thanks - joey
At 10:08 -0700 2008/06/30, Roger Hui wrote:
To gain more speed (and reduce space), use:
f3=: 3 : 'y * ($y) [EMAIL PROTECTED] 0'
[EMAIL PROTECTED] is supported by special code. The difference
is most striking for random booleans:
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
ts '1e6 [EMAIL PROTECTED] 2'
0.00275063 1.04934e6
ts '?1e6$2'
0.00555685 5.24352e6
----- Original Message -----
From: Joey K Tuttle <[EMAIL PROTECTED]>
Date: Monday, June 30, 2008 8:54
Subject: RE: [Jprogramming] Random number generation
To: Programming forum <[email protected]>
Cc: 'Programming forum' <[email protected]>
Not to quibble... but
f2 =: 3 : 'y * ?(#y)#0'
has a related trouble to the original post with
argument rank > 1 ... f1 is actually better in
extending "to work with arrays of any shape". To
try to gain some speed, perhaps you really meant
to say:
f2 =: 3 : 'y * ?($y)$0'
- joey
At 10:59 -0400 2008/06/30, Henry Rich wrote:
>What you executed was:
>
>3 3 * ?0
>
>which is
>
>3 3 * (?0)
>
>in other words, you asked for one number, then multiplied it by
3 twice.
>
>
>You could have your verb apply to atoms by giving it a rank of 0:
>
> f1 =: 3 : 'y * ?0'"0
>
>Or, you could design it to work with arrays of any shape:
>
> f2 =: 3 : 'y * ?(#y)#0'
>
>Working with bigger arrays is faster, but perhaps not by enough
>to be worth the trouble. Depends on your application.
>
>Henry Rich
>
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of
>> Benoît Roesslinger
>> Sent: Monday, June 30, 2008 10:46 AM
>> To: [email protected]
>> Subject: [Jprogramming] Random number generation
>>
>> Hi,
>>
>> I am new to J and when doing some experiments with random
>> number generation
>> I stumbled across the following behavior, which wasn't what
>> I'd expect :
>>
>> f=: 3 : 'y * ?0'
>> f 3
>> 2.91414
>> f 3
>> 0.139888
>> f 3
>> 0.990328
>>
>> OK so far, but when I tried:
>>
>> f 3 3
>>
>> it gives me :
>>
>> 0.0403801 0.0403801 (same values!)
>>
>> whereas I'd expect a behavior much like the one of '?'...
>> Is this behavior normal ?
>> Suppose I want to create a function to generate a random
>> deviate from a
>> distribution (normal for instance) with some parameters (mean
>> and sd for
>> instance) that will work in the same fashion as '?', ie
it is
>> possible to
>> generate lots of random deviates at once using code
such as :
>> distri 100 $
>> x, where x would represent parameters, what is the best
way to go ?
>>
>> Many thanks in advance!
>>
>> Benoît.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm