fix_numpy1.24_PR17035
authorDebian Python Team <team+python@tracker.debian.org>
Thu, 19 Jan 2023 13:54:51 +0000 (13:54 +0000)
committerDrew Parsons <dparsons@debian.org>
Thu, 19 Jan 2023 13:54:51 +0000 (13:54 +0000)
===================================================================

Gbp-Pq: Name fix_numpy1.24_PR17035.patch

scipy/sparse/_sputils.py

index add718f2d7fa0cc713cd7c4b158a9a8f4a6b05c2..b7fb07297611a1ed41bf46da36c00b7424d29d0f 100644 (file)
@@ -11,7 +11,8 @@ __all__ = ['upcast', 'getdtype', 'getdata', 'isscalarlike', 'isintlike',
            'isshape', 'issequence', 'isdense', 'ismatrix', 'get_sum_dtype']
 
 supported_dtypes = [np.bool_, np.byte, np.ubyte, np.short, np.ushort, np.intc,
-                    np.uintc, np.int_, np.uint, np.longlong, np.ulonglong, np.single, np.double,
+                    np.uintc, np.int_, np.uint, np.longlong, np.ulonglong,
+                    np.single, np.double,
                     np.longdouble, np.csingle, np.cdouble, np.clongdouble]
 
 _upcast_memo = {}
@@ -89,7 +90,19 @@ def downcast_intp_index(arr):
 
 
 def to_native(A):
-    return np.asarray(A, dtype=A.dtype.newbyteorder('native'))
+    """
+    Ensure that the data type of the NumPy array `A` has native byte order.
+
+    `A` must be a NumPy array.  If the data type of `A` does not have native
+    byte order, a copy of `A` with a native byte order is returned. Otherwise
+    `A` is returned.
+    """
+    dt = A.dtype
+    if dt.isnative:
+        # Don't call `asarray()` if A is already native, to avoid unnecessarily
+        # creating a view of the input array.
+        return A
+    return np.asarray(A, dtype=dt.newbyteorder('native'))
 
 
 def getdtype(dtype, a=None, default=None):