Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: avoiding non-machine numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115758] Re: avoiding non-machine numbers
  • From: wpb <wicher.bergsma at gmail.com>
  • Date: Thu, 20 Jan 2011 06:28:06 -0500 (EST)
  • References: <ih164u$jd2$1@smc.vnet.net>

On Jan 17, 10:37 am, DrMajorBob <btre... at austin.rr.com> wrote:
> The difference could be 4GB of RAM here, speed of the hard drive, other =
 
> applications running... who knows?
>
> Bobby
>
> On Sun, 16 Jan 2011 04:53:51 -0600, Achilleas Lazarides  
>
>
>
> <achilleas.lazari... at gmx.com> wrote:
> > Strange, I just tried again and got the same answer:
> > In[9]:= Exp[-#^2] &@
> >    RandomReal[NormalDistribution[0, 20], 400000]; // Timing
> > switchCatchUnderflow[];
> > Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing
> > switchCatchUnderflow[];
> > $Version
>
> > Out[9]= {1.66873, Null}
>
> > Out[11]= {0.130301, Null}
>
> > Out[13]= "8.0 for Mac OS X x86 (64-bit) (November 6, 2010)"
>
> > No difference after quitting and restarting the kernel etc.
>
> > On Jan15, 2011, at 9:07 PM, DrMajorBob wrote:
>
> >> It made far less difference here:
>
> >> switchCatchUnderflow[] := (SetSystemOptions[
> >>     CatchMachineUnderflow -> #1] &)[! CatchMachineUnderflow /.
> >>   SystemOptions[CatchMachineUnderflow]]
>
> >> Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing
> >> switchCatchUnderflow[];
> >> Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing
>
> >> {1.54747, Null}
>
> >> {1.4913, Null}
>
> >> $Version
>
> >> "8.0 for Mac OS X x86 (64-bit) (November 6, 2010)"
>
> >> Bobby
>
> >> On Sat, 15 Jan 2011 03:47:22 -0600, Achilleas Lazarides  
> >> <achilleas.lazari... at gmx.com> wrote:
>
> >>> I have this in my init.m:
>
> >>> switchCatchUnderflow[]:==(SetSystemOptions[CatchMachineUnderflow-=
>#1]&)[!CatchMachineUnderflow/.SystemOptions[CatchMachineUnderflow]]
>
> >>> which flips the option indicated. I get:
>
> >>> In[65]:== Exp[-#^2] &@
> >>>   RandomReal[NormalDistribution[0, 20], 400000]; // Timing
> >>> switchCatchUnderflow[];
> >>> Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing
>
> >>> Out[65]== {1.62773, Null}
>
> >>> Out[67]== {0.12662, Null}
>
> >>> On Jan14, 2011, at 12:17 PM, wpb wrote:
>
> >>>> t == RandomReal[NormalDistribution[0, 20], 400000];
> >>>> Exp[-t^2]; // Timing
>
> >> --
> >> DrMajor... at yahoo.com
>
> --
> DrMajor... at yahoo.com

Many thanks for the useful discussion, learnt several new things. I
think I'll be using Rolf's compile solution for now (I had tried
compile before, but in a less clever way which didn't work well).
Achilleas' solution is quite interesting as well, esp. as it doesn't
seem to slow things down when there is no machine underflow (however I
need to figure out how to implement exactly, I probably did something
wrong but modifying init.m didn't work with a quick try).

In fact, I've run into this problem many times over the years and have
used various ad hoc solutions, I'd be quite happy if the people at
Wolfram Inc implemented a thorough solution.

Wicher


  • Prev by Date: Re: Array of arrays of various sizes and compile
  • Next by Date: Re: DesignerUnits: Gallons divided by km yields an area.
  • Previous by thread: Re: avoiding non-machine numbers
  • Next by thread: Re: avoiding non-machine numbers