diff --git a/crates/accelerate/src/sparse_pauli_op.rs b/crates/accelerate/src/sparse_pauli_op.rs index 4a4836ce69ab..68406bba234e 100644 --- a/crates/accelerate/src/sparse_pauli_op.rs +++ b/crates/accelerate/src/sparse_pauli_op.rs @@ -317,6 +317,9 @@ fn decompose_first_level( out_stack.push(PauliLocation::new(0, 0, 0)); } _ => { + unsafe { scratch.set_len(side * side) }; + let mut ptr = 0usize; + let cur_qubit = num_qubits - 1; let mid = 1 << cur_qubit; let loc = PauliLocation::new(0, 0, cur_qubit); @@ -344,7 +347,8 @@ fn decompose_first_level( let i_col = i_col_0 + off_col; let z_col = z_col_0 + off_col; let value = in_op[[i_row, i_col]] + in_op[[z_row, z_col]]; - scratch.push(value); + scratch[ptr] = value; + ptr += 1; i_nonzero = i_nonzero || (value != zero); } @@ -354,7 +358,8 @@ fn decompose_first_level( let x_col = x_col_0 + off_col; let y_col = y_col_0 + off_col; let value = in_op[[x_row, x_col]] + in_op[[y_row, y_col]]; - scratch.push(value); + scratch[ptr] = value; + ptr += 1; x_nonzero = x_nonzero || (value != zero); } } @@ -365,7 +370,8 @@ fn decompose_first_level( let x_col = x_col_0 + off_col; let y_col = y_col_0 + off_col; let value = in_op[[x_row, x_col]] - in_op[[y_row, y_col]]; - scratch.push(value); + scratch[ptr] = value; + ptr += 1; y_nonzero = y_nonzero || (value != zero); } let i_row = i_row_0 + off_row; @@ -374,7 +380,8 @@ fn decompose_first_level( let i_col = i_col_0 + off_col; let z_col = z_col_0 + off_col; let value = in_op[[i_row, i_col]] - in_op[[z_row, z_col]]; - scratch.push(value); + scratch[ptr] = value; + ptr += 1; z_nonzero = z_nonzero || (value != zero); } }