示例#1
0
 def map_call_symbols(self, symbol_map):
     safe_sub_map = itemmap(tupfun(safe_symbol, safe_symbol), symbol_map)
     symbol_map_ = fallback(safe_sub_map.__getitem__,
                            identity,
                            exception_type=KeyError)
     symbol_tup_map = compose(tuple, curry(map)(symbol_map_))
     return tuple(
         map(tupfun(symbol_tup_map, tupfun(identity, symbol_tup_map)),
             self.calls))
示例#2
0
 def __init__(self, inputs, calls, outputs, origin=None):
     '''
     A Function represents a function in the computational sense.  Function objects are the 
     intermediary between fitted estimators and generated code.  Adapters return Function 
     objects, and sklearn2code converts Function objects into working code.  A Function object
     is composed of Expression objects (including Variable objects) and other Function objects.  
     It knows its inputs (Variable objects), its internal calls (made up of Variable objects 
     and other Function objects), and its outputs (general Expression objects).  
     
     Parameters
     ----------
     inputs : tuple of Variables
         The input variables for this function.
     
     calls : tuple of pairs with (tuples of Variables, pairs of Function objects and tuples of their inputs)
         The values are other function calls made by this function.  The keys are 
         variables to which the outputs are assigned.  The number of output variables in the
         key must match the number of outputs in the Function.  The length of the tuple of inputs must match the
         number of inputs for the function.  Also, no two keys may contain 
         the same variable.  These constraints are checked.
         
     outputs : tuple of expressions
         The actual calculations made by this Function.  The return values of the function
         are the results of the computations expressed by the expressions.
     
     '''
     self.inputs = tuple(map(safe_symbol, tupify(inputs)))
     self.calls = tupsmap(
         1, tupfun(identity, compose(tuple,
                                     curry(map)(safe_symbol))),
         tupsmap(0, compose(tuple,
                            curry(map)(safe_symbol)), calls))
     self.outputs = tupify(outputs)
     self._validate()
示例#3
0
 def free_symbols(self):
     return reduce(
         __or__,
         map(
             compose(
                 curry(reduce)(__or__),
                 tupfun(
                     flip(getattr)('free_symbols'),
                     flip(getattr)('free_symbols'))),
             self.mapping.items())) | self.arg.free_symbols
示例#4
0
 def __init__(self, *pairs):
     self.pairs = tuple(pairs)
     ExprType = self.outtype
     if not all(
             map(
                 compose(
                     all,
                     tupfun(
                         flip(isinstance)(ExprType),
                         flip(isinstance)(BooleanExpression))),
                 self.pairs)):
         raise TypeError('Arguments to Piecewise have incorrect type.')
示例#5
0
 def subs(self, varmap):
     return self.__class__(mapping=itemmap(
         tupfun(methodcaller('subs', varmap=varmap),
                methodcaller('subs', varmap=varmap)), self.mapping),
                           arg=self.arg.subs(varmap))
示例#6
0
 def subs(self, varmap):
     return self.__class__(*(map(
         tupfun(methodcaller('subs', varmap), methodcaller('subs', varmap)),
         self.pairs)))
示例#7
0
 def map_output_symbols(self, symbol_map):
     safe_sub_map = itemmap(tupfun(safe_symbol, safe_symbol), symbol_map)
     return tuple(map(methodcaller('subs', safe_sub_map), self.outputs))
示例#8
0
 def map_input_symbols(self, symbol_map):
     safe_sub_map = itemmap(tupfun(safe_symbol, safe_symbol), symbol_map)
     symbol_map_ = fallback(safe_sub_map.__getitem__,
                            identity,
                            exception_type=KeyError)
     return tuple(map(symbol_map_, self.inputs))