[Numpy-discussion] odd performance of sum?

Sturla Molden sturla@molden...
Sun Feb 13 10:11:35 CST 2011


Den 13.02.2011 01:02, skrev eat:
> Now, I'm not pretending to know what kind of a person a 'typical' 
> numpy user is. But I'm assuming that there just exists more than me 
> with roughly similar questions in their (our) minds and who wish to 
> utilize numpy more  'pythonic; all batteries included' way. 
> Ocassionally I (we) may ask really stupid questions, but please beare 
> with us.

It was not a stupid question. It is not intuitive that N multiplications 
and N additions can be faster than just N additions.

>  If you need fast loops, you
>
>     can always write your own Fortran or C, and even insert OpenMP
>     pragmas.
>
> That's a very important potential, but surely not all numpy users are 
> expected to master that ;-)

Anyone who is serious about scintific computing should spend some time 
to learn Fortran 95, C, or both.

Fortran is easier to learn and use, and has arrays like NumPy. C is more 
portable, but no so well suited for numerical computing.

One of the strengths of NumPy, compared to e.g. Matlab, is the easy 
integration with C and Fortran libraries using tools like ctypes, f2py, 
Cython, or Swig. If you have ever tried to write a MEX file for Matlab, 
you'll appreciate NumPy.

It is also a big strength to learn to use certain numerical libraries, 
like BLAS and LAPACK (e.g. Intel MKL and AMD ACML), IMSL, FFTW, NAG, et 
al., to avoid reinventing the wheel. Most of the numerical processing in 
scientific computing is done by these libraries, so even learning to use 
them and call them from Python (e.g. with ctypes) is a very useful 
skill. Premature optimization might be the root of all evil in computer 
programming, but reinventing the wheel is the root of all evil in 
scienfic computing. People far to often resort to C or Fortran, when 
they should just have called a (well known) library function. But apart 
from that, knowing C and/or Fortran is a too important skill to ignore. 
For example, just knowing about C and Fortran data types and calling 
conventions makes using existing libraries with ctypes or f2py easier. 
Go ahead and learn it, you will not regret it.

(What you probably will regret, is wasting your time on learning Fortran 
i/o or C++. We have Python for that.)


Sturla





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110213/08ea3868/attachment.html 


More information about the NumPy-Discussion mailing list