On Fri, Sep 11, 2015 at 3:20 PM Sebastian Berg <sebast...@sipsolutions.net>
wrote:

> On Fr, 2015-09-11 at 13:10 +0000, Daniel Manson wrote:
> > Originally posted as issue 6301 on github.
> >
> >
> > Presumably any block of code that modifies an ndarray's buffer is
> > wrapped in a (thread safe?) check of the writable flag. Would it be
> > possible to hold a counter rather than a simple bool flag and then
> > increment the counter whenever you test the flag? Hopefully this would
> > introduce only a tiny additional overhead, but would permit
> > pseudo-hashing to test whether a mutable array has changed since you
> > last encountered it.
> >
>
> Just a quick note. This is a bit more complex then it might appear. The
> reason being that when a view of the array is changed, you would have to
> "notify" the array itself that it has changed. So propagation from top
> to bottom does not seem straight forward to me. (the other way is fine,
> since on check you could check all parents, but you cannot check all
> children).
>

Actually not so much. Like the writable flag, you'd make the counter be a
per-buffer piece of information. Each array already has a pointer to the
array object that "owns" the buffer, so you'd just go there in one hop.
This does mean that modifying one view would affect the modified flag on
all views sharing the same buffer, whether there's data overlap or not, but
for caching purposes that's not so bad.

I think a more serious concern is that it may be customary to simply check
the writable flag by hand rather than calling an is_writable function, so
to make this idea work you'd have to change all code that checks the
writable flag, including user code. You'd also have to make sure that all
code that tries to write to an array really checks the writable flag.

Rather than making this happen for all arrays, does it make sense to use an
array subclass with a "dirty flag", maybe even if this requires manual
setting in some cases?

Anne
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to