Skip to content

Commit

Permalink
Avoid 'use'ing SliceOrInt enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Nov 1, 2023
1 parent c3e6b96 commit 2cf9a19
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/accelerate/src/quantum_circuit/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

use crate::quantum_circuit::circuit_data::SliceOrInt::{Int, Slice};
use crate::quantum_circuit::circuit_instruction::CircuitInstruction;
use crate::quantum_circuit::intern_context::{BitType, IndexType, InternContext};
use crate::quantum_circuit::py_ext;
Expand Down Expand Up @@ -233,14 +232,14 @@ impl CircuitData {

pub fn __delitem__(&mut self, py: Python<'_>, index: SliceOrInt) -> PyResult<()> {
match index {
Slice(slice) => {
SliceOrInt::Slice(slice) => {
let slice = self.convert_py_slice(py, slice)?;
for (i, x) in slice.into_iter().enumerate() {
self.__delitem__(py, Int(x - i as isize))?;
self.__delitem__(py, SliceOrInt::Int(x - i as isize))?;
}
Ok(())
}
Int(index) => {
SliceOrInt::Int(index) => {
let index = self.convert_py_index(index)?;
if self.data.get(index).is_some() {
self.data.remove(index);
Expand All @@ -262,7 +261,7 @@ impl CircuitData {
value: &PyAny,
) -> PyResult<()> {
match index {
Slice(slice) => {
SliceOrInt::Slice(slice) => {
let indices = slice.indices(self.data.len().try_into().unwrap())?;
let slice = self.convert_py_slice(py, slice)?;
let values = value.iter()?.collect::<PyResult<Vec<&PyAny>>>()?;
Expand All @@ -277,13 +276,13 @@ impl CircuitData {
let enumerated = zip(slice.iter(), values.iter());
for (i, v) in enumerated {
let v = v;
self.__setitem__(py, Int(*i), *v)?;
self.__setitem__(py, SliceOrInt::Int(*i), *v)?;
}

// Delete any extras.
if slice.len() >= values.len() {
for _ in 0..(slice.len() - values.len()) {
let res = self.__delitem__(py, Int(indices.stop - 1));
let res = self.__delitem__(py, SliceOrInt::Int(indices.stop - 1));
if res.is_err() {
// We're empty!
break;
Expand All @@ -299,7 +298,7 @@ impl CircuitData {

Ok(())
}
Int(index) => {
SliceOrInt::Int(index) => {
let index = self.convert_py_index(index)?;
let value: PyRef<CircuitInstruction> = value.extract()?;
let mut cached_entry = self.get_or_cache(py, value)?;
Expand Down

0 comments on commit 2cf9a19

Please sign in to comment.