nujo/autodiff/tensor.py
def backward(self, _debug=False) -> None:
        ''' It uses Breadth First Search to traverse the computation graph
        and compute the gradient for each differentiable Tensor in the graph.

        '''

        nodes_to_visit: List['Tensor'] = [self]
        if _debug:
            i = 1

        while nodes_to_visit:
            node = nodes_to_visit.pop()
            node.compute_grad()

            if _debug:
                nstr = f' [{i}]'
                node.name += nstr if nstr not in node.name else ''
                i += 1

            if node.creator:
                for child in node.creator.children:
                    # Avoid visiting the same node twice
                    if all(child is not node for node in nodes_to_visit):
                        nodes_to_visit.insert(0, child)
 It uses Breadth First Search to traverse the computation graph
        and compute the gradient for each differentiable Tensor in the graph.

        
It uses Breadth First Search to traverse the computation graph
and compute the gradient for each differentiable Tensor in the graph.
It uses Breadth First Search to traverse the computation graph and compute the gradient for each differentiable Tensor in the graph .
def backward(self, _debug=False) -> None:
        nodes_to_visit: List['Tensor'] = [self]
        if _debug:
            i = 1
        while nodes_to_visit:
            node = nodes_to_visit.pop()
            node.compute_grad()
            if _debug:
                nstr = f' [{i}]'
                node.name += nstr if nstr not in node.name else ''
                i += 1
            if node.creator:
                for child in node.creator.children:
                    if all(child is not node for node in nodes_to_visit):
                        nodes_to_visit.insert(0, child)
def backward ( self , _debug = False ) -> None : nodes_to_visit : List [ 'Tensor' ] = [ self ] if _debug : i = 1 while nodes_to_visit : node = nodes_to_visit . pop ( ) node . compute_grad ( ) if _debug : nstr = f' [{i}]' node . name += nstr if nstr not in node . name else '' i += 1 if node . creator : for child in node . creator . children : if all ( child is not node for node in nodes_to_visit ) : nodes_to_visit . insert ( 0 , child )
It uses Breadth First Search to traverse the computation graph
and compute the gradient for each differentiable Tensor in the graph.
It uses Breadth First Search to traverse the computation graph and compute the gradient for each differentiable Tensor in the graph .
''' It uses Breadth First Search to traverse the computation graph
        and compute the gradient for each differentiable Tensor in the graph.

        ''' # Avoid visiting the same node twice
self
_debug