[Cython] Interest in contributing to the project

Arthur de Souza Ribeiro arthurdesribeiro at gmail.com
Sun Apr 3 04:17:37 CEST 2011


Hi Stefan, well, i took a look at CPython's source code and as you said, if
we use Cython in there we could get a very more readable code without losing
performance (I suppose).

I took a look especially in cmathmodule.c that composes Python 3.2 source
code (more recent stable version). As you said, depending on how fast I
create the Cython code, we could add more modules (like socket one, for
example).

An example on how code would be more readable (in my opinion, please correct
me if I'm wrong) is that we wouldn't have to have configuration code about
what functions would compose the module, for example, in math module we
have:

static PyMethodDef cmath_methods[] = {
    {"acos",   cmath_acos,  METH_VARARGS, c_acos_doc},
    {"acosh",  cmath_acosh, METH_VARARGS, c_acosh_doc},
    {"asin",   cmath_asin,  METH_VARARGS, c_asin_doc},
    {"asinh",  cmath_asinh, METH_VARARGS, c_asinh_doc},
    {"atan",   cmath_atan,  METH_VARARGS, c_atan_doc},
    {"atanh",  cmath_atanh, METH_VARARGS, c_atanh_doc},
    {"cos",    cmath_cos,   METH_VARARGS, c_cos_doc},
    {"cosh",   cmath_cosh,  METH_VARARGS, c_cosh_doc},
    {"exp",    cmath_exp,   METH_VARARGS, c_exp_doc},
    {"isfinite", cmath_isfinite, METH_VARARGS, cmath_isfinite_doc},
    {"isinf",  cmath_isinf, METH_VARARGS, cmath_isinf_doc},
    {"isnan",  cmath_isnan, METH_VARARGS, cmath_isnan_doc},
    {"log",    cmath_log,   METH_VARARGS, cmath_log_doc},
    {"log10",  cmath_log10, METH_VARARGS, c_log10_doc},
    {"phase",  cmath_phase, METH_VARARGS, cmath_phase_doc},
    {"polar",  cmath_polar, METH_VARARGS, cmath_polar_doc},
    {"rect",   cmath_rect,  METH_VARARGS, cmath_rect_doc},
    {"sin",    cmath_sin,   METH_VARARGS, c_sin_doc},
    {"sinh",   cmath_sinh,  METH_VARARGS, c_sinh_doc},
    {"sqrt",   cmath_sqrt,  METH_VARARGS, c_sqrt_doc},
    {"tan",    cmath_tan,   METH_VARARGS, c_tan_doc},
    {"tanh",   cmath_tanh,  METH_VARARGS, c_tanh_doc},
    {NULL,              NULL}           /* sentinel */
};


static struct PyModuleDef cmathmodule = {
    PyModuleDef_HEAD_INIT,
    "cmath",
    module_doc,
    -1,
    cmath_methods,
    NULL,
    NULL,
    NULL,
    NULL
};

And the init function after it, as I saw in cython (and implemented some
examples), we would just have to implement the functions that the
compilation would generate the object files that would be imported.

But, I noticed a problem that may likely appears that is the configuration
part. I mean, Cython code is compiled differently than CPython's one right?
If yes, would you have an idea on how we could work on this?

Another stuff that I'm getting in trouble in this initial part is how we
would translate functions like PyArg_ParseTuple, any clue? I'm studing ways
to replace too.

As you suggested, I'm practicing Cython to create functions and get more and
more familiar with the language, so that I can create a very efficient
cython code that would meet our expectations. I'm also reading CPython's
code to see where cython can be applied.

Thank you.

Best Regards.

[]s

Arthur

2011/4/2 Stefan Behnel <stefan_ml at behnel.de>

> Hi Arthur,
>
> Arthur de Souza Ribeiro, 02.04.2011 03:52:
>
>  HI Stefan, thank you very much for responding my e-mail to cython's list.
>>
>> About the proposal, I'd be very happy in helping the cython community
>> doing
>> the task 'rewrite modules in CPython's standard library in Cython that are
>> currently written in C'. I didn't think about any special modules, but I'm
>> going to start doing it, in my opinion, both modules you've mentioned are
>> really good examples.
>>
>
> Cool.
>
>
>
>  I think this project could be very important, but, I don't know CPython
>> very
>> well, are there any examples you could suggest me to understand CPython
>> better? I think I could do a good effort to understand this as fast as I
>> can
>> and we discuss more the proposal.
>>
>
> The nice thing about this task is that you don't have to be an expert of
> CPython's C-API, nor a core developer of Cython. You will have to read the C
> code of the modules, and you will have to look up and understand what the
> C-API calls in the code are doing, but most of them have rather
> understandable names.
>
> However, you will have to program efficiently in Cython, and write fast
> code in it. Writing Cython code that is easy to read and maintain, and at
> the same time fast enough to replace the existing manually tuned C code is
> the challenging bit here.
>
> So my advice would be to get going in Cython programming (take a look
> through our tutorials), and to start reading the source code of a couple of
> CPython stdlib modules to get an idea of what you need to translate.
>
> It would certainly help your application if you could reimplement one
> reasonably sized and self-contained function in a stdlib C module of your
> choice, and present that on the cython-users mailing list to get feedback. A
> couple of benchmark or profiling results comparing it to the original
> CPython function would round this up very nicely.
>
> Stefan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20110402/d5db1719/attachment.html>


More information about the cython-devel mailing list