MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_ConcatenateInto

Function PyArray_ConcatenateInto

numpy/core/src/multiarray/multiarraymodule.c:684–755  ·  view source on GitHub ↗

* Implementation for np.concatenate * * @param op Sequence of arrays to concatenate * @param axis Axis to concatenate along * @param ret output array to fill * @param dtype Forced output array dtype (cannot be combined with ret) * @param casting Casting mode used * @param casting_not_passed Deprecation helper */

Source from the content-addressed store, hash-verified

682 * @param casting_not_passed Deprecation helper
683 */
684NPY_NO_EXPORT PyObject *
685PyArray_ConcatenateInto(PyObject *op,
686 int axis, PyArrayObject *ret, PyArray_Descr *dtype,
687 NPY_CASTING casting, npy_bool casting_not_passed)
688{
689 int iarrays, narrays;
690 PyArrayObject **arrays;
691
692 if (!PySequence_Check(op)) {
693 PyErr_SetString(PyExc_TypeError,
694 "The first input argument needs to be a sequence");
695 return NULL;
696 }
697 if (ret != NULL && dtype != NULL) {
698 PyErr_SetString(PyExc_TypeError,
699 "concatenate() only takes `out` or `dtype` as an "
700 "argument, but both were provided.");
701 return NULL;
702 }
703
704 /* Convert the input list into arrays */
705 narrays = PySequence_Size(op);
706 if (narrays < 0) {
707 return NULL;
708 }
709 arrays = PyArray_malloc(narrays * sizeof(arrays[0]));
710 if (arrays == NULL) {
711 PyErr_NoMemory();
712 return NULL;
713 }
714 for (iarrays = 0; iarrays < narrays; ++iarrays) {
715 PyObject *item = PySequence_GetItem(op, iarrays);
716 if (item == NULL) {
717 narrays = iarrays;
718 goto fail;
719 }
720 arrays[iarrays] = (PyArrayObject *)PyArray_FROM_O(item);
721 if (arrays[iarrays] == NULL) {
722 Py_DECREF(item);
723 narrays = iarrays;
724 goto fail;
725 }
726 npy_mark_tmp_array_if_pyscalar(item, arrays[iarrays], NULL);
727 Py_DECREF(item);
728 }
729
730 if (axis >= NPY_MAXDIMS) {
731 ret = PyArray_ConcatenateFlattenedArrays(
732 narrays, arrays, NPY_CORDER, ret, dtype,
733 casting, casting_not_passed);
734 }
735 else {
736 ret = PyArray_ConcatenateArrays(
737 narrays, arrays, axis, ret, dtype, casting);
738 }
739
740 for (iarrays = 0; iarrays < narrays; ++iarrays) {
741 Py_DECREF(arrays[iarrays]);

Callers 2

PyArray_ConcatenateFunction · 0.85
array_concatenateFunction · 0.85

Tested by

no test coverage detected