(func)
return memoizer
Memoize to avoid rebuilding of the gradient tree.

    Arguments:
        func (Function): Function to memoize.
Memoize to avoid rebuilding of the gradient tree.
Memoize to avoid rebuilding of the gradient tree .
def memoize_autodiff(func):
    """
    Memoize to avoid rebuilding of the gradient tree.

    Arguments:
        func (Function): Function to memoize.
    """
    cache = {}

    @wraps(func)
    def memoizer(op_tree, be, next_error=None):
        """
        If params in the caches, return results directly. Othewise, add to cache
        and return the results.

        Arguments:
            op_tree (OpTreeNode): the op-tree to supply to the func.
            be (Backend): computation backend to supply to the func.
            next_error (Tensor or OpTreeNode, optional): next layer's error to
                                                         supply to the func.
        """
        key = (op_tree.key(), be, next_error)
        if key not in cache:
            cache[key] = func(op_tree, be, next_error)
            # print 'created grad_tree cache'
        return cache[key]
    return memoizer
def memoize_autodiff ( func ) : cache = { } @ wraps ( func ) def memoizer ( op_tree , be , next_error = None ) : """
        If params in the caches, return results directly. Othewise, add to cache
        and return the results.

        Arguments:
            op_tree (OpTreeNode): the op-tree to supply to the func.
            be (Backend): computation backend to supply to the func.
            next_error (Tensor or OpTreeNode, optional): next layer's error to
                                                         supply to the func.
        """ key = ( op_tree . key ( ) , be , next_error ) if key not in cache : cache [ key ] = func ( op_tree , be , next_error ) # print 'created grad_tree cache' return cache [ key ] return memoizer