[SciPy-dev] cython in scipy?

Anne Archibald peridot.faceted at gmail.com
Thu Oct 9 03:40:04 EDT 2008


Okay, the cython code for the von Mises CDF is committed. It's
actually a mongrel, since I needed scipy.stats.norm.cdf and
scipy.special.i0 for one branch, and the only way I knew of get them
was through python, so I left that branch vectorized. Otherwise I
think the cython version would have been shorter than the python
version.

The new CDF code also makes a minor change in the API: for values
outside the domain -pi..pi, instead of returning cdf( (x+pi)%(2*pi)-pi
) it returns an increasing function. In particular, this means that
the probability of getting a value between x and y is cdf(y)-cdf(x)
whenever x and y differ by less than 2*pi. (Previously if x=3 and y=4
it gave you the probability minus 1.) This is valuable since the
"location" parameter shifts the domain: in particular, the CDF is zero
at "location" minus pi.

2008/10/9 Fernando Perez <fperez.net at gmail.com>:

> This is the kind of very simple code I've used in the past (back in
> the pyrex days, same thing for cython):
>
> # Make this usable by people who don't have pyrex installed (I've committed
> # the generated C sources to SVN).
> try:
>    from Pyrex.Distutils import build_ext
>    has_pyrex = True
>    cmdclass  = {'build_ext': build_ext}
> except ImportError:
>    has_pyrex = False
>    cmdclass  = {}
>
> # Set up key extension
> key_sources = ['mwadap/key.pyx']
> if not has_pyrex:
>    key_sources = [s.replace('.pyx','.c') for s in key_sources]
> keyx = Extension('mwadap.key',key_sources,
>                 include_dirs = [numpy_include_dir])
>
> ###

I didn't get this working, I'm afraid; I wasn't willing to delve into
the guts of numpy's distutils to figure out what was wrong, but it
complained that I'd given it a ".pyx" file but I didn't have Pyrex
installed.

Anne



More information about the SciPy-Dev mailing list