Create new mapiter.
- NOTE: The outer iteration (and subspace if requested buffered) is
- created with DELAY_BUFALLOC. It must be reset before usage!
@param Index information filled by prepare_index. @param Number of indices (gotten through prepare_index). @param Kind of index (gotten through preprare_index). @param NpyIter flags for an extra array. If 0 assume that there is no
System Message: ERROR/3 (<string>
, line 10) Unexpected indentation.
<blockquote> extra operand. NPY_ITER_ALLOCATE can make sense here.</blockquote>
System Message: WARNING/2 (<string>
, line 11) Block quote ends without a blank line; unexpected unindent.
@param Array being indexed @param subspace (result of getting view for the indices) @param Subspace iterator flags can be used to enable buffering.
System Message: ERROR/3 (<string>
, line 14) Unexpected indentation.
<blockquote>
- NOTE: When no subspace is necessary, the extra operand will
- always be buffered! Buffering the subspace when not necessary is very slow when the subspace is small.
</blockquote>
System Message: WARNING/2 (<string>
, line 17) Block quote ends without a blank line; unexpected unindent.
@param Subspace operand flags (should just be 0 normally) @param Operand iteration flags for the extra operand, this must not be
System Message: ERROR/3 (<string>
, line 19) Unexpected indentation.
<blockquote> 0 if an extra operand should be used, otherwise it must be 0. Should be at least READONLY, WRITEONLY or READWRITE.</blockquote>
System Message: WARNING/2 (<string>
, line 21) Block quote ends without a blank line; unexpected unindent.
- @param Extra operand. For getmap, this would be the result, for setmap
- this would be the arrays to get from. Can be NULL, and will be allocated in that case. However, it matches the mapiter iteration, so you have to call MapIterSwapAxes(mit, &extra_op, 1) on it. The operand has no effect on the shape.
- @param Dtype for the extra operand, borrows the reference and must not
- be NULL (if extra_op_flags is not 0).
@return A new MapIter (PyObject
*) or NULL.
System Message: WARNING/2 (
<string>
, line 30);
backlink Inline emphasis start-string without end-string.
For shape reporting on error
create new MapIter object
set all attributes of mapiter to zero
The subspace, the part of the array which is not indexed by arrays, needs to be iterated when the size of the subspace is larger than 1. If it is one, it has only an effect on the result shape. (Optimizes for example np.newaxis usage)
Fill basic information about the mapiter
Set iteration information of the indexing arrays.
For MapIterArray, it is possible that there is no fancy index. to support this case, add a a dummy iterator. Since it is 0-d its transpose, etc. does not matter.
signal necessity to decref...
- Now there are two general cases how extra_op is used:
-
No subspace iteration is necessary, so the extra_op can be included into the index iterator (it will be buffered)
-
Subspace iteration is necessary, so the extra op is iterated independently, and the iteration order is fixed at C (could also use Fortran order if the array is Fortran order). In this case the subspace iterator is not buffered.
If subspace iteration is necessary and an extra_op was given, it may also be necessary to transpose the extra_op (or signal the transposing to the advanced iterator).
- If we have an extra_op given, need to prepare it.
-
Subclasses might mess with the shape, so need a baseclass
-
Need to make sure the shape is compatible
-
May need to remove leading 1s and transpose dimensions. Normal assignments allows broadcasting away leading 1s, but the transposing code does not like this.
Usual assignments allows removal of leading one dimensions. (or equivalently adding of one dimensions to the array being assigned to). To implement this, reshape the array.
If dimensions need to be prepended (and no swapaxis is needed), use op_axes after extra_op is allocated for sure.
We are not using the subspace, so its size is 1. All dimensions of the extra_op corresponding to the subspace must be equal to 1.
If subspace is not NULL, NpyIter cannot allocate extra_op for us. This is a bit of a kludge. A dummy iterator is created to find the correct output shape and stride permutation. TODO: This can at least partially be replaced, since the shape
System Message: ERROR/3 (<string>
, line 5) Unexpected indentation.
<blockquote> is found for broadcasting errors.</blockquote>
Create an iterator, just to broadcast the arrays?!
nditer allows itemsize with npy_intp type, so it works here, but it would not work directly, since elsize is limited to int.
Just use C-order strides (TODO: allow also F-order)
shape is set, and strides is set up to mit->nd, set rest
Allocate new array. Note: Always base class, because subclasses might mess with the shape.
The extra op is now either allocated, can be allocated by NpyIter (no subspace) or is not used at all.
Need to set the axis remapping for the extra_op. This needs to cause ignoring of subspace dimensions and prepending -1 for broadcasting.
(fills subspace dimensions too, but they are not unused)
- NOTE: If for some reason someone wishes to use REDUCE_OK, be
- careful and fix the error message replacement at the end.
For a single 1-d operand, guarantee iteration order (scipy used this). Note that subspace may be used.
If external array is iterated, and no subspace is needed
- NOTE: This small limitation should practically not matter.
- (replaces npyiter error)
Use the axis remapping
TODO: Maybe add test for the CORDER, and maybe also allow F
NpyIter cleanup and information:
We may be doing a cast for the buffer, and that may have failed
Get the allocated extra_op
If extra_op is being tracked but subspace is used, we need to create a dedicated iterator for the outer iteration of the extra operand.
Get the full dimension information
Calculate total size of the MapIter
Can now return early if no subspace is being used
Fill in the last bit of mapiter information needed
Now just need to create the correct subspace iterator.
We should iterate the extra_op as well
Buffering is never used here, but in case someone plugs it in somewhere else, set the type correctly then.
- NOTE: In this case, need to call PyErr_Occurred() after
- basepointer resetting (buffer allocation)
Check whether the operand could not be broadcast and replace the error in that case. This should however normally be found early with a direct goto to broadcast_error
(j < 0 is currently impossible, extra_op is reshaped)
extra_op cannot be broadcast to the indexing result
Report the shape of the original array if it exists
References PyArray_DIM.