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

Function raw_array_assign_array

numpy/core/src/multiarray/array_assign_array.c:79–167  ·  view source on GitHub ↗

* Assigns the array from 'src' to 'dst'. The strides must already have * been broadcast. * * Returns 0 on success, -1 on failure. */

Source from the content-addressed store, hash-verified

77 * Returns 0 on success, -1 on failure.
78 */
79NPY_NO_EXPORT int
80raw_array_assign_array(int ndim, npy_intp const *shape,
81 PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
82 PyArray_Descr *src_dtype, char *src_data, npy_intp const *src_strides)
83{
84 int idim;
85 npy_intp shape_it[NPY_MAXDIMS];
86 npy_intp dst_strides_it[NPY_MAXDIMS];
87 npy_intp src_strides_it[NPY_MAXDIMS];
88 npy_intp coord[NPY_MAXDIMS];
89
90 int aligned;
91
92 NPY_BEGIN_THREADS_DEF;
93
94 aligned =
95 copycast_isaligned(ndim, shape, dst_dtype, dst_data, dst_strides) &&
96 copycast_isaligned(ndim, shape, src_dtype, src_data, src_strides);
97
98 /* Use raw iteration with no heap allocation */
99 if (PyArray_PrepareTwoRawArrayIter(
100 ndim, shape,
101 dst_data, dst_strides,
102 src_data, src_strides,
103 &ndim, shape_it,
104 &dst_data, dst_strides_it,
105 &src_data, src_strides_it) < 0) {
106 return -1;
107 }
108
109 /*
110 * Overlap check for the 1D case. Higher dimensional arrays and
111 * opposite strides cause a temporary copy before getting here.
112 */
113 if (ndim == 1 && src_data < dst_data &&
114 src_data + shape_it[0] * src_strides_it[0] > dst_data) {
115 src_data += (shape_it[0] - 1) * src_strides_it[0];
116 dst_data += (shape_it[0] - 1) * dst_strides_it[0];
117 src_strides_it[0] = -src_strides_it[0];
118 dst_strides_it[0] = -dst_strides_it[0];
119 }
120
121 /* Get the function to do the casting */
122 NPY_cast_info cast_info;
123 NPY_ARRAYMETHOD_FLAGS flags;
124 if (PyArray_GetDTypeTransferFunction(aligned,
125 src_strides_it[0], dst_strides_it[0],
126 src_dtype, dst_dtype,
127 0,
128 &cast_info, &flags) != NPY_SUCCEED) {
129 return -1;
130 }
131
132 if (!(flags & NPY_METH_NO_FLOATINGPOINT_ERRORS)) {
133 npy_clear_floatstatus_barrier((char*)&src_data);
134 }
135 if (!(flags & NPY_METH_REQUIRES_PYAPI)) {
136 NPY_BEGIN_THREADS;

Callers 1

PyArray_AssignArrayFunction · 0.85

Calls 8

copycast_isalignedFunction · 0.85
NPY_cast_info_xfreeFunction · 0.85
funcMethod · 0.45

Tested by

no test coverage detected