Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11080
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Can anyone see a faster way to compute quantities for a pair or |
| Date | 2012-07-26 07:36 +0000 |
| Message-ID | <juqs15$66q$1@smc.vnet.net> (permalink) |
| References | <juim0j$k9a$1@smc.vnet.net> <20120724081538.B3AF16802@smc.vnet.net> |
| Organization | Time-Warner Telecom |
On Jul 24, 11:34 pm, W Craig Carter <ccar...@MIT.EDU> wrote:
> 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]]}
I can only speculate about why the original code is slow,
but I can offer informed advice about how to keep my code
running fast: gradfield must be a packed array.
Also, my code for the angles can be simplified slightly,
with no change in speed:
psifield2 = ArcTan[gradfield[[1]] + UnitStep[-magfield2],
gradfield[[2]]]
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can anyone see a faster way to compute quantities for a pair or large matrices? W Craig Carter <ccarter@MIT.EDU> - 2012-07-23 05:04 +0000 Re: Can anyone see a faster way to compute quantities for a pair or daniel.lichtblau0@gmail.com - 2012-07-23 23:59 +0000 Re: Can anyone see a faster way to compute quantities for a pair or large matrices? "andre.robin3" <andre.robin281@orange.fr> - 2012-07-24 08:15 +0000 Re: Can anyone see a faster way to compute quantities for a pair or Ray Koopman <koopman@sfu.ca> - 2012-07-24 08:15 +0000 Re: Can anyone see a faster way to compute quantities for a pair or Ray Koopman <koopman@sfu.ca> - 2012-07-24 08:16 +0000 Re: Can anyone see a faster way to compute quantities for a pair or W Craig Carter <ccarter@MIT.EDU> - 2012-07-25 06:34 +0000 Re: Can anyone see a faster way to compute quantities for a pair or large matrices? W Craig Carter <ccarter@MIT.EDU> - 2012-07-25 06:31 +0000 Re: Can anyone see a faster way to compute quantities for a pair or Ray Koopman <koopman@sfu.ca> - 2012-07-26 07:36 +0000 Re: Can anyone see a faster way to compute quantities for a pair or Sseziwa Mukasa <mukasa@gmail.com> - 2012-07-26 07:38 +0000
csiph-web