[Numpy-discussion] Views of a different dtype
Sebastian Berg
sebastian at sipsolutions.net
Sat Jan 31 04:17:02 EST 2015
On Fr, 2015-01-30 at 19:52 -0800, Jaime Fernández del Río wrote:
> On Thu, Jan 29, 2015 at 8:57 AM, Nathaniel Smith <njs at pobox.com>
> wrote:
> On Thu, Jan 29, 2015 at 12:56 AM, Jaime Fernández del Río
> <jaime.frio at gmail.com> wrote:
> [...]
<snip>
>
> Could we make it more like: check to see if the last dimension
> works.
> If not, raise an error (and let the user transpose some other
> dimension there if that's what they wanted)? Or require the
> user to
> specify which dimension will absorb the shape change? (If we
> were
> doing this from scratch, then it would be tempting to just say
> that we
> always add a new dimension at the end with newtype.itemsize /
> oldtype.itemsize entries, or absorb such a dimension if
> shrinking. As
> a bonus, this would always work, regardless of contiguity!
> Except that
> when shrinking the last dimension would have to be contiguous,
> of
> course.)
>
>
> When we roll @ in and people start working with stacks of matrices, we
> will probably find ourselves having to create an alias, similar to .T,
> for .swapaxes(-1, -2). Searching for the smallest stride allows to
> take views of such arrays, which does not work right now because the
> array is no longer contiguous globally.
>
That is true, but I agree with Nathaniel at least as far as that I would
prefer a user to be able to safely use `view` even he has not even an
inkling about what his memory layout is. One option would be an
`axis=-1` default (maybe FutureWarn this from `axis=None` which would
look at order, see below -- or maybe have axis='A', 'C' and 'F' and
default to 'A' for starters).
This even now could start creating bugs when enabling relaxed
strides :(, because your good old fortran order complex array being
viewed as a float one could expand along the wrong axis, and even
without such arrays swap order pretty fast when operating on them, which
can create impossibly to find bugs, because even a poweruser is likely
to forget about such things.
Of course you could argue that view is a poweruser feature and a user
using it should keep these things in mind.... Though if you argue that,
you can almost just use `np.ndarray` directly ;) -- ok, not really
considering how cumbersome it is, but still.
- Sebastian
>
> I guess the main consideration for this is that we may be
> stuck with
> stuff b/c of backwards compatibility. Can you maybe say a
> little bit
> about what is allowed now, and what constraints that puts on
> things?
> E.g. are we already grovelling around in strides and picking
> random
> dimensions in some cases?
>
>
> Just to restate it: right now we only allow new views if the array is
> globally contiguous, so either along the first or last dimension.
>
>
> Jaime
>
>
> -n
>
> --
> Nathaniel J. Smith
> Postdoctoral researcher - Informatics - University of
> Edinburgh
> http://vorpus.org
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
>
>
> --
> (\__/)
> ( O.o)
> ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
> planes de dominación mundial.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150131/15f37743/attachment.sig>
More information about the NumPy-Discussion
mailing list