Hi Sturla,

First of all, my apologies to have spelled your name wrong for the
past year - I just realized it! Thanks to Eric Firing who pointed this
out to me. Thank you Sturla for bearing with me!

And then - thank you for pointing out Numba! I tried to use it years
ago, but ended up Cython eventually because the loop-jitting
constraint 
(http://numba.pydata.org/numba-doc/0.16.0/arrays.html#loop-jitting-constraints)
was too strict by that time. After seeing your email, I went to the
latest version and saw that it has been greatly relaxed! I really look
forward to using it for any new projects. Most of the time,
loop-jitting is all I need.

Lastly, your comments on Fortran 90/95 is convincing me to move away
from Fortran 77. I am writing a small section of code that was called
by some other legacy code written in F77. I heard that as long as I
compile it correctly, it will interface with the legacy code with no
problem. I'll definitely give it a try!

Thanks again for all the help Sturla,

Shawn



On Fri, Jan 2, 2015 at 8:22 AM, Sturla Molden <sturla.mol...@gmail.com> wrote:
> Yuxiang Wang <yw...@virginia.edu> wrote:
>
>> 4) I wanted to say that it seems to me, as the project gradually
>> scales up, Cython is easier to deal with, especially when I am using a
>> lot of numpy arrays. If it is even higher dimensional data, it would
>> be verbose while it is really succinct to use Cython.
>
> The easiest way to speed up NumPy code is to use Numba which is an LLVM
> based JIT compiler. Numba will often give you performance comparable to C
> for free. All you have to do is to add the @numba.jit decorator to your
> Python function and possibly include some type hints. If all you want is to
> speed up NumPy code, just use Numba and it will take care of it in at least
> 9 of 10 cases.
>
> Numexpr is also a JIT compiler which can speed up Numpy code, but it does
> not give as dramatic results as Numba.
>
> Cython is easier to work with than ctypes, particularly when the problem
> scales up. If you use typed memoryviews in Cython you can also avoid having
> to work with pointer arithmetics. Cython is mainly a competitior to using
> the Python C API manually for C extension modules to Python. Cython also
> allows you to wrap external C and C++ code, and e.g. use Python and C++
> objects together. The drawback is that you need to learn the Cython
> language as well as Python and C and C++ and know how they differ. Cython
> also have many of the same hidden dangers as C++, due to the possibility of
> exceptions being raised between C statements. But because Cython is the
> most flexible tool for writing C extensions to Python you will in the long
> run do yourself a favor by learning to use it.
>
> ctypes is good when you have a DLL, possibly form a foreign source, and you
> just want to use it without any build step. CFFI is easier to work with
> than ctypes and has the same usecase. It can parse C headers and does not
> require you to define the C API with Python statements like ctypes do.
> Generally I would say it is alway better to use CFFI than ctypes. ctypes is
> also currently an orphan, albeit in the Python standard library, while CFFI
> is actively maintained.
>
> Numba will also JIT compile ctypes and CFFI calls to remove the extra
> overhead. This is good to know if you need to call a C function in a tight
> loop. In that case Numba can JIT compile away the Python as well as the
> ctypes/CFFI overhead.
>
> Fortran 90/95 is also underrated. It is easier to work with than C, and
> gives similar results performance wise. You can call Fortran with f2py,
> ctypes, CFFI, or Cython (use fwrap). Generally I would say that it is
> better for a student to learn C than Fortran if you have to choose, because
> C is also useful for other things than numerical computing. But if you want
> fast and robust numerical code, it is easier to get good results with
> Fortran than C or Cython.
>
> Sturla
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



-- 
Yuxiang "Shawn" Wang
Gerling Research Lab
University of Virginia
yw...@virginia.edu
+1 (434) 284-0836
https://sites.google.com/a/virginia.edu/yw5aj/
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to