You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by "rich7420 (via GitHub)" <gi...@apache.org> on 2026/04/19 09:39:19 UTC
Re: [PR] feat: Add float32 zero-copy angle encoding in Python bindings (single sample) [mahout]
rich7420 commented on code in PR #1264:
URL: https://github.com/apache/mahout/pull/1264#discussion_r3106585096
##########
qdp/qdp-python/src/engine.rs:
##########
@@ -522,6 +541,12 @@ impl QdpEngine {
})
}
2 => {
+ if method.as_str() == "angle" {
+ return Err(PyRuntimeError::new_err(
+ "CUDA tensor float32 angle encoding currently supports only 1D single-sample tensors. \
+ Use tensor.to(torch.float64) for batch angle encoding.",
+ ));
+ }
Review Comment:
validate_cuda_tensor_for_encoding in pytorch.rs already rejects 2D F32 angle tensors before
_encode_from_cuda_tensor is ever called. So the check here , it seems unreachable
plz correct me if i'm wrong.
##########
qdp/qdp-python/src/engine.rs:
##########
@@ -504,16 +508,31 @@ impl QdpEngine {
let data_ptr = data_ptr_u64 as *const f32;
let ptr = unsafe {
- self.engine
- .encode_from_gpu_ptr_f32_with_stream(
- data_ptr, input_len, num_qubits, stream_ptr,
- )
- .map_err(|e| {
- PyRuntimeError::new_err(format!(
- "Encoding failed (float32 amplitude): {}",
- e
- ))
- })?
+ match method.as_str() {
+ "amplitude" => self
+ .engine
+ .encode_from_gpu_ptr_f32_with_stream(
+ data_ptr, input_len, num_qubits, stream_ptr,
+ )
+ .map_err(|e| {
+ PyRuntimeError::new_err(format!(
+ "Encoding failed (float32 amplitude): {}",
+ e
+ ))
+ })?,
+ "angle" => self
+ .engine
+ .encode_angle_from_gpu_ptr_f32_with_stream(
+ data_ptr, input_len, num_qubits, stream_ptr,
+ )
+ .map_err(|e| {
+ PyRuntimeError::new_err(format!(
+ "Encoding failed (float32 angle): {}",
+ e
+ ))
+ })?,
+ _ => unreachable!("matches!() should have limited f32 methods"),
Review Comment:
just a nits: The panic message references the internal matches!() macro. Something like "unreachable: unhandled f32 encodin method" is clearer.
--
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: commits-unsubscribe@mahout.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org