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

Function npyiter_copy_from_buffers

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

* This gets called after the buffers have been exhausted, and * their data needs to be written back to the arrays. The multi-index * must be positioned for the beginning of the buffer. */

Source from the content-addressed store, hash-verified

1894 * must be positioned for the beginning of the buffer.
1895 */
1896NPY_NO_EXPORT int
1897npyiter_copy_from_buffers(NpyIter *iter)
1898{
1899 npy_uint32 itflags = NIT_ITFLAGS(iter);
1900 int ndim = NIT_NDIM(iter);
1901 int iop, nop = NIT_NOP(iter);
1902 int maskop = NIT_MASKOP(iter);
1903
1904 npyiter_opitflags *op_itflags = NIT_OPITFLAGS(iter);
1905 NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
1906 NpyIter_AxisData *axisdata = NIT_AXISDATA(iter),
1907 *reduce_outeraxisdata = NULL;
1908
1909 PyArray_Descr **dtypes = NIT_DTYPES(iter);
1910 npy_intp transfersize = NBF_SIZE(bufferdata);
1911 npy_intp *strides = NBF_STRIDES(bufferdata),
1912 *ad_strides = NAD_STRIDES(axisdata);
1913 npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
1914 char **ad_ptrs = NAD_PTRS(axisdata);
1915 char **buffers = NBF_BUFFERS(bufferdata);
1916 char *buffer;
1917
1918 npy_intp reduce_outerdim = 0;
1919 npy_intp *reduce_outerstrides = NULL;
1920
1921 npy_intp axisdata_incr = NIT_AXISDATA_SIZEOF(itflags, ndim, nop) /
1922 NPY_SIZEOF_INTP;
1923
1924 /* If we're past the end, nothing to copy */
1925 if (NBF_SIZE(bufferdata) == 0) {
1926 return 0;
1927 }
1928
1929 NPY_IT_DBG_PRINT("Iterator: Copying buffers to outputs\n");
1930
1931 if (itflags&NPY_ITFLAG_REDUCE) {
1932 reduce_outerdim = NBF_REDUCE_OUTERDIM(bufferdata);
1933 reduce_outerstrides = NBF_REDUCE_OUTERSTRIDES(bufferdata);
1934 reduce_outeraxisdata = NIT_INDEX_AXISDATA(axisdata, reduce_outerdim);
1935 transfersize *= NBF_REDUCE_OUTERSIZE(bufferdata);
1936 }
1937
1938 NpyIter_TransferInfo *transferinfo = NBF_TRANSFERINFO(bufferdata);
1939 for (iop = 0; iop < nop; ++iop) {
1940 buffer = buffers[iop];
1941 /*
1942 * Copy the data back to the arrays. If the type has refs,
1943 * this function moves them so the buffer's refs are released.
1944 *
1945 * The flag USINGBUFFER is set when the buffer was used, so
1946 * only copy back when this flag is on.
1947 */
1948 if ((transferinfo[iop].write.func != NULL) &&
1949 (op_itflags[iop]&NPY_OP_ITFLAG_USINGBUFFER)) {
1950 npy_intp op_transfersize;
1951
1952 npy_intp src_stride, *dst_strides, *dst_coords, *dst_shape;
1953 int ndim_transfer;

Callers 4

NpyIter_DeallocateFunction · 0.85
NpyIter_ResetFunction · 0.85
NpyIter_GotoIterIndexFunction · 0.85

Calls 1

funcMethod · 0.45

Tested by

no test coverage detected