[Numpy-discussion] ZeroRank memmap behavior?
Sebastian Berg
sebastian at sipsolutions.net
Fri Sep 21 10:26:44 EDT 2012
Hey,
this is indirectly related (I think it might fix many of these memmap
oddities though?)...
Why does the memmap object not implement:
def __array_wrap__(self, obj):
if self is obj:
return obj
return np.array(obj, copy=False, subok=False)
By doing so if we have a ufunc with only memmap objects, the result will
not be a memmap object, but if the ufunc has an output parameter, then
"self is obj" which means that it is not casted. The problem is that
subclass automatically inherit an __array_wrap__ method that sets the
result to the subclasses type (which is not generally wanted for
memmaps). May make a PR for this...
Regards,
Sebastian
On Fri, 2012-09-21 at 14:59 +0200, Wim Bakker wrote:
> I'm deeply puzzled by the recently changed behavior of zero-rank
> memmaps. I think this change happened from version 1.6.0 to 1.6.1,
> which I'm currently using.
>
>
> >>> import numpy as np
>
>
> Create a zero-rank memmap.
>
>
> >>> x = np.memmap(filename='/tmp/m', dtype=float, mode='w+', shape=())
>
>
> Give it a value:
>
>
> >>> x[...] = 22
> >>> x
> memmap(22.0)
>
>
> So far so good. But now:
>
>
> >>> b = (x + x) / 1.5
> >>> b
> memmap(29.333333333333332)
>
>
> WT.? Why is the result of this calculation a memmap?
>
>
> It even thinks that it's still linked to the file, but it's not:
>
>
> >>> b.filename
> '/tmp/m'
>
>
> If I try this with arrays then I don't get this weird behavior:
>
>
> >>> a = np.array(2, dtype=float)
>
>
> >>> (a + a) / 2.5
> 1.6000000000000001
>
>
> which gives me a Python float, not a zero-rank array.
>
>
> Why does the memmap behave like that? Why do I get a memmap even
> though it's not connected to any file?
>
>
> Regards,
>
>
> Wim
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list