Re: Extending Plus very slow
- To: mathgroup at smc.vnet.net
- Subject: [mg66777] Re: Extending Plus very slow
- From: Giuseppe Bilotta <bilotta78 at hotpop.com>
- Date: Tue, 30 May 2006 05:48:15 -0400 (EDT)
- References: <e5ei4g$7ut$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Mon, 29 May 2006 10:24:16 +0000 (UTC), Giuseppe Bilotta wrote: > I found an interesting bottleneck in the way > Plus is handled. If I have: > > Unprotect[Plus]; > PlusNS[a__AffineExpression /; Length[{a}] > 1] := > Sanitize@AffineExpression[Plus @@ Center /@ {a}, > Join @@ Deviations /@ {a}]; > Plus[a__AffineExpression /; Length[{a}] > 1] := > Sanitize@AffineExpression[Plus @@ Center /@ {a}, > Join @@ Deviations /@ {a}]; > a_AffineExpression + b_Interval := a + AffineExpression[b] > a_Interval + b_AffineExpression := AffineExpression[a] + b > AffineExpression[c_, dev_] + other_?NumberQ := > AffineExpression[c + other, dev] > Protect[Plus]; > > and then run an intensive test > > LastNoiseSymbol = 0; > rndaff := > AffineExpression[Random[Real, {-1, 1}], Table[{Random[Integer, {2, > 20}], Random[Real, {-1, 1}]}, {Random[Integer, {2, 8}]}]]; > Timing@(pretest = Table[rndaff, {10000}];) > Timing@(test = Sanitize /@ pretest;) > Timing@(sns = PlusNS @@ test;) > Timing@(sp = Plus @@ test;) > > I get that sp calculates in about 10 times as much time as sns (about > 5 seconds vs about .5 seconds). Sorry for replying to my own post, but after some extensive testing I found out that the reason for the slowdown is the "Orderless" attribute in Plus. Clearing it speeds things up considerably, but it breaks "further down the line" ... -- Giuseppe "Oblomov" Bilotta "I'm never quite so stupid as when I'm being smart" --Linus van Pelt