Skip to content

Commit

Permalink
Switch to pre-allocated Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Nov 13, 2023
1 parent acfd538 commit 3e5f973
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/accelerate/src/sparse_pauli_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 3e5f973

Please sign in to comment.