Skip to content

Commit

Permalink
Fix: Filter out rust native functions to match previous behavior.
Browse files Browse the repository at this point in the history
- The recently implemented rustwork-x core functions include the origin node and instances with no successors.
- Filter out those instances from the iterators.
  • Loading branch information
raynelfss committed Jul 2, 2024
1 parent 96c7873 commit e55d502
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/circuit/src/dag_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3595,18 +3595,18 @@ impl DAGCircuit {

/// Returns an iterator of the ancestors indices of a node.
pub fn ancestors<'a>(&'a self, node: NodeIndex) -> impl Iterator<Item = NodeIndex> + 'a {
core_ancestors(&self.dag, node)
core_ancestors(&self.dag, node).filter(move |next| next != &node)
}

/// Returns an iterator of the descendants of a node as DAGOpNodes and DAGOutNodes.
pub fn descendants<'a>(&'a self, node: NodeIndex) -> impl Iterator<Item= NodeIndex> + 'a {
core_descendants(&self.dag, node)
core_descendants(&self.dag, node).filter(move |next| next != &node)
}

/// Returns an iterator of tuples of (DAGNode, [DAGNodes]) where the DAGNode is the current node
/// and [DAGNode] is its successors in BFS order.
pub fn bfs_successors<'a>(&'a self, node: NodeIndex) -> impl Iterator<Item = (NodeIndex, Vec<NodeIndex>)> + 'a {
core_bfs_successors(&self.dag, node)
core_bfs_successors(&self.dag, node).filter(move |(_, others)| !others.is_empty())
}

fn unpack_into(&self, py: Python, id: NodeIndex, weight: &NodeType) -> PyResult<Py<PyAny>> {
Expand Down

0 comments on commit e55d502

Please sign in to comment.