Skip to content

Commit

Permalink
Add: Comparison methods for Param
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Jun 14, 2024
1 parent 3406c8b commit 934b825
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions crates/circuit/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Param {
fn compare(one: &PyObject, other: &PyObject) -> bool {
Python::with_gil(|py| -> PyResult<bool> {
let other_bound = other.bind(py);
other_bound.eq(one)
Ok(other_bound.eq(one)? || other_bound.is(one))
})
.unwrap_or_default()
}
Expand All @@ -187,16 +187,11 @@ impl PartialEq for Param {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Param::Float(s), Param::Float(other)) => s == other,
(Param::Float(_), Param::ParameterExpression(_)) => false,
(Param::ParameterExpression(_), Param::Float(_)) => false,
(Param::ParameterExpression(s), Param::ParameterExpression(other)) => {
Self::compare(s, other)
(Param::ParameterExpression(one), Param::ParameterExpression(other)) => {
Self::compare(one, other)
}
(Param::ParameterExpression(_), Param::Obj(_)) => false,
(Param::Float(_), Param::Obj(_)) => false,
(Param::Obj(_), Param::ParameterExpression(_)) => false,
(Param::Obj(_), Param::Float(_)) => false,
(Param::Obj(one), Param::Obj(other)) => Self::compare(one, other),
_ => false,
}
}
}
Expand Down

0 comments on commit 934b825

Please sign in to comment.