Difference between revisions of "IgnoreWarnings"

(rewrite)
(rewrite)
Line 13: Line 13:
 
= Notes =
 
= Notes =
  
In some cases, judicious use of IgnoreWarnings can speed up evaluation.  This can be the case if inner expressions encounter many warning conditions, even though these may never reach the final result.  For example, an expression such as:
+
Judicious use of '''IgnoreWarnings''' can speed up calculation in some cases where inner expressions encounter many warning conditions, which do not propagate to the final result.  Consider:
 
  If x>0 then Sqrt(X) else Sqrt(-X)
 
  If x>0 then Sqrt(X) else Sqrt(-X)
  
can benefit when x is a very large array.  This expression encounters a warning condition for every X (assuming they are all non-zero), since either Sqrt(X) or Sqrt(-X) requires a warning.  You will not see any of these warnings, since none of them make it to the top level, but because Analytica must do extra bookkeeping to deduce whether it needs to display a warning, the expression evaluates quicker inside IgnoreWarnings, i.e.:
+
This expression encounters a warning condition for every X (assuming they are all non-zero), since either Sqrt(X) or Sqrt(-X) requires a warning.  You will not see any of these warnings, since none of them make it to the top level. But Analytica must do extra bookkeeping to track the warnings and decide whether it needs to display them. So, it will evaluate more quickly (especially if x large) if you embed the expression inside IgnoreWarnings, i.e.:
  IgnoreWarnings( if x>0 then Sqrt(X) else Sqrt(-X) )
+
  IgnoreWarnings(IF x>0 THEN Sqrt(X) ELSESqrt(-X))
  
In this example, the best equivalent expression would be Sqrt(Abs(X)), which would half the number of Sqrt evaluations with no warning issues.  The example was chosen for illustrative purposes.
+
We chose this example for illustration only -- it would be simpler and faster still to use the equivalent:
 +
  Sqrt(Abs(X))

Revision as of 00:28, 18 April 2007


IgnoreWarnings(e)

Evaluates the expression, e, while suppressing any warnings that might otherwise be generated during the evaluation of e.

We highly recommend that you keep the Show Result Warnings checked in the Preferences Dialog, since warnings can help you find many modeling errors. However, sometimes you really do want to do something that generates a warning. For example, you may intentionally want to allow an out-of-range subscript, which returns NULL when warnings are ignored. In these cases, you can wrap the expression inside IgnoreWarnings to suppress the warnings, while leaving Show Result Warnings checked.

Example

IgnoreWarnings( Emissions[@Time=@Time+1] )

Notes

Judicious use of IgnoreWarnings can speed up calculation in some cases where inner expressions encounter many warning conditions, which do not propagate to the final result. Consider:

If x>0 then Sqrt(X) else Sqrt(-X)

This expression encounters a warning condition for every X (assuming they are all non-zero), since either Sqrt(X) or Sqrt(-X) requires a warning. You will not see any of these warnings, since none of them make it to the top level. But Analytica must do extra bookkeeping to track the warnings and decide whether it needs to display them. So, it will evaluate more quickly (especially if x large) if you embed the expression inside IgnoreWarnings, i.e.:

IgnoreWarnings(IF x>0 THEN Sqrt(X) ELSESqrt(-X))

We chose this example for illustration only -- it would be simpler and faster still to use the equivalent:

 Sqrt(Abs(X))
Comments


You are not allowed to post comments.