8000 Make AdvancedNew iter more 0-d aware by seberg · Pull Request #3104 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Make AdvancedNew iter more 0-d aware #3104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/release/1.8.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ compiler, then it's possible you will encounter problems. If so, please
file a bug and as a temporary workaround you can re-enable the old build
system by exporting the shell variable NPY_SEPARATE_COMPILATION=0.

For the AdvancedNew iterator the ``oa_ndim`` flag should now be -1 to indicate
that no ``op_axes`` and ``itershape`` are passed in. The ``oa_ndim == 0``
case, now indicates a 0-D iteration and ``op_axes`` being NULL and the old
usage is deprecated. This does not effect the ``NpyIter_New`` or
``NpyIter_MultiNew`` functions.


New features
============

Expand Down
11 changes: 8 additions & 3 deletions doc/source/reference/c-api.iterator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@ Construction and Destruction
Extends :cfunc:`NpyIter_MultiNew` with several advanced options providing
more control over broadcasting and buffering.

If 0/NULL values are passed to ``oa_ndim``, ``op_axes``, ``itershape``,
If -1/NULL values are passed to ``oa_ndim``, ``op_axes``, ``itershape``,
and ``buffersize``, it is equivalent to :cfunc:`NpyIter_MultiNew`.

The parameter ``oa_ndim``, when non-zero, specifies the number of
The parameter ``oa_ndim``, when not zero or -1, specifies the number of
dimensions that will be iterated with customized broadcasting.
If it is provided, ``op_axes`` and/or ``itershape`` must also be provided.
If it is provided, ``op_axes`` must and ``itershape`` can also be provided.
The ``op_axes`` parameter let you control in detail how the
axes of the operand arrays get matched together and iterated.
In ``op_axes``, you must provide an array of ``nop`` pointers
Expand All @@ -649,6 +649,11 @@ Construction and Destruction
-1 which means ``newaxis``. Within each ``op_axes[j]`` array, axes
may not be repeated. The following example is how normal broadcasting
applies to a 3-D array, a 2-D array, a 1-D array and a scalar.

**Note**: Before NumPy 1.8 ``oa_ndim == 0` was used for signalling that
that ``op_axes`` and ``itershape`` are unused. This is deprecated and
should be replaced with -1. Better backward compatibility may be
achieved by using :cfunc:`NpyIter_MultiNew` for this case.

.. code-block:: c

Expand Down
15 changes: 9 additions & 6 deletions numpy/core/src/multiarray/nditer_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,10 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis)
axisdata = NIT_INDEX_AXISDATA(axisdata_del, 1);
memmove(axisdata_del, axisdata, (ndim-1-xdim)*sizeof_axisdata);

/* If there is more than one dimension, shrink the iterator */
if (ndim > 1) {
NIT_NDIM(iter) = ndim-1;
}
/* Otherwise convert it to a singleton dimension */
else {
/* Shrink the iterator */
NIT_NDIM(iter) = ndim - 1;
/* If it is now 0-d fill the singleton dimension */
if (ndim == 1) {
npy_intp *strides = NAD_STRIDES(axisdata_del);
NAD_SHAPE(axisdata_del) = 1;
for (iop = 0; iop < nop; ++iop) {
Expand Down Expand Up @@ -642,6 +640,9 @@ NpyIter_GetIterIndex(NpyIter *iter)
npy_intp sizeof_axisdata;

iterindex = 0;
if (ndim == 0) {
return 0;
}
sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
axisdata = NIT_INDEX_AXISDATA(NIT_AXISDATA(iter), ndim-1);

Expand Down Expand Up @@ -1750,6 +1751,8 @@ npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex)

NIT_ITERINDEX(iter) = iterindex;

ndim = ndim ? ndim : 1;

if (iterindex == 0) {
dataptr = NIT_RESETDATAPTR(iter);

Expand Down
Loading
0