<commit_before># (C) <NAME> and Carnegie Mellon University, 2016
#
# functions, which support evaluation and backprop
#

import sys
import logging
import copy

import opfunutil
import ops
import config
import mutil
import numpy

conf = config.Config()
conf.trace = False;         conf.help.trace =         "Print debug info during function eval"
conf.long_trace = False;    conf.help.long_trace =    "Print output of functions during eval - only for small tasks"

class Function(object):
    """The tensorlog representation of a function. This supports eval and
    evalGrad operations, and take a list of input values as the inputs.
    """
    

    def eval(self,db,values,pad):
        self._checkDuplications()
        if conf.trace:
            print "Invoking:\n%s" % "\n. . ".join(self.pprint())
        pad[self.id].output = self._doEval(db,values,pad)
        if conf.trace:
            print "Function completed:\n%s" % "\n. . ".join(self.pprint())
            if conf.long_trace:
                for k,v in enumerate(values):
                    print '. input',k+1,':',db.matrixAsSymbolDict(values[k])
                print '. result :',db.matrixAsSymbolDict(result)
        return pad[self.id].output

    def backprop(self,delta,gradAccum,pad):
        if conf.trace:
            print "Backprop:\n%s" % "\n. . ".join(self.pprint())
        pad[self.id].delta = self._doBackprop(delta,gradAccum,pad)
        if conf.trace:
            print "Backprop completed:\n%s" % "\n. . ".join(self.pprint())
        return pad[self.id].delta

    def _checkDuplications(self):
        """For debugging/testing - poke around for copies of the same function
        somewhere in the tree."""
        kids = self.children()
        for i in range(len(kids)):
            for j in range(i+1,len(kids)):
                assert not kids[i] is kids[j], "Matching values not permitted for kids[%d],kids[%d]" % (i,j)
        for f in kids:
            if isinstance(f,Function):
                f._checkDuplications()

    def install(self,nextId=1):
        """ Give a numeric id to each function in this tree, and all the<commit_msg>bug fix in tracing<commit_after># (C) <NAME> and Carnegie Mellon University, 2016
#
# functions, which support evaluation and backprop
#

import sys
import logging
import copy

import opfunutil
import ops
import config
import mutil
import numpy

conf = config.Config()
conf.trace = False;         conf.help.trace =         "Print debug info during function eval"
conf.long_trace = False;    conf.help.long_trace =    "Print output of functions during eval - only for small tasks"

class Function(object):
    """The tensorlog representation of a function. This supports eval and
    evalGrad operations, and take a list of input values as the inputs.
    """
    

    def eval(self,db,values,pad):
        self._checkDuplications()
        if conf.trace:
            print "Invoking:\n%s" % "\n. . ".join(self.pprint())
        pad[self.id].output = self._doEval(db,values,pad)
        if conf.trace:
            print "Function completed:\n%s" % "\n. . ".join(self.pprint())
            if conf.long_trace:
                for k,v in enumerate(values):
                    print '. input',k+1,':',db.matrixAsSymbolDict(values[k])
                print '. result :',db.matrixAsSymbolDict(pad[self.id].output)
        return pad[self.id].output

    def backprop(self,delta,gradAccum,pad):
        if conf.trace:
            print "Backprop:\n%s" % "\n. . ".join(self.pprint())
        pad[self.id].delta = self._doBackprop(delta,gradAccum,pad)
        if conf.trace:
            print "Backprop completed:\n%s" % "\n. . ".join(self.pprint())
        return pad[self.id].delta

    def _checkDuplications(self):
        """For debugging/testing - poke around for copies of the same function
        somewhere in the tree."""
        kids = self.children()
        for i in range(len(kids)):
            for j in range(i+1,len(kids)):
                assert not kids[i] is kids[j], "Matching values not permitted for kids[%d],kids[%d]" % (i,j)
        for f in kids:
            if isinstance(f,Function):
                f._checkDuplications()

    def install(self,nextId=1):
        """ Give a numeric id to each function in this tree, and all the
{'fraction_non_alphanumeric': 0.12102803738317756, 'fraction_numerical': 0.0032710280373831778, 'mean_word_length': 2.419329073482428, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4684836', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1249, 'n_words': 378}