guan404ming commented on code in PR #690:
URL: https://github.com/apache/mahout/pull/690#discussion_r2596274841
##########
qdp/qdp-core/src/gpu/encodings/amplitude.rs:
##########
@@ -121,6 +122,130 @@ impl QuantumEncoder for AmplitudeEncoder {
fn description(&self) -> &'static str {
"Amplitude encoding with L2 normalization"
}
+
+ /// Override to avoid intermediate Vec allocation. Processes chunks
directly to GPU offsets.
+ fn encode_chunked(
+ &self,
+ device: &Arc<CudaDevice>,
+ chunks: &[Float64Array],
+ num_qubits: usize,
+ ) -> Result<GpuStateVector> {
+ #[cfg(target_os = "linux")]
+ {
+ let total_len: usize = chunks.iter().map(|c| c.len()).sum();
+ let state_len = 1 << num_qubits;
+
+ if total_len == 0 {
+ return Err(MahoutError::InvalidInput("Input chunks cannot be
empty".to_string()));
+ }
+ if total_len > state_len {
+ return Err(MahoutError::InvalidInput(
+ format!("Total data length {} exceeds state vector size
{}", total_len, state_len)
+ ));
+ }
+ if num_qubits == 0 || num_qubits > 30 {
Review Comment:
Sure, feel free to add it in follow up.
--
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]