[Numpy-discussion] Depreciating asfortranarray and ascontiguousarray

Joe Kington joferkington at gmail.com
Thu Oct 25 17:00:26 EDT 2018


For what it's worth, these are fairly widely used functions.  From a user
standpoint, I'd gently argue against deprecating them. Documenting the
inconsistency with scalars  seems like a less invasive approach.

In particular ascontiguousarray is a very common check to make when working
with C libraries or low-level file formats.  A significant advantage over
asarray(..., order='C') is readability.  It makes the intention very
clear.  Similarly, asfortranarray is quite readable for folks that aren't
deeply familiar with numpy.

Given that the use-cases they're primarily used for are likely to be read
by developers working in other languages (i.e. ascontiguousarray gets used
at a lot of "boundaries" with other systems), keeping function names that
make intention very clear is important.

Just my $0.02, anyway.  Cheers,
-Joe

On Thu, Oct 25, 2018 at 3:17 PM Alex Rogozhnikov <alex.rogozhnikov at yandex.ru>
wrote:

> Dear numpy community,
>
> I'm planning to depreciate np.asfortranarray and np.ascontiguousarray
> functions due to their misbehavior on scalar (0-D tensors) with PR #12244.
>
> Current behavior (converting scalars to 1-d array with single element)
> - is unexpected and contradicts to documentation
> - probably, can't be changed without breaking external code
> - I believe, this was a cause for poor support of 0-d arrays in mxnet.
> - both functions are easily replaced with asarray(..., order='...'), which
> has expected behavior
>
> There is no timeline for removal - we just need to discourage from using
> this functions in new code.
>
> Function naming may be related to how numpy treats 0-d tensors specially,
> and those probably should not be called arrays.
> https://www.numpy.org/neps/nep-0027-zero-rank-arrarys.html
> However, as a user I never thought about 0-d arrays being special and
> being "not arrays".
>
>
> Please see original discussion at github for more details
> https://github.com/numpy/numpy/issues/5300
>
> Your comments welcome,
> Alex Rogozhnikov
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20181025/aa8db7b6/attachment.html>


More information about the NumPy-Discussion mailing list