[SciPy-dev] Cython / python policy
Fri Mar 6 19:55:09 CST 2009
Matthew Brett wrote:
> I was just thinking of doing some Cython.
> Do we think that, in general, scipy code should have both C(ython)
> _and_ python implementations of the same thing, with different names,
> as for Anne's spatial package?y-dev
I think SciPy should adopt the same policy as Python 3. That is, first
import a Python module, then try to import a C module on top of that,
Having two versions with similar functionality but different name in
Python and C (e.g. pickle and cPickle, profile and cProfile, KDTree and
cKDTree) is not a good idea. SciPy will move to Python 3 at some point
anyway, and doing this differently from other Python packages would be
confusing. It is less messy this way as well, as we avoid subtle
differences between the C and Python objects - any difference would be
considered a bug. It would also mean that anything is prototyped in
Python first, before migration to C. Hopefully it would also limit the
use of C to the parts that really benefit from migration, as the working
Python code is always written first.
To use Anne's kd-tree as an example, a tentative organization of the
code would be a Python module kdtree.py with a full Python
implementation of teh kd-tree, and a Cython file ckdtree.pyx with a
partial Cython re-implementation.
# full python implementation here
from ckdtree import KDTree
__all__ = ['KDTree']
from kdtree import baseKDTree
# Cython re-implementation of the slowest
# parts of the base class, the rest we keep
# in Python.
More information about the Scipy-dev