jorisvandenbossche commented on code in PR #37533:
URL: https://github.com/apache/arrow/pull/37533#discussion_r1426941260


##########
python/pyarrow/array.pxi:
##########
@@ -3573,17 +3595,20 @@ class FixedShapeTensorArray(ExtensionArray):
           ]
         ]
         """
-        if not obj.flags["C_CONTIGUOUS"]:
-            raise ValueError('The data in the numpy array need to be in a 
single, '
-                             'C-style contiguous segment.')
+
+        permutation = (-np.array(obj.strides)).argsort()
+        if not permutation[0] == 0:
+            raise ValueError('First stride needs to be largest to ensure that '
+                             'individual tensor data is contiguous in memory.')
 
         arrow_type = from_numpy_dtype(obj.dtype)
-        shape = obj.shape[1:]
-        size = obj.size / obj.shape[0]
+        shape = np.take(obj.shape, permutation)
+        values = np.lib.stride_tricks.as_strided(
+            obj, shape=(obj.size,), strides=(obj.dtype.itemsize,))

Review Comment:
   In general it will make a copy when the memory layout changes, but by 
specifying `order="K"`, you say to use the original memory layout, which I 
think means it will always be zero-copy



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to