# Path: autograd/util.py
# def subvals(x, ivs):
#     x_ = list(x)
#     for i, v in ivs:
#         x_[i] = v
#     return tuple(x_)
# 
# def toposort(end_node, parents=operator.attrgetter('parents')):
#     child_counts = {}
#     stack = [end_node]
#     while stack:
#         node = stack.pop()
#         if node in child_counts:
#             child_counts[node] += 1
#         else:
#             child_counts[node] = 1
#             stack.extend(parents(node))
# 
#     childless_nodes = [end_node]
#     while childless_nodes:
#         node = childless_nodes.pop()
#         yield node
#         for parent in parents(node):
#             if child_counts[parent] == 1:
#                 childless_nodes.append(parent)
#             else:
#                 child_counts[parent] -= 1


import warnings
from contextlib import contextmanager
from collections import defaultdict
from .util import subvals, toposort
from .wrap_util import wraps
        start_box = new_box(x, t, start_node)
        end_box = fun(start_box)
        if isbox(end_box) and end_box._trace == start_box._trace:
            return end_box._value, end_box._node
        else:
            warnings.warn("Output seems independent of input.")
            return end_box, None

class Node(object):
    __slots__ = []
    def __init__(self, value, fun, args, kwargs, parent_argnums, parents):
        assert False

    def initialize_root(self, *args, **kwargs):
        assert False

    @classmethod
    def new_root(cls, *args, **kwargs):
        root = cls.__new__(cls)
        root.initialize_root(*args, **kwargs)
        return root

def primitive(f_raw):
    """
    Wraps a function so that its gradient can be specified and its invocation
    can be recorded. For examples, see the docs."""
    @wraps(f_raw)
    def f_wrapped(*args, **kwargs):
        boxed_args, trace, node_constructor = find_top_boxed_args(args)
        if boxed_args:

# Path: autograd/util.py
# def subvals(x, ivs):
#     x_ = list(x)
#     for i, v in ivs:
#         x_[i] = v
#     return tuple(x_)
# 
# def toposort(end_node, parents=operator.attrgetter('parents')):
#     child_counts = {}
#     stack = [end_node]
#     while stack:
#         node = stack.pop()
#         if node in child_counts:
#             child_counts[node] += 1
#         else:
#             child_counts[node] = 1
#             stack.extend(parents(node))
# 
#     childless_nodes = [end_node]
#     while childless_nodes:
#         node = childless_nodes.pop()
#         yield node
#         for parent in parents(node):
#             if child_counts[parent] == 1:
#                 childless_nodes.append(parent)
#             else:
#                 child_counts[parent] -= 1


# Path: autograd/tracer.py
import warnings
from contextlib import contextmanager
from collections import defaultdict
from .util import subvals, toposort
from .wrap_util import wraps

        start_box = new_box(x, t, start_node)
        end_box = fun(start_box)
        if isbox(end_box) and end_box._trace == start_box._trace:
            return end_box._value, end_box._node
        else:
            warnings.warn("Output seems independent of input.")
            return end_box, None

class Node(object):
    __slots__ = []
    def __init__(self, value, fun, args, kwargs, parent_argnums, parents):
        assert False

    def initialize_root(self, *args, **kwargs):
        assert False

    @classmethod
    def new_root(cls, *args, **kwargs):
        root = cls.__new__(cls)
        root.initialize_root(*args, **kwargs)
        return root

def primitive(f_raw):
    """
    Wraps a function so that its gradient can be specified and its invocation
    can be recorded. For examples, see the docs."""
    @wraps(f_raw)
    def f_wrapped(*args, **kwargs):
        boxed_args, trace, node_constructor = find_top_boxed_args(args)
        if boxed_args:

            argvals = subvals(args, [(argnum, box._value) for argnum, box in boxed_args])