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

Function npyiter_copy_to_buffers

numpy/core/src/multiarray/nditer_api.c:2086–2600  ·  view source on GitHub ↗

* This gets called after the iterator has been positioned to a multi-index * for the start of a buffer. It decides which operands need a buffer, * and copies the data into the buffers. */

Source from the content-addressed store, hash-verified

2084 * and copies the data into the buffers.
2085 */
2086NPY_NO_EXPORT int
2087npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs)
2088{
2089 npy_uint32 itflags = NIT_ITFLAGS(iter);
2090 int ndim = NIT_NDIM(iter);
2091 int iop, nop = NIT_NOP(iter);
2092
2093 npyiter_opitflags *op_itflags = NIT_OPITFLAGS(iter);
2094 NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
2095 NpyIter_AxisData *axisdata = NIT_AXISDATA(iter),
2096 *reduce_outeraxisdata = NULL;
2097
2098 PyArray_Descr **dtypes = NIT_DTYPES(iter);
2099 PyArrayObject **operands = NIT_OPERANDS(iter);
2100 npy_intp *strides = NBF_STRIDES(bufferdata),
2101 *ad_strides = NAD_STRIDES(axisdata);
2102 npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
2103 char **ptrs = NBF_PTRS(bufferdata), **ad_ptrs = NAD_PTRS(axisdata);
2104 char **buffers = NBF_BUFFERS(bufferdata);
2105 npy_intp iterindex, iterend, transfersize,
2106 singlestridesize, reduce_innersize = 0, reduce_outerdim = 0;
2107 int is_onestride = 0, any_buffered = 0;
2108
2109 npy_intp *reduce_outerstrides = NULL;
2110 char **reduce_outerptrs = NULL;
2111
2112 /*
2113 * Have to get this flag before npyiter_checkreducesize sets
2114 * it for the next iteration.
2115 */
2116 npy_bool reuse_reduce_loops = (prev_dataptrs != NULL) &&
2117 ((itflags&NPY_ITFLAG_REUSE_REDUCE_LOOPS) != 0);
2118
2119 npy_intp axisdata_incr = NIT_AXISDATA_SIZEOF(itflags, ndim, nop) /
2120 NPY_SIZEOF_INTP;
2121
2122 NPY_IT_DBG_PRINT("Iterator: Copying inputs to buffers\n");
2123
2124 /* Calculate the size if using any buffers */
2125 iterindex = NIT_ITERINDEX(iter);
2126 iterend = NIT_ITEREND(iter);
2127 transfersize = NBF_BUFFERSIZE(bufferdata);
2128 if (transfersize > iterend - iterindex) {
2129 transfersize = iterend - iterindex;
2130 }
2131
2132 /* If last time around, the reduce loop structure was full, we reuse it */
2133 if (reuse_reduce_loops) {
2134 npy_intp full_transfersize, prev_reduce_outersize;
2135
2136 prev_reduce_outersize = NBF_REDUCE_OUTERSIZE(bufferdata);
2137 reduce_outerstrides = NBF_REDUCE_OUTERSTRIDES(bufferdata);
2138 reduce_outerptrs = NBF_REDUCE_OUTERPTRS(bufferdata);
2139 reduce_outerdim = NBF_REDUCE_OUTERDIM(bufferdata);
2140 reduce_outeraxisdata = NIT_INDEX_AXISDATA(axisdata, reduce_outerdim);
2141 reduce_innersize = NBF_SIZE(bufferdata);
2142 NBF_REDUCE_POS(bufferdata) = 0;
2143 /*

Callers 5

NpyIter_AdvancedNewFunction · 0.85
NpyIter_CopyFunction · 0.85
NpyIter_ResetFunction · 0.85
NpyIter_GotoIterIndexFunction · 0.85

Calls 3

NpyIter_GetIterSizeFunction · 0.85
npyiter_checkreducesizeFunction · 0.85
PyArray_DTYPEFunction · 0.85

Tested by

no test coverage detected