The NumPy Fortran-ordering quiz

Travis Oliphant oliphant.travis at
Tue Oct 17 23:43:29 CDT 2006

>         You are right, it doesn't need to.   My check is not general
>         enough.
>         It can be challenging to come up with a general way to
>         differentiate the
>         view-vs-copy situation and I struggled with it.  In this case,
>         it's the
>         fact that while self->nd > 1, the other dimensions are only of
>         shape 1
>         and so don't really matter.   If you could come up with some
>         kind of
>         striding check that would distinguish the two cases, I would
>         appreciate it. 
>     I suppose the problem is mostly in discontiguous arrays. Hmmm...,
>     this isn't too different that reshaping the transpose.
>     a.reshape((m,n),order='F' ~ a.reshape((n,m)).T.reshape(m,n)

I just committed a change to the check-for-copy code to SVN.   A copy 
will occur if an actual reshaping is taking place that involves more 
than just adding or deleting ones from the old shape and if

1) self is not "single-segment".  Single-segment means either 
Fortran-order or C-order.  If we don't have a single-segment array, then 
we have to get a (Fortran or C-) contiguous buffer to do any reshaping 
(there may be special cases when it's possible, but I haven't figure 
them out...)

2) self is single-segment but self.squeeze().ndim > 1 and it is in the 
"wrong" order from what was requested in the order argument (i.e. self 
is in C-contiguous order but a Fortran-order reshape was requested or 
self is in F-contiguous order but a C-order reshape was requested).

If there are any cases satisfying these rules where a copy does not have 
to occur then let me know.


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list