* Concatenates a list of ndarrays. */
| 392 | * Concatenates a list of ndarrays. |
| 393 | */ |
| 394 | NPY_NO_EXPORT PyArrayObject * |
| 395 | PyArray_ConcatenateArrays(int narrays, PyArrayObject **arrays, int axis, |
| 396 | PyArrayObject* ret, PyArray_Descr *dtype, |
| 397 | NPY_CASTING casting) |
| 398 | { |
| 399 | int iarrays, idim, ndim; |
| 400 | npy_intp shape[NPY_MAXDIMS]; |
| 401 | PyArrayObject_fields *sliding_view = NULL; |
| 402 | |
| 403 | if (narrays <= 0) { |
| 404 | PyErr_SetString(PyExc_ValueError, |
| 405 | "need at least one array to concatenate"); |
| 406 | return NULL; |
| 407 | } |
| 408 | |
| 409 | /* All the arrays must have the same 'ndim' */ |
| 410 | ndim = PyArray_NDIM(arrays[0]); |
| 411 | |
| 412 | if (ndim == 0) { |
| 413 | PyErr_SetString(PyExc_ValueError, |
| 414 | "zero-dimensional arrays cannot be concatenated"); |
| 415 | return NULL; |
| 416 | } |
| 417 | |
| 418 | /* Handle standard Python negative indexing */ |
| 419 | if (check_and_adjust_axis(&axis, ndim) < 0) { |
| 420 | return NULL; |
| 421 | } |
| 422 | |
| 423 | /* |
| 424 | * Figure out the final concatenated shape starting from the first |
| 425 | * array's shape. |
| 426 | */ |
| 427 | memcpy(shape, PyArray_SHAPE(arrays[0]), ndim * sizeof(shape[0])); |
| 428 | for (iarrays = 1; iarrays < narrays; ++iarrays) { |
| 429 | npy_intp *arr_shape; |
| 430 | |
| 431 | if (PyArray_NDIM(arrays[iarrays]) != ndim) { |
| 432 | PyErr_Format(PyExc_ValueError, |
| 433 | "all the input arrays must have same number of " |
| 434 | "dimensions, but the array at index %d has %d " |
| 435 | "dimension(s) and the array at index %d has %d " |
| 436 | "dimension(s)", |
| 437 | 0, ndim, iarrays, PyArray_NDIM(arrays[iarrays])); |
| 438 | return NULL; |
| 439 | } |
| 440 | arr_shape = PyArray_SHAPE(arrays[iarrays]); |
| 441 | |
| 442 | for (idim = 0; idim < ndim; ++idim) { |
| 443 | /* Build up the size of the concatenation axis */ |
| 444 | if (idim == axis) { |
| 445 | shape[idim] += arr_shape[idim]; |
| 446 | } |
| 447 | /* Validate that the rest of the dimensions match */ |
| 448 | else if (shape[idim] != arr_shape[idim]) { |
| 449 | PyErr_Format(PyExc_ValueError, |
| 450 | "all the input array dimensions except for the " |
| 451 | "concatenation axis must match exactly, but " |
no test coverage detected