[Numpy-discussion] Obscure code in concatenate code path?

Travis Oliphant travis at continuum.io
Thu Sep 13 10:01:05 EDT 2012

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. 


More information about the NumPy-Discussion mailing list