rich7420 commented on code in PR #935:
URL: https://github.com/apache/mahout/pull/935#discussion_r2730143798


##########
qdp/qdp-python/src/lib.rs:
##########
@@ -318,6 +318,12 @@ fn extract_dlpack_tensor(_py: Python<'_>, tensor: 
&Bound<'_, PyAny>) -> PyResult
 
     unsafe {

Review Comment:
   I think this unsafe block is too large. Please try to add detailed safety 
comments or extract smaller, well-documented unsafe blocks.



##########
qdp/qdp-python/src/lib.rs:
##########
@@ -346,6 +382,38 @@ fn extract_dlpack_tensor(_py: Python<'_>, tensor: 
&Bound<'_, PyAny>) -> PyResult
             vec![]
         };
 
+        if ndim == 0 || shape.is_empty() {
+            return Err(PyRuntimeError::new_err(
+                "DLPack tensor must have at least 1 dimension",
+            ));
+        }
+
+        // Validate contiguous layout when strides are present
+        if !dl_tensor.strides.is_null() {
+            let strides = std::slice::from_raw_parts(dl_tensor.strides, ndim);
+            match ndim {
+                1 => {
+                    if strides[0] != 1 {
+                        return Err(PyRuntimeError::new_err(
+                            "DLPack tensor must be contiguous (stride != 1)",

Review Comment:
   nits: plz improve error message to include actual vs expected values.



-- 
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