* Private implementation of PyArray_CopyAnyInto with an additional order * parameter. */
| 2563 | * parameter. |
| 2564 | */ |
| 2565 | NPY_NO_EXPORT int |
| 2566 | PyArray_CopyAsFlat(PyArrayObject *dst, PyArrayObject *src, NPY_ORDER order) |
| 2567 | { |
| 2568 | NpyIter *dst_iter, *src_iter; |
| 2569 | |
| 2570 | NpyIter_IterNextFunc *dst_iternext, *src_iternext; |
| 2571 | char **dst_dataptr, **src_dataptr; |
| 2572 | npy_intp dst_stride, src_stride; |
| 2573 | npy_intp *dst_countptr, *src_countptr; |
| 2574 | npy_uint32 baseflags; |
| 2575 | |
| 2576 | npy_intp dst_count, src_count, count; |
| 2577 | npy_intp dst_size, src_size; |
| 2578 | int needs_api; |
| 2579 | |
| 2580 | NPY_BEGIN_THREADS_DEF; |
| 2581 | |
| 2582 | if (PyArray_FailUnlessWriteable(dst, "destination array") < 0) { |
| 2583 | return -1; |
| 2584 | } |
| 2585 | |
| 2586 | /* |
| 2587 | * If the shapes match and a particular order is forced |
| 2588 | * for both, use the more efficient CopyInto |
| 2589 | */ |
| 2590 | if (order != NPY_ANYORDER && order != NPY_KEEPORDER && |
| 2591 | PyArray_NDIM(dst) == PyArray_NDIM(src) && |
| 2592 | PyArray_CompareLists(PyArray_DIMS(dst), PyArray_DIMS(src), |
| 2593 | PyArray_NDIM(dst))) { |
| 2594 | return PyArray_CopyInto(dst, src); |
| 2595 | } |
| 2596 | |
| 2597 | dst_size = PyArray_SIZE(dst); |
| 2598 | src_size = PyArray_SIZE(src); |
| 2599 | if (dst_size != src_size) { |
| 2600 | PyErr_Format(PyExc_ValueError, |
| 2601 | "cannot copy from array of size %" NPY_INTP_FMT " into an array " |
| 2602 | "of size %" NPY_INTP_FMT, src_size, dst_size); |
| 2603 | return -1; |
| 2604 | } |
| 2605 | |
| 2606 | /* Zero-sized arrays require nothing be done */ |
| 2607 | if (dst_size == 0) { |
| 2608 | return 0; |
| 2609 | } |
| 2610 | |
| 2611 | baseflags = NPY_ITER_EXTERNAL_LOOP | |
| 2612 | NPY_ITER_DONT_NEGATE_STRIDES | |
| 2613 | NPY_ITER_REFS_OK; |
| 2614 | |
| 2615 | /* |
| 2616 | * This copy is based on matching C-order traversals of src and dst. |
| 2617 | * By using two iterators, we can find maximal sub-chunks that |
| 2618 | * can be processed at once. |
| 2619 | */ |
| 2620 | dst_iter = NpyIter_New(dst, NPY_ITER_WRITEONLY | baseflags, |
| 2621 | order, |
| 2622 | NPY_NO_CASTING, |
no test coverage detected