Professional Documents
Culture Documents
Ufuncs RST
Ufuncs RST
==================================
.. note::
This was implemented already, but the notes are kept here for historical
and explanatory purposes.
Right now, all data is copied into the buffers (even scalars are copied
multiple times into the buffers even if they are not going to be cast).
Also we only copy into output arrays if needed as well (other-wise the
output arrays are used directly in the ufunc code).
Call the function using the appropriate strides information from all the input
arrays. Only set the strides to the element-size for arrays that will be copied.
If N > B, then we have to do the above operation in a loop (with an extra loop
at the end with a different buffer size).
So, the code looks very similar to NOBUFFER_LOOP except the inner loop is
replaced with::
If there are object arrays involved then loop->obj gets set to 1. Then there are
two cases:
Inputs:
- castbuf starts as NULL and then gets filled with new references.
- function gets called and doesn't alter the reference count in castbuf
- on the next iteration (next value of k), the casting function will
DECREF what is present in castbuf already and place a new object.
- At the end of the inner loop (for loop over k), the final new-
references
in castbuf must be DECREF'd. If its a scalar then a single DECREF
suffices
Otherwise, "bufsize" DECREF's are needed (unless there was only one
loop, then "remainder" DECREF's are needed).
Outputs:
- castbuf contains a new reference as the result of the function call.
This
gets converted to the type of interest and. This new reference in
castbuf
will be DECREF'd by later calls to the function. Thus, only after the
inner most loop do we need to DECREF the remaining references in
castbuf.
Inputs:
Outputs:
- The buffer[i] memory receives the PyObject input after the cast.
This is
a new reference which will be "stolen" as it is copied over into
memory.
The only problem is that what is presently in memory must be DECREF'd
first.