clib.conversion: Remove the as_c_contiguous function and use np.ascontiguousarray instead#3492
clib.conversion: Remove the as_c_contiguous function and use np.ascontiguousarray instead#3492
Conversation
There was a problem hiding this comment.
This np.ascontiguousarray was available back in NumPy 1.13 (https://numpy.org/doc/1.13/reference/generated/numpy.ascontiguousarray.html) that was released on 8 Jun 2017 (and possibly earlier), just when Leo wrote this function in #100 😆
Ok with not having a deprecation cycle since there is a direct replacement. Also, I think this np.ascontiguousarray function supports the __array_function__ protocol which might help with interoperability with other array types.
The function was available even in NumPy v1.0 (https://github.com/numpy/numpy/blob/v1.0/numpy/core/numeric.py#L139). I guess Leo didn't know this function at that time, just like that I didn't know it until now. |
Description of proposed changes
np.ascontiguousarray does the same thing with the
as_c_contiguousfunction, and is even slightly faster (see the benchmarks below).This PR removes the
as_c_contiguousfunction (assuming that no one is using this non-public function so the function doesn't go inot a deprecation cycle) and usesnp.ascontiguousarrayinstead.Benchmarks:
For a small array:
For a large array: