Generate a callback for evaluating derivative of ``self.exprs``
517014
def get_dfdx_callback(self):
        
        dfdx_exprs = self.get_dfdx()
        if dfdx_exprs is False:
            return None
        return self._callback_factory(dfdx_exprs)
513258
def eval(self, exp):
    ""
    # todo: this needs an AST-assert that all BaseX descendants are being handled
    if isinstance(exp,sqparse2.BinX): return evalop(exp.op.op, *map(self.eval, (exp.left, exp.right)))
    elif isinstance(exp,sqparse2.UnX): return self.eval_unx(exp)
    elif isinstance(exp,sqparse2.NameX): return self.nix.rowget(self.tables,self.c_row,exp)
    elif isinstance(exp,sqparse2.AsterX): return sum(self.c_row,[]) # todo doc: how does this get disassembled by caller?
    elif isinstance(exp,sqparse2.ArrayLit): return map(self.eval,exp.vals)
    elif isinstance(exp,(sqparse2.Literal,sqparse2.ArrayLit)): return exp.toliteral()
    elif isinstance(exp,sqparse2.CommaX):
      # todo: think about getting rid of CommaX everywhere; it complicates syntax tree navigation.
      #   a lot of things that are CommaX now should become weval.Row.
      ret = []
      for child in exp.children:
        (ret.extend if starlike(child) else ret.append)(self.eval(child))
      return ret
    elif isinstance(exp,sqparse2.CallX): return self.eval_callx(exp)
    elif isinstance(exp,sqparse2.SelectX):
      raise NotImplementedError('subqueries should have been evaluated earlier') # todo: specific error class
    elif isinstance(exp,sqparse2.AttrX):return self.nix.rowget(self.tables,self.c_row,exp)
    elif isinstance(exp,sqparse2.CaseX):
      for case in exp.cases:
        if self.eval(case.when): return self.eval(case.then)
      return self.eval(exp.elsex)
    elif isinstance(exp,sqparse2.CastX):
      if exp.to_type.type.lower() in ('text','varchar'): return unicode(self.eval(exp.expr))
      else: raise NotImplementedError('unhandled_cast_type',exp.to_type)
    elif isinstance(exp,(int,basestring,float,type(None))):
      return exp # I think Table.insert is creating this in expand_row
    # todo: why tuple, list, dict below? throw some asserts in here and see where these are coming from.
    elif isinstance(exp,tuple): return tuple(map(self.eval, exp))
    elif isinstance(exp,list): return map(self.eval, exp)
    elif isinstance(exp,dict): return exp
    elif isinstance(exp,sqparse2.NullX): return None
    elif isinstance(exp,sqparse2.ReturnX):
      # todo: I think ReturnX is *always* CommaX now; revisit this
      ret=self.eval(exp.expr)
      print "warning: not sure what I'm doing here with cardinality tweak on CommaX"
      return [ret] if isinstance(exp.expr,(sqparse2.CommaX,sqparse2.AsterX)) else [[ret]] # todo: update parser so this is always * or a commalist
    elif isinstance(exp,sqparse2.AliasX): return self.eval(exp.name) # todo: rename AliasX 'name' to 'expr'
    else: raise NotImplementedError(type(exp), exp)
639318
def _make_eval_func(self, tensors, session, feed_dict, fetches,
                      callback=None):
    """"""
    if not isinstance(tensors, list):
      tensors = [tensors]
    num_tensors = len(tensors)

    def eval_func(x):
      """Function to evaluate a `Tensor`."""
      shapes = dict(zip(self._vars, self._var_shapes))
      augmented_feed_dict = {
          var: x[packing_slice].reshape(shapes[var])
          for var, packing_slice in zip(self._vars, self._packing_slices)
      }
      augmented_feed_dict.update(feed_dict)
      augmented_fetches = tensors + fetches

      augmented_fetch_vals = session.run(
          augmented_fetches, feed_dict=augmented_feed_dict)

      if callable(callback):
        callback(*augmented_fetch_vals[num_tensors:])

      return augmented_fetch_vals[:num_tensors]

    return eval_func
296831
def parse_expr(tokens, options):
    """"""
    seq = parse_seq(tokens, options)
    if tokens.current() != '|':
        return seq
    result = [Required(*seq)] if len(seq) > 1 else seq
    while tokens.current() == '|':
        tokens.move()
        seq = parse_seq(tokens, options)
        result += [Required(*seq)] if len(seq) > 1 else seq
    return [Either(*result)] if len(result) > 1 else result
1149532
function(expr, options) {
                    var ctx = expr;
                    expr = Mustache.resolve(expr);
                    if ( !! expr) {
                        return options.fn(ctx);
                    }
                }
1246039
def inspect
      expr = @expr || @unit.expr
      expr = (expr) ? ","+expr.inspect : ""
      sufx = (@@verbose_inspect) ? " "+@unit.inspect : ""
      self.class.to_s+"["+Unit::Utils.num_inspect(@value)+expr+"]"+sufx
    end
278608
def eval_formula(expr: str, dataframe=None, context=None):
    '''
    
    '''

    if context is None:
        dd = {}  # context dictionary
    elif isinstance(context, CalibrationDict):
        dd = context.flat.copy()
    else:
        dd = context.copy()

    # compat since normalize form for parameters doesn't match calib dict.
    for k in [*dd.keys()]:
        dd[stringify_symbol(k)] = dd[k]

    expr_ast = parse_string(expr).value
    variables = list_variables(expr_ast)
    nexpr = stringify(expr_ast)


    dd['log'] = log
    dd['exp'] = exp

    if dataframe is not None:

        import pandas as pd
        for (k, t) in variables:
            dd[stringify_symbol((k, t))] = dataframe[k].shift(t)
        dd['t_'] = pd.Series(dataframe.index, index=dataframe.index)

    expr = to_source(nexpr)

    res = eval(expr, dd)

    return res
937388
def evaluate_rule(self, rule, value, target):
        """"""
        def evaluate(expr):
            if expr in LOGICAL_OPERATORS.values():
                return expr
            rvalue = self.get_value_for_expr(expr, target)
            if rvalue is None:
                return False  # ignore this result
            return expr['op'](value, rvalue)

        evaluated = [evaluate(expr) for expr in rule['exprs']]
        while len(evaluated) > 1:
            lhs, logical_op, rhs = (evaluated.pop(0) for _ in range(3))
            evaluated.insert(0, logical_op(lhs, rhs))

        return evaluated[0]
359333
def normalize(expr):
    """"""
    args = [normalize(arg) for arg in expr.args]

    return type(expr)(expr.func, *args, start=expr.start, end=expr.end)
77843
def arithm_expr_eval(cell, expr):
    
    if isinstance(expr, tuple):
        (left, op, right) = expr
        lval = arithm_expr_eval(cell, left)
        rval = arithm_expr_eval(cell, right)
        if op == '+':
            return lval + rval
        if op == '-':
            return lval - rval
        if op == '*':
            return lval * rval
        if op == '/':
            return lval // rval
    elif isinstance(expr, int):
        return expr
    else:
        cell[expr] = arithm_expr_eval(cell, cell[expr])
        return cell[expr]
85812
def func(self, node):
        ''
        _, params, _, _, _, expr = node
        params = map(self.eval, params)
        def func(*args):
            env = dict(self.env.items() + zip(params, args))
            return Mini(env).eval(expr)
        return func
316500
def visit_FunctionDef(self, node):
        '''
        
        '''
        self.aliases = IntrinsicAliases.copy()

        self.aliases.update((f.name, {f})
                            for f in self.global_declarations.values())

        self.aliases.update((arg.id, {arg})
                            for arg in node.args.args)

        self.generic_visit(node)
        if Aliases.RetId in self.aliases:
            # parametrize the expression
            def parametrize(exp):
                # constant(?) or global -> no change
                if isinstance(exp, (ast.Index, Intrinsic, ast.FunctionDef)):
                    return lambda _: {exp}
                elif isinstance(exp, ContainerOf):
                    pcontainee = parametrize(exp.containee)
                    index = exp.index
                    return lambda args: {
                        ContainerOf(pc, index)
                        for pc in pcontainee(args)
                    }
                elif isinstance(exp, ast.Name):
                    try:
                        w = node.args.args.index(exp)

                        def return_alias(args):
                            if w < len(args):
                                return {args[w]}
                            else:
                                return {node.args.defaults[w - len(args)]}
                        return return_alias
                    except ValueError:
                        return lambda _: self.get_unbound_value_set()
                elif isinstance(exp, ast.Subscript):
                    values = parametrize(exp.value)
                    slices = parametrize(exp.slice)
                    return lambda args: {
                        ast.Subscript(value, slice, ast.Load())
                        for value in values(args)
                        for slice in slices(args)}
                else:
                    return lambda _: self.get_unbound_value_set()

            # this is a little tricky: for each returned alias,
            # parametrize builds a function that, given a list of args,
            # returns the alias
            # then as we may have multiple returned alias, we compute the union
            # of these returned aliases
            return_aliases = [parametrize(ret_alias)
                              for ret_alias
                              in self.aliases[Aliases.RetId]]

            def merge_return_aliases(args):
                merged_return_aliases = set()
                for return_alias in return_aliases:
                    merged_return_aliases.update(return_alias(args))
                return merged_return_aliases

            node.return_alias = merge_return_aliases
1031342
def create(cls, expr, binds):
        
        return cls(expr=expr, binds=binds, dtype=bool_dtype)
432817
def visit_expr(self, node, parent):
        """"""
        newnode = nodes.Expr(node.lineno, node.col_offset, parent)
        newnode.postinit(self.visit(node.value, newnode))
        return newnode
406540
def Nand(*xs, simplify=True):
    
    xs = [Expression.box(x).node for x in xs]
    y = exprnode.not_(exprnode.and_(*xs))
    if simplify:
        y = y.simplify()
    return _expr(y)
853706
def derivative(self,*args):
        '''
        
        '''
        if self.i_dim == 0:
            return np.ones_like(*args[0])
        else:
            return np.zeros_like(*args[0])
811968
def parse_expr(expr, local_dict=None):
    
    if local_dict is None:
        local_dict = {}
    if expr["type"] == "Add":
        return add([parse_expr(arg, local_dict) for arg in expr["args"]])
    elif expr["type"] == "Mul":
        return mul([parse_expr(arg, local_dict) for arg in expr["args"]])
    elif expr["type"] == "Pow":
        return Pow(parse_expr(arg, local_dict) for arg in expr["args"])
    elif expr["type"] == "Symbol":
        try:
            return local_dict[expr["name"]]
        except KeyError:
            return symbolics.Symbol(expr["name"])
    elif expr["type"] == "Number":
        return symbolics.sympify(expr["value"])
    else:
        raise NotImplementedError(expr["type"] + " is not implemented")