'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 = {}
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):