rich7420 commented on code in PR #763:
URL: https://github.com/apache/mahout/pull/763#discussion_r2658939535
##########
qdp/qdp-python/src/lib.rs:
##########
@@ -215,6 +246,40 @@ impl QdpEngine {
})
}
+ /// Encode from PyTorch Tensor
+ ///
+ /// Args:
+ /// tensor: PyTorch Tensor (must be on CPU)
+ /// num_qubits: Number of qubits for encoding
+ /// encoding_method: Encoding strategy
+ ///
+ /// Returns:
+ /// QuantumTensor: DLPack-compatible tensor
+ fn encode_tensor(
+ &self,
+ tensor: &Bound<'_, PyAny>,
+ num_qubits: usize,
+ encoding_method: &str,
+ ) -> PyResult<QuantumTensor> {
+ validate_tensor(tensor)?;
+
+ // Convert to flat list for encoding
+ let data: Vec<f64> = tensor
+ .call_method0("flatten")?
+ .call_method0("tolist")?
+ .extract()?;
Review Comment:
It seems here do twice copy.
```
PyTorch tensor → Python list
Python list → Rust Vec<f64>
```
We should improve this in follow-up PR use like numpy() or
`PinnedHostBuffer` way to decrease memory copy time.
Please comments in this part.
--
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]