mg7715 Sums vs Map efficiency
- To: mathgroup at smc.vnet.net
- Subject: [mg7907] mg7715 Sums vs Map efficiency
- From: Andre Deprit <Deprit at his.com>
- Date: Mon, 21 Jul 1997 03:21:59 -0400
- Organization: Heller Information Services, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
Mr. Pichon asked for a tensorial version of his program gm=Table[ Sum[ A1[[i,j,k]]* A2[[i1,k1]]* a[[i,i1]]* a[[j,j1]] ,{i1,n},{j1,n},{i,n},{j,n}] ,{k,n},{k1,n}]//Flatten; Here is a suggestion. R = Transpose[ Map[ Plus @@ # &, Transpose[A2] . Transpose[a] . Transpose[A1, {1, 3, 2}] . a, {2}]] Note that the Flatten which is wrapping gm has been dropped. On a Macintosh Power 3400-240, for n = 6, the summations for gm are executed in about 21 sec while R is calculated in about 2.8 sec. As the check TrueQ[Expand[R] === gm] reveals, however, the performance improvement is, for the most part, an illusion. Indeed, the code R = Transpose[ Map[ Expand[Plus @@ #] &, Transpose[A2] . Transpose[a] . Transpose[A1, {1, 3, 2}] . a, {2}]] takes about 18 sec.