On 7/21/07, Eric Firing <[EMAIL PROTECTED]> wrote:

> Sometimes functions from the different sources do the same thing, but
> usually at different speeds.

And the difference may be *very* significant:

In [1]: import numpy as N

In [2]: import math as M

In [3]: nsqrt = N.sqrt

In [4]: msqrt = M.sqrt

In [5]: def sqtest(sqrt,reps):
   ...:     x = 99.9
   ...:     for i in xrange(reps):
   ...:         a = sqrt(x)
   ...:

In [13]: reps = int(1e6)

In [14]: time sqtest(msqrt,reps)
CPU times: user 0.90 s, sys: 0.00 s, total: 0.90 s
Wall time: 0.90

In [15]: time sqtest(nsqrt,reps)
CPU times: user 7.62 s, sys: 0.39 s, total: 8.02 s
Wall time: 8.08

The overhead from numpy for scalars is not trivial at all.  And as you
pointed out, the semantical differences between math, cmath and numpy
(ignoring ma for now) are important enough that people should know
exactly what they are getting.

I guess if you want to provide a 'common math functions' module with
clearly defined conventions for everyday usage, you could do something
like (using cos as an example, apply to all names that are common to
all such modules):

numpy.cos -> cos  # unmodified, numpy is the 'default' a la matlab
math.cos  -> scos # names from math are s-prefixed for 'scalar' (could be 'm')
cmath.cos -> ccos # complex names
numpy.ma.cos -> macos # masked array names


Just an idea...

Cheers,

f

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to