Stefan Behnel wrote:
> Dag Sverre Seljebotn, 13.04.2010 18:55:
>
>> Stefan Behnel wrote:
>>
>>> Lisandro Dalcin, 13.04.2010 17:09:
>>>
>>>
>>>> I really cannot understand the opposition to the None handling being
>>>> determined by a user-selected compiler directive...
>>>>
>>>>
>>> There is little use in a directive that everyone uses anyway. After finding
>>> out about it, that is...
>>>
>>>
>> Well, a lot of my typed arguments *are* None, and has None as a
>> perfectly valid value, so I wouldn't enable it.
>>
>
> Ah, so now we're getting to the 'why' of this discussion. lxml contains
> one(!) function with a typed argument that allows None, and that has a None
> default argument. So we see the world from completely different angles.
> Could you give code examples where typed None arguments make sense for you?
>
I do this a lot:
def some_operation(np.ndarray[double] a, np.ndarray[double] b,
np.ndarray[double] out=None):
if out is None:
# no output buffer allocated; allocate one
out = np.zeros_like(a)
# computation, store result in out
return out
But there's also stuff like (making up the concrete example):
def some_operation(np.ndarray values, np.ndarray jacobian):
for k in ...:
...
if jacobian is not None: # include it in the computation
...
These could all be handled by special-casing "arg=None", but I'd really,
really prefer choosing default values for arguments to be an orthogonal
issue to this. Perhaps I want to force users into thinking about
supplying a jacobian or not -- it shouldn't be up to the Cython language.
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev