Stefan Behnel | 1 May 2012 21:22
Picon
Favicon

Re: [Cython] Conditional import in pure Python mode

Stefan Behnel, 01.05.2012 21:14:
> 2) Use math.pxd as an override for the math module. I'm not sure yet how
> that would best be made to work, but it shouldn't be all that complex. It
> already works (mostly?) for numpy.pxd, for example, although that's done
> explicitly in user code.

BTW, I think it would be helpful to make the numpy.pxd cimport automatic as
well whenever someone does "import numpy" and friends, right?

Stefan
mark florisson | 1 May 2012 21:39
Picon
Gravatar

Re: [Cython] Conditional import in pure Python mode

On 1 May 2012 20:22, Stefan Behnel <stefan_ml@...> wrote:
> Stefan Behnel, 01.05.2012 21:14:
>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>> that would best be made to work, but it shouldn't be all that complex. It
>> already works (mostly?) for numpy.pxd, for example, although that's done
>> explicitly in user code.
>
> BTW, I think it would be helpful to make the numpy.pxd cimport automatic as
> well whenever someone does "import numpy" and friends, right?
>
> Stefan
> _______________________________________________
> cython-devel mailing list
> cython-devel@...
> http://mail.python.org/mailman/listinfo/cython-devel

I'm not sure, it means the user has to have numpy development headers.
Francesc Alted | 1 May 2012 21:49

Re: [Cython] Conditional import in pure Python mode

On 5/1/12 2:39 PM, mark florisson wrote:
> On 1 May 2012 20:22, Stefan Behnel<stefan_ml@...>  wrote:
>> Stefan Behnel, 01.05.2012 21:14:
>>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>>> that would best be made to work, but it shouldn't be all that complex. It
>>> already works (mostly?) for numpy.pxd, for example, although that's done
>>> explicitly in user code.
>> BTW, I think it would be helpful to make the numpy.pxd cimport automatic as
>> well whenever someone does "import numpy" and friends, right?
>>
>> Stefan
>> _______________________________________________
>> cython-devel mailing list
>> cython-devel@...
>> http://mail.python.org/mailman/listinfo/cython-devel
> I'm not sure, it means the user has to have numpy development headers.

But if the user is going to compile a NumPy application, it sounds like 
strange to me that she should not be required to install the NumPy 
development headers, right?

--

-- 
Francesc Alted

Stefan Behnel | 1 May 2012 22:02
Picon
Favicon

Re: [Cython] Conditional import in pure Python mode

Francesc Alted, 01.05.2012 21:49:
> On 5/1/12 2:39 PM, mark florisson wrote:
>> On 1 May 2012 20:22, Stefan Behnel wrote:
>>> Stefan Behnel, 01.05.2012 21:14:
>>>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>>>> that would best be made to work, but it shouldn't be all that complex. It
>>>> already works (mostly?) for numpy.pxd, for example, although that's done
>>>> explicitly in user code.
>>> BTW, I think it would be helpful to make the numpy.pxd cimport automatic as
>>> well whenever someone does "import numpy" and friends, right?
>>>
>> I'm not sure, it means the user has to have numpy development headers.
> 
> But if the user is going to compile a NumPy application, it sounds like
> strange to me that she should not be required to install the NumPy
> development headers, right?

Let's say it's not impossible that someone uses NumPy and Cython without
any accelerated C level connection between the two, but it's rather
unlikely, given that Cython already has all dependencies that this
connection would require as well, except for the NumPy header files.

So I would suggest to make the automatic override the default for any
module for which a .pxd file with the same fully qualified name is found in
the search path, and to require users to explicitly disable this feature
for a given module using a module level (or external) compiler directive if
they feel like getting slower code (or working around a bug or whatever).

Anyway, given that this feature isn't even implemented yet, it may appear a
bit premature to discuss these details.
(Continue reading)

Robert Bradshaw | 2 May 2012 08:56
Picon

Re: [Cython] Conditional import in pure Python mode

On Tue, May 1, 2012 at 1:02 PM, Stefan Behnel <stefan_ml@...> wrote:
> Francesc Alted, 01.05.2012 21:49:
>> On 5/1/12 2:39 PM, mark florisson wrote:
>>> On 1 May 2012 20:22, Stefan Behnel wrote:
>>>> Stefan Behnel, 01.05.2012 21:14:
>>>>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>>>>> that would best be made to work, but it shouldn't be all that complex. It
>>>>> already works (mostly?) for numpy.pxd, for example, although that's done
>>>>> explicitly in user code.

