This is an automated email from the ASF dual-hosted git repository.
400Ping pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git
The following commit(s) were added to refs/heads/main by this push:
new 359f9590d refactor(qdp): rename validate_tensor to validate_tensor_cpu
and drop redundant check (#1415)
359f9590d is described below
commit 359f9590de355afe44131250327d3df68993940c
Author: Ryan Huang <[email protected]>
AuthorDate: Fri Jul 3 13:17:15 2026 +0900
refactor(qdp): rename validate_tensor to validate_tensor_cpu and drop
redundant check (#1415)
---
qdp/qdp-python/src/engine.rs | 4 ++--
qdp/qdp-python/src/pytorch.rs | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/qdp/qdp-python/src/engine.rs b/qdp/qdp-python/src/engine.rs
index e3b9a9bd7..08288909d 100644
--- a/qdp/qdp-python/src/engine.rs
+++ b/qdp/qdp-python/src/engine.rs
@@ -16,7 +16,7 @@
use crate::pytorch::{
extract_cuda_tensor_info, get_torch_cuda_stream_ptr, is_cuda_tensor,
is_pytorch_tensor,
- validate_cuda_tensor_for_encoding, validate_shape, validate_tensor,
+ validate_cuda_tensor_for_encoding, validate_shape, validate_tensor_cpu,
};
use crate::tensor::QuantumTensor;
use numpy::{PyReadonlyArray1, PyReadonlyArray2, PyUntypedArrayMethods};
@@ -206,7 +206,7 @@ impl QdpEngine {
}
// CPU tensor path
- validate_tensor(data)?;
+ validate_tensor_cpu(data)?;
// PERF: Avoid Tensor -> Python list -> Vec deep copies.
//
// For CPU tensors, `tensor.detach().numpy()` returns a NumPy view
that shares the same
diff --git a/qdp/qdp-python/src/pytorch.rs b/qdp/qdp-python/src/pytorch.rs
index a46ae1df2..8181e551f 100644
--- a/qdp/qdp-python/src/pytorch.rs
+++ b/qdp/qdp-python/src/pytorch.rs
@@ -33,12 +33,12 @@ pub fn is_pytorch_tensor(obj: &Bound<'_, PyAny>) ->
PyResult<bool> {
Ok(module_name == "torch")
}
-/// Helper to validate CPU tensor
-pub fn validate_tensor(tensor: &Bound<'_, PyAny>) -> PyResult<()> {
- if !is_pytorch_tensor(tensor)? {
- return Err(PyRuntimeError::new_err("Object is not a PyTorch Tensor"));
- }
-
+/// Validate that a PyTorch tensor lives on the CPU.
+///
+/// The caller must have already confirmed `tensor` is a `torch.Tensor` (e.g.
+/// via [`is_pytorch_tensor`]). This function only checks device placement, so
+/// it also rejects non-CPU backends such as CUDA, MPS, XLA, and HPU.
+pub fn validate_tensor_cpu(tensor: &Bound<'_, PyAny>) -> PyResult<()> {
let device = tensor.getattr("device")?;
let device_type: String = device.getattr("type")?.extract()?;