Python math.__dict__() Examples

The following are 11 code examples of math.__dict__(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module math , or try the search function .
Example #1
Source File: svgfig.py    From earthengine with MIT License 6 votes vote down vote up
def next(self):
      if not self.shown:
        self.shown = True
        if self.ti != ():
          return self.ti, self.svg

      if not isinstance(self.svg, SVG): raise StopIteration
      if self.depth_limit != None and len(self.ti) >= self.depth_limit: raise StopIteration

      if "iterators" not in self.__dict__:
        self.iterators = []
        for i, s in enumerate(self.svg.sub):
          self.iterators.append(self.__class__(s, self.ti + (i,), self.depth_limit))
        for k, s in self.svg.attr.items():
          self.iterators.append(self.__class__(s, self.ti + (k,), self.depth_limit))
        self.iterators = itertools.chain(*self.iterators)

      return self.iterators.next()
  ### end nested class 
Example #2
Source File: svgfig.py    From earthengine with MIT License 6 votes vote down vote up
def funcRtoC(expr, var="t", globals=None, locals=None):
  """Converts a complex "z(t)" string to a function acceptable for Curve.

  expr    required        string in the form "z(t)"
  var     default="t"   name of the independent variable
  globals default=None    dict of global variables used in the expression;
                          you may want to use Python's builtin globals()
  locals  default=None    dict of local variables
  """
  g = cmath.__dict__
  if globals != None: g.update(globals)
  output = eval("lambda %s: (%s)" % (var, expr), g, locals)
  split = lambda z: (z.real, z.imag)
  output2 = lambda t: split(output(t))
  output2.func_name = "%s -> %s" % (var, expr)
  return output2 
Example #3
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def set_axis_input(self, axis_id, axis_val):
        if axis_val == self.axes_values[axis_id]:
            return

        self.axes_values[axis_id] = axis_val

        if len(axis_val) == 0:
            self.axes_coords[axis_id] = None
            self.axes_eval_success[axis_id] = True
        else:
            try:
                #self.axes_coords[axis_id] = float(eval(axis_val, {}, {}))
                self.axes_coords[axis_id] = \
                    float(eval(axis_val, math.__dict__))
                self.axes_eval_success[axis_id] = True
            except:
                self.axes_eval_success[axis_id] = False 
Example #4
Source File: svgfig.py    From earthengine with MIT License 5 votes vote down vote up
def funcRtoR2(expr, var="t", globals=None, locals=None):
  """Converts a "f(t), g(t)" string to a function acceptable for Curve.

  expr    required        string in the form "f(t), g(t)"
  var     default="t"   name of the independent variable
  globals default=None    dict of global variables used in the expression;
                          you may want to use Python's builtin globals()
  locals  default=None    dict of local variables
  """
  g = math.__dict__
  if globals != None: g.update(globals)
  output = eval("lambda %s: (%s)" % (var, expr), g, locals)
  output.func_name = "%s -> %s" % (var, expr)
  return output 
Example #5
Source File: svgfig.py    From earthengine with MIT License 5 votes vote down vote up
def funcRtoR(expr, var="x", globals=None, locals=None):
  """Converts a "f(x)" string to a function acceptable for Curve.

  expr    required        string in the form "f(x)"
  var     default="x"   name of the independent variable
  globals default=None    dict of global variables used in the expression;
                          you may want to use Python's builtin globals()
  locals  default=None    dict of local variables
  """
  g = math.__dict__
  if globals != None: g.update(globals)
  output = eval("lambda %s: (%s, %s)" % (var, var, expr), g, locals)
  output.func_name = "%s -> %s" % (var, expr)
  return output 
Example #6
Source File: util.py    From histogrammar-python with Apache License 2.0 5 votes vote down vote up
def inheritdoc(cls):
    def _fn(fn):
        if fn.__name__ in cls.__dict__:
            fn.__doc__ = cls.__dict__[fn.__name__].__doc__
        return fn
    return _fn


################################################################ attach sub-methods to the fill and plot methods 
Example #7
Source File: sympy.py    From qupulse with MIT License 5 votes vote down vote up
def substitute_with_eval(expression: sympy.Expr,
                         substitutions: Dict[str, Union[sympy.Expr, numpy.ndarray, str]]) -> sympy.Expr:
    """Substitutes only sympy.Symbols. Workaround for numpy like array behaviour. ~Factor 3 slower compared to subs"""
    substitutions = {k: v if isinstance(v, sympy.Expr) else sympify(v)
                     for k, v in substitutions.items()}

    for symbol in get_free_symbols(expression):
        symbol_name = str(symbol)
        if symbol_name not in substitutions:
            substitutions[symbol_name] = symbol

    string_representation = sympy.srepr(expression)
    return eval(string_representation, sympy.__dict__, {'Symbol': substitutions.__getitem__,
                                                        'Mul': numpy_compatible_mul}) 
Example #8
Source File: util.py    From oamap with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def import_module(modulename):
        module = __import__(modulename)
        for name in modulename.split(".")[1:]:
            module = module.__dict__[name]
        return module 
Example #9
Source File: chisq.py    From pycbc with GNU General Public License v3.0 5 votes vote down vote up
def parse_option(row, arg):
        safe_dict = {}
        safe_dict.update(row.__dict__)
        safe_dict.update(math.__dict__)
        safe_dict.update(pycbc.pnutils.__dict__)
        return eval(arg, {"__builtins__":None}, safe_dict) 
Example #10
Source File: svgfig.py    From earthengine with MIT License 4 votes vote down vote up
def totrans(expr, vars=("x", "y"), globals=None, locals=None):
  """Converts to a coordinate transformation (a function that accepts
  two arguments and returns two values).

  expr       required                  a string expression or a function
                                       of two real or one complex value
  vars       default=("x", "y")    independent variable names;
                                       a singleton ("z",) is interpreted
                                       as complex
  globals    default=None              dict of global variables
  locals     default=None              dict of local variables
  """

  if callable(expr):
    if expr.func_code.co_argcount == 2:
      return expr

    elif expr.func_code.co_argcount == 1:
      split = lambda z: (z.real, z.imag)
      output = lambda x, y: split(expr(x + y*1j))
      output.func_name = expr.func_name
      return output

    else:
      raise TypeError, "must be a function of 2 or 1 variables"

  if len(vars) == 2:
    g = math.__dict__
    if globals != None: g.update(globals)
    output = eval("lambda %s, %s: (%s)" % (vars[0], vars[1], expr), g, locals)
    output.func_name = "%s,%s -> %s" % (vars[0], vars[1], expr)
    return output

  elif len(vars) == 1:
    g = cmath.__dict__
    if globals != None: g.update(globals)
    output = eval("lambda %s: (%s)" % (vars[0], expr), g, locals)
    split = lambda z: (z.real, z.imag)
    output2 = lambda x, y: split(output(x + y*1j))
    output2.func_name = "%s -> %s" % (vars[0], expr)
    return output2

  else:
    raise TypeError, "vars must have 2 or 1 elements" 
Example #11
Source File: util.py    From oamap with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def stringfcn(fcn):
    if isinstance(fcn, basestring):
        parsed = ast.parse(fcn).body
        if isinstance(parsed[-1], ast.Expr):
            parsed[-1] = ast.Return(parsed[-1].value)
            parsed[-1].lineno = parsed[-1].value.lineno
            parsed[-1].col_offset = parsed[-1].value.col_offset

        env = dict(math.__dict__)
        env.update(globals())

        free = set()
        defined = set(["None", "False", "True"])
        defined.update(env)
        def recurse(node):
            if isinstance(node, ast.Name):
                if isinstance(node.ctx, ast.Store):
                    defined.add(node.id)
                elif isinstance(node.ctx, ast.Load) and node.id not in defined:
                    free.add(node.id)
            elif isinstance(node, ast.AST):
                for n in node._fields:
                    recurse(getattr(node, n))
            elif isinstance(node, list):
                for x in node:
                    recurse(x)
        recurse(parsed)

        avoid = free.union(defined)
        fcnname = varname(avoid, "fcn")

        module = ast.parse("""
def {fcn}({params}):
    REPLACEME
""".format(fcn=fcnname, params=",".join(free)))
        module.body[0].body = parsed
        module = compile(module, "<fcn string>", "exec")

        doexec(module, env)
        fcn = env[fcnname]

    return fcn