viiccwen commented on code in PR #1106:
URL: https://github.com/apache/mahout/pull/1106#discussion_r2874103097


##########
qdp/qdp-python/qumat_qdp/loader.py:
##########
@@ -254,6 +343,25 @@ def _create_iterator(self) -> Iterator[object]:
             )
         )
 
+    def _wrap_iterator(self, raw_iter: Iterator[object]) -> Iterator[Any]:
+        if self._output_format is None:
+            yield from raw_iter
+            return
+        kind = self._output_format[0]
+        if kind == "torch":
+            device = self._output_format[1]
+            for qt in raw_iter:
+                t = _torch.from_dlpack(qt)
+                yield t.cpu() if device == "cpu" else t
+        elif kind == "numpy":
+            for qt in raw_iter:
+                yield _torch.from_dlpack(qt).cpu().numpy()

Review Comment:
   `as_torch()` validates that `torch` is installed, but `as_numpy()` does not. 
Then `_wrap_iterator()` calls `_torch.from_dlpack(...)` for the `"numpy"` path.
   
   Does it mean `as_numpy()` can succeed at configuration time and then fail 
during iteration with an unclear runtime error if PyTorch is not installed. 🤔



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