Oh dear, I fear that array didn't come across formatted very well.  Try
this: http://pastebin.ca/2382718


On Sun, May 26, 2013 at 12:47 PM, Jeremy Smith <[email protected]
> wrote:

> > Can you post your commands?  It would be an interesting exercise trying
> to optimize for performance.
>
> > -Dan
>
> I will be happy to share my commands, with the disclaimer that I'm a
> novice at J.  My approach is simply what I've been able to cobble together
> in isolation.
>
> Suppose you have the following array of factors, each row being a box:
>
>  1.75481  1.62128   1.9037  2.32099 2.23944 2.92083 0.929577 3.41011
> 1.87385 1.50193 1.46014 1.23175
> 1.33699  1.25722  1.25292  1.45213 1.66981 1.11555  1.94697 1.65239
> 1.81117 2.06941 2.37717       0
> 1.09631  1.30063  1.37888  1.06136 1.11959 1.35294  1.38781 1.20239
> 1.22937 1.38261       0       0
> 1.19252  1.19422  1.05293  1.26402 1.14045 1.23251  1.24019 1.16252
> 1.20354       0       0       0
> 1.07837 0.998656  1.03209  1.06962 1.24631 1.06288  1.05953 1.07418
> 0       0       0       0
> 1.03052  1.02557  1.05389  1.10402 1.02959 1.03608  1.06828       0
> 0       0       0       0
> 1.00987  1.02625  1.08751 0.964162 1.03218 1.04666        0       0
> 0       0       0       0
> 1.00419  1.04348 0.997288  1.01199 1.00334       0        0       0
> 0       0       0       0
> 1.00139        1  1.02448        1       0       0        0       0
> 0       0       0       0
>       1        1        1        0       0       0        0       0
> 0       0       0       0
>       1        1        0        0       0       0        0       0
> 0       0       0       0
>       1        0        0        0       0       0        0       0
> 0       0       0       0
>
> I want to find every possible product down the columns and store the
> results in a box. The only exception is that I don't want any products
> where the result is zero.  In other words, every nonzero term in the first
> row multiplied by every nonzero term in the second row multiplied by .....
>
> Because there are 12 nonzero factors in the first row, 11 in the second,
> and so on, there will be 12! total products in the resulting box.
>
> Here's the gerund I came up with to do it:
>
> convolvefactors=:multiplyfirsttwoboxesandappend`justmultiplyfirsttwoboxes@
> .arethereonlytwoboxes
>
> where:
>
> arethereonlytwoboxes=:{.@(=&2@$)
>
> justmultiplyfirsttwoboxes=:<@(sparse@(>@(0&{)) */ sparse@(>@(1&{)))
>
> multiplyfirsttwoboxesandappend=:<@(sparse@(>@(0&{)) */ sparse@(>@(1&{)))
> , 2&}.
>
> sparse=:5 & $.@ $.
>
> In this case, convolvefactors(^:11) applied to the array above will give
> the result I want.  (But remember, each row must be a box.  I displayed it
> as an array above because I couldn't figure out how to paste the boxes).
>
> This function, convolvefactors(^:11), terminates in about 30 minutes on my
> little Mac Mini.  It doesn't even get out of the gate on my Windows 7
> laptop; I get an immediate "Out of Memory" error.
>
> By the way, I stumbled upon the "sparse" function above when I was trying
> to get rid of the 0's.  I realized after the fact that I could have done
> something like this:
>
> removezeros=:(#~(~:&0)) (&.>)
>
>
> Cheers,
> Jeremy
>
>
> On Sun, May 26, 2013 at 9:26 AM, Jeremy Smith <
> [email protected]> wrote:
>
>> Hi everyone,
>>
>> I was trying to take 9 boxes and multiply them all together, storing the
>> output in a single box.  The first of the 9 boxes contains 12 numbers, the
>> second contains 11, and so on, so that the output of this calculation will
>> be a single box with 12*11*10*9*8*7*6*5*4=79,833,600 numbers.
>>
>> When I do this on Jgtk701 for Mac, the operation completes successfully
>> and requires about 10 seconds.  On my windows machine I receive an "Out of
>> Memory" error.  I'm using exactly the same series of commands.
>>
>> Do these errors vary by machine, or operating system?  My windows laptop
>> has 8GB of RAM compared to my Mac's puny 4GB.
>>
>> Thanks,
>> Jeremy
>>
>>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to