[Numpy-discussion] Obscure code in concatenate code path?
Matthew Brett
matthew.brett at gmail.com
Thu Sep 13 13:34:07 EDT 2012
Hi,
On Thu, Sep 13, 2012 at 3:01 PM, Travis Oliphant <travis at continuum.io> wrote:
>
> On Sep 13, 2012, at 8:40 AM, Nathaniel Smith wrote:
>
>> On Thu, Sep 13, 2012 at 11:12 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
>>> Hi,
>>>
>>> While writing some tests for np.concatenate, I ran foul of this code:
>>>
>>> if (axis >= NPY_MAXDIMS) {
>>> ret = PyArray_ConcatenateFlattenedArrays(narrays, arrays, NPY_CORDER);
>>> }
>>> else {
>>> ret = PyArray_ConcatenateArrays(narrays, arrays, axis);
>>> }
>>>
>>> in multiarraymodule.c
>>
>> How deeply weird
>
>
> This is expected behavior. It's how the concatenate Python function manages to handle axis=None to flatten the arrays before concatenation. This has been in NumPy since 1.0 and should not be changed without deprecation warnings which I am -0 on.
>
> Now, it is true that the C-API could have been written differently (I think this is what Mark was trying to encourage) so that there are two C-API functions and they are dispatched separately from the array_concatenate method depending on whether or not a None is passed in. But, the behavior is documented and has been for a long time.
>
> Reference PyArray_AxisConverter (which turns a "None" Python argument into an axis=MAX_DIMS). This is consistent behavior throughout the C-API.
How about something like:
#define NPY_NONE_AXIS NPY_MAXDIMS
to make it clearer what is intended?
Best,
Matthew
More information about the NumPy-Discussion
mailing list