On Mon, Sep 24, 2012 at 07:10:01AM -0500, Jason Grout wrote: > On 9/24/12 3:55 AM, Nicolas M. Thiery wrote: > >That being said, if there is a way to raise ValueError in a way that > >can be turned off like for assertions, I am happy to change my mind! > >(I am missing this from MuPAD; we could even change this at runtime > >which was really cool),. > > Of course, we can also define a utility function that does this: > > validation = True > def validate(condition, message): > if not condition and validation: > raise ValueError(message) > > > def myfunction(bound): > validate(bound>0, "bound must be positive because the square > root of the bound is used.") > > > Then changing the value of the validation variable turns on or off > messages. You still incur the function call cost, which is still a > negative.
Sorry if I have been unclear; the point is to turn off the *testing of the condition* altogether, in order not incur a speed penalty. Of course, this is only relevant for low level methods and/or expensive conditions. Cheers, Nicolas -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To post to this group, send email to sage-devel@googlegroups.com. To unsubscribe from this group, send email to sage-devel+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en.