[Numpy-discussion] Re: Switching default order to column-major
Hi, On Mon, Nov 13, 2023 at 7:41 AM Aaron Meurer wrote: > > High level abstractions like .flat or boolean indexing / np.nonzero() > always use C ordering regardless of the underlying data. > > >>> list(np.asarray([[0, 1], [2, 3]]).flat) > [0, 1, 2, 3] > >>> list(np.asarray([[0, 1], [2, 3]], order='F').flat) > [0, 1, 2, 3] Just in case it caused others to pause as it did me, here's the Boolean indexing demonstration: >>> c_arr = np.asarray([[0, 1], [2, 3]]) >>> f_arr = np.asarray([[0, 1], [2, 3]], order='F') >>> bool_arr = np.array([[False, True], [True, False]]) >>> c_arr[bool_arr] array([1, 2]) >>> f_arr[bool_arr] array([1, 2]) >>> c_arr[np.array(bool_arr, order='F')]. # Indexing array order is irrelevant array([1, 2]) >>> np.nonzero(c_arr < 3) (array([0, 0, 1]), array([0, 1, 0])) >>> np.nonzero(f_arr < 3) (array([0, 0, 1]), array([0, 1, 0])) Cheers, Matthew ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com
[Numpy-discussion] Re: Switching default order to column-major
Few things in the Python API care about order, but there are also quite a few places that will return C-order (and are faster for C-order inputs) whether you change those defaults or not. The main issue is that e.g. some cython wrappers will probably assume that the newly created array is C-order. And those will just not work. For example, I would imagine many libraries that have C/Cython wrappers have code that doesn't specify `order="C"` explicitly (why would they?) but then passes it into a typed memory-views (if cython) like `double[:, ::1]` enforcing a C-contiguous memory layout for speed. Such code should normally fail gracefully, but fail it will. Also, as Aaron said, a lot of these places might not enforce it but still be speed impacted. So yes, it would be expected break a lot of C-interfacing code that has Python wrappers around it to normalize input. - Sebastian On Fri, 2023-11-10 at 22:37 +, Valerio De Benedetto wrote: > Hi, I found that the documented default row-major order is enforced > throughout the library with a series of `order='C'` default > parameters, so given this I supposed there's no way to change the > default (or am I wrong?) > If, supposedly, I'd change that by patching the library (substituting > 'C's for 'F's), do you think there would by any problem with other > downstream libraries using numpy in my project? Do you think they > assume a default-constructed array is always row-major and access the > underlying data? > ___ > NumPy-Discussion mailing list -- numpy-discussion@python.org > To unsubscribe send an email to numpy-discussion-le...@python.org > https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ > Member address: sebast...@sipsolutions.net > ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com
[Numpy-discussion] next NumPy Newcomers' Hour - 10pm UTC
Our next Newcomers' Hour will be held this Thursday, November 16th at 10pm UTC. Stop by to ask questions, share your progress, celebrate success, or just to say hi. To add to the meeting agenda the topics you’d like to discuss, follow the link: https://hackmd.io/3f3otyyuTte3FU9y3QzsLg?both. Join the meeting via Zoom: https://us06web.zoom.us/j/82563808729?pwd=ZFU3Z2dMcXBGb05YemRsaGE1OW5nQT09. -- Cheers, Inessa Inessa Pawson GitHub: inessapawson ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com