Re: Particular structure

*To*: mathgroup at smc.vnet.net*Subject*: [mg33656] Re: Particular structure*From*: "Allan Hayes" <hay at haystack.demon.co.uk>*Date*: Thu, 4 Apr 2002 19:40:41 -0500 (EST)*References*: <a8g36d$b2s$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Yas, Here is a solution, simpler than the one one I posted Re: Particular structure[2] and that you report below. It seems to hold out more hop of generalizing. Quit x= y=Table[1,{400}];f=Plus;F= Times; Table[ReleaseHold[F@@#],{j, Length[y]}]&[ Table[f[x[[i]],Hold[y[[j]]],z],{i,Length[x]}]];//Timing {7.41 Second,Null} MaxMemoryUsed[ ] 1451568 As you note, the problem with using Outer is that a very large matrix is constructed, using lots of memory, before the function F is used. The method above, and my previous one, uses the fact that Table evaluates step by step, building up a list of *values* of F[...], these may use much less memory than the expressions F[...]. Of course if the values of F[...] were bigger than the expression then nothing would be gained. I have used Table for generating {f[..],f[...] ....} in case there is some benefit here also, and for uniformity. We could use f[...]&/@x as in my previous code. Incidentally, the use of Hold[ y[[i]] ] , and the subequent release with ReleaseHold is to prevent Mathematica reacting to y[[i]] with a symbolic input i, it generates messages and this slows down the evaluation considerable - even if we turn the messages off. GENERAL PRINCIPLE: avoid messages if possible - even if you turn them off they slow down evaluation. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Yas" <yast at optushome.com.au> wrote in message news:a8g36d$b2s$1 at smc.vnet.net... > Hi, > Thanks to all the replies to the problem I posted earlier on achieving a > particular structure. All the solutions provided deal with the problem > adequately but because my lists are fairly large I find myself running > out of memory. For example, using Outer on lists where x > 500 and y > > 100 gets me into trouble very quickly. The other draw back is that the > time for calculation gets long. > > In an effort to overcome these undesirable properties, Allan Hayes has > suggested the following construct, > > x = y = Table[i + 1, {i, 1, 400}]; f = Plus; F = Times @@ # &; > > Table[Function[kk, ReleaseHold[#]][y[[i]]], {i, Length[y]}] &[ > Hold[F][f[#, kk, z] & /@ x]]; // Timing > > {5.81667 Second, Null} > > This construct is more efficient than the ones I've constructed > previously in that the MaxMemoryUsed is reduced by a whopping 93% and > the time for evaluation reduced by half compared to those using Outer > and Map[Map... > > I wonder if there are any other suggestions to speeding things up even > more? > > Cheers > Yas > >