math.pxd would be a bit trickier, as we're trying to shadow python
functions with independent c implementations (rather than declaring
structure to the single numpy array object and exposing c-level only
methods. We'd need to support stuff like

double x = ...
double y = sin(x) # fast
cdef object f = sin # grab the builtin one?

but this is by no means insurmountable and could be really useful.

>>>> BTW, I think it would be helpful to make the numpy.pxd cimport automatic as
>>>> well whenever someone does "import numpy" and friends, right?
>>>>
>>> I'm not sure, it means the user has to have numpy development headers.
>>
>> But if the user is going to compile a NumPy application, it sounds like
>> strange to me that she should not be required to install the NumPy
>> development headers, right?
>
(Continue reading)

Stefan Behnel | 2 May 2012 09:33
Picon
Favicon

Re: [Cython] Conditional import in pure Python mode

Robert Bradshaw, 02.05.2012 08:56:
> On Tue, May 1, 2012 at 1:02 PM, Stefan Behnel wrote:
>> Francesc Alted, 01.05.2012 21:49:
>>> On 5/1/12 2:39 PM, mark florisson wrote:
>>>> On 1 May 2012 20:22, Stefan Behnel wrote:
>>>>> Stefan Behnel, 01.05.2012 21:14:
>>>>>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>>>>>> that would best be made to work, but it shouldn't be all that complex. It
>>>>>> already works (mostly?) for numpy.pxd, for example, although that's done
>>>>>> explicitly in user code.
> 
> math.pxd would be a bit trickier, as we're trying to shadow python
> functions with independent c implementations (rather than declaring
> structure to the single numpy array object and exposing c-level only
> methods. We'd need to support stuff like
> 
> double x = ...
> double y = sin(x) # fast
> cdef object f = sin # grab the builtin one?
> 
> but this is by no means insurmountable and could be really useful.

I already did that for the builtin abs() function. Works nicely so far,
although not from a .pxd but declared internally in Builtin.py.

It's not currently supported for methods (I tried it for one of the builtin
types and it seemed to require more work than I wanted to invest at that
point), but I don't think we need that here. Module level functions should
totally be enough for math.pxd.

(Continue reading)

Robert Bradshaw | 2 May 2012 09:59
Picon

Re: [Cython] Conditional import in pure Python mode

On Wed, May 2, 2012 at 12:33 AM, Stefan Behnel <stefan_ml@...> wrote:
> Robert Bradshaw, 02.05.2012 08:56:
>> On Tue, May 1, 2012 at 1:02 PM, Stefan Behnel wrote:
>>> Francesc Alted, 01.05.2012 21:49:
>>>> On 5/1/12 2:39 PM, mark florisson wrote:
>>>>> On 1 May 2012 20:22, Stefan Behnel wrote:
>>>>>> Stefan Behnel, 01.05.2012 21:14:
>>>>>>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>>>>>>> that would best be made to work, but it shouldn't be all that complex. It
>>>>>>> already works (mostly?) for numpy.pxd, for example, although that's done
>>>>>>> explicitly in user code.
>>
>> math.pxd would be a bit trickier, as we're trying to shadow python
>> functions with independent c implementations (rather than declaring
>> structure to the single numpy array object and exposing c-level only
>> methods. We'd need to support stuff like
>>
>> double x = ...
>> double y = sin(x) # fast
>> cdef object f = sin # grab the builtin one?
>>
>> but this is by no means insurmountable and could be really useful.
>
> I already did that for the builtin abs() function. Works nicely so far,
> although not from a .pxd but declared internally in Builtin.py.
>
> It's not currently supported for methods (I tried it for one of the builtin
> types and it seemed to require more work than I wanted to invest at that
> point), but I don't think we need that here. Module level functions should
> totally be enough for math.pxd.
(Continue reading)

Stefan Behnel | 1 May 2012 21:51
Picon
Favicon

Re: [Cython] Conditional import in pure Python mode

mark florisson, 01.05.2012 21:39:
> On 1 May 2012 20:22, Stefan Behnel wrote:
>> Stefan Behnel, 01.05.2012 21:14:
>>> 2) Use math.pxd as an override for the math module. I'm not sure yet how
>>> that would best be made to work, but it shouldn't be all that complex. It
>>> already works (mostly?) for numpy.pxd, for example, although that's done
>>> explicitly in user code.
>>
>> BTW, I think it would be helpful to make the numpy.pxd cimport automatic as
>> well whenever someone does "import numpy" and friends, right?
> 
> I'm not sure, it means the user has to have numpy development headers.

Hmm, right. What about making it an explicit compile time option then?
Something like

  # cython: override_modules = math,numpy

Or should we go for an opt-out?

  # cython: python_modules = math,numpy

Sounds like it would hit the more common case by default.

Stefan

Gmane