Re: Can anyone see a faster way to compute quantities for a pair or

• To: mathgroup at smc.vnet.net
• Subject: [mg127441] Re: Can anyone see a faster way to compute quantities for a pair or
• From: W Craig Carter <ccarter at MIT.EDU>
• Date: Wed, 25 Jul 2012 02:32:35 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <juim0j\$k9a\$1@smc.vnet.net> <20120724081538.B3AF16802@smc.vnet.net>

```Thanks to Ray, Dan, Sseziwa, Andre, and David Park (offline response)
for their suggestions which improve computation time by about a factor
of 100.

I am very curious what is going on under the hood that makes my original
method (pasted again below) using MapThread so inefficient  compared to
the better solutions (i.e., using Apply and Map solutions not the
Compile solution).  This seems a good learning--and
teaching--opportunity.

(*original posting, the myArcTan is not the real culprit (btw, I am very
impressed with Ray's UnitStep trick*)

(* original inefficient posted method*)
gradfield =  { RandomReal[{-1, 1}, {256, 256}], RandomReal[{-1, 1},
{256, 256}]};

SetAttributes[myArcTan, {Listable, NumericFunction}];
myArcTan[0.0, 0.0] = 0.0;
myArcTan[x_, y_] := ArcTan[x, y]

(*the angles, this is slow*)
psiField = MapThread[myArcTan, gradfield, 2];

(*the magnitudes, this is slower*)
magfield =  MapThread[Norm[{#}] &, gradfield, 2];

>
>   psifield2 = ArcTan@@{gradfield[[1]] + UnitStep[-magfield2],
>                        gradfield[[2]]}

```

• Prev by Date: Re: FindCurvePath has a problem
• Next by Date: Re: Using Fit to interpolate data
• Previous by thread: Re: Can anyone see a faster way to compute quantities for a pair or
• Next by thread: Re: Can anyone see a faster way to compute quantities for a pair or