-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
change updateifcopy semantics in nditer #9714
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
Comments
+1. The correct solution is to use |
@xoviat I don't see how |
Just from reading the documentation:
If we think about other Python iterators, |
The example is not a good one. Here is a better one:
The real issue is the nditer creation/destruction which uses a scratch buffer via UPDATEIFCOPY semantics. The operands have a different memory layout than the original array The scratch buffer is copied back to Alternatively we could deprecate this whole mess, under the assumption that no-one uses it. |
The assumption here is that |
Ah, nditer is unfortunately a much more subtle and complicated beast than a
regular iterator. And this isn't really about copy() anyway; that's just a
way of demonstrating the problem.
The problem here is that nditer assumes it can pass back an UPDATEIFCOPY
pseudo-view to python code, and that the writeback will be triggered
magically when that python code is done with it. This is fundamentally
broken on PyPy with it's delayed gc. That's what needs to be fixed somehow,
either by removing the functionality or by giving nditer a way to
explicitly trigger the writeback.
…On Nov 7, 2017 18:53, "xoviat" ***@***.***> wrote:
The assumption here is that nditer should have a .copy() method. But that
assumption isn't backed by any other examples in Python, so the question
is: why should the method exist? .copy() functionality is already
provided by Python itself with itertools.tee, and if that has a
performance penalty, there's nothing stopping implementations from
rewriting it in C or rpython.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9714 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAlOaCyKx9Raxwdrf0EkD88uwagykVKxks5s0PtygaJpZM4PcvdP>
.
|
So when we talk about "removing the functionality", we mean raising an error and requiring the user to make an iterable copy of their array themselves? Ie, they should write: a = arange(24, dtype='<i4').reshape(2, 3, 4)
cpy = ascontiguousarray(a)
i = nditer(cpy, ['buffered'], casting='unsafe',
op_dtypes='>f8', buffersize=5)
# do something here
a[...] = cpy I have only just learned about all of this. But personally the context-manager seems friendlier, and doesn't seem too hard to implement given you already wrote the C-api for all of this in |
pull request #9998 opened for comment and review |
pull request #10184 solves this issue via a third alternative, a python-level |
Closed by PR #9998 |
a continuation of issue #7054
pr #9639 starts deprecating the resolution of
UPDATEIFCOPY
semantics in ndarraydealloc
. Thenditer
class also uses theUPDATEIFCOPY
mechanism, whenever a read-write iterator is used or if theupdateifcopy
flag is explicitly set viaopflags
, leading to code like this::I can see two solutions to removing the need to do
i = None
to trigger the resolution of temporary data:I can issue a pull request for either option, which one is preferable? Once we have a resolution for this issue, we can enable the
DeprecationWarning
on any use ofUPDATEIFCOPY
in favor ofWRITEBACKIFCOPY
+ use ofPyArray_ResolveWritebackIfCopy
The text was updated successfully, but these errors were encountered: