Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Can anyone see a faster way to compute quantities for a pair or large matrices?
Replies: 11   Last Post: Jul 26, 2012 3:38 AM

 Messages: [ Previous | Next ]
 Ray Koopman Posts: 3,345 Registered: 12/7/04
Re: Can anyone see a faster way to compute quantities for a pair or
Posted: Jul 26, 2012 3:36 AM

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*)
>
> (*the magnitudes, this is slower*)
>
>
>

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

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:

Date Subject Author
7/23/12 W. Craig Carter
7/23/12 daniel.lichtblau0@gmail.com
7/24/12 Ray Koopman
7/24/12 andre.robin3
7/24/12 Ray Koopman
7/25/12 W. Craig Carter
7/25/12 W. Craig Carter
7/26/12 Ray Koopman
7/26/12 Sseziwa Mukasa