Exemple #1
0
def __trig_param_array(som, param, trig_func):
    """
    This private function applies a trigonometric function to a given
    parameter obtained from the supplied object.

    @param som: The object containing the requested information.
    @type som: C{SOM.SOM}

    @param param: The name of the parameter to seek.
    @type param: C{string}

    @param trig_func: The name of the trigonometric function to apply.
    @type trig_func: C{string}
    

    @return: An array of trigonometry applied values from parameters from the
             incoming object.
    @rtype: C{list}   
    """
    import math

    len_som = hlr_utils.get_length(som)
    plist = []
    inst = som.attr_list.instrument

    tfunc = math.__getattribute__(trig_func)

    for i in xrange(len_som):
        plist.append(tfunc(hlr_utils.get_parameter(param, som[i], inst)[0]))

    return plist
Exemple #2
0
def __trig_param_array(som, param, trig_func):
    """
    This private function applies a trigonometric function to a given
    parameter obtained from the supplied object.

    @param som: The object containing the requested information.
    @type som: C{SOM.SOM}

    @param param: The name of the parameter to seek.
    @type param: C{string}

    @param trig_func: The name of the trigonometric function to apply.
    @type trig_func: C{string}
    

    @return: An array of trigonometry applied values from parameters from the
             incoming object.
    @rtype: C{list}   
    """
    import math
    len_som = hlr_utils.get_length(som)
    plist = []
    inst = som.attr_list.instrument

    tfunc = math.__getattribute__(trig_func)

    for i in xrange(len_som):
        plist.append(tfunc(hlr_utils.get_parameter(param, som[i], inst)[0]))

    return plist
Exemple #3
0
def math(n: Unit, fn: String, evaluator=None):
    """Apply Math ``fn`` to ``n``"""
    assert_type(n, "unit", "n")
    assert_string(fn, "fn")

    if fn.string == "round":
        return Unit(int(stilus_round(n.value)), n.type)

    return Unit(m.__getattribute__(fn.string)(n.value), n.type)
Exemple #4
0
def overload2(x,y,term):
    if isinstance(x,Node):
        return x.__getattribute__(term)(y)
    else:
        print(type(x))
        return math.__getattribute__(term)(x,y)
 def rslt(arg):
     if type(arg) == complex:
         return func(arg)
     else:
         return math.__getattribute__(func.__name__)(arg)
    return math.cosh(z.real)*math.cos(z.imag) + 1j*math.sinh(z.real)*math.sin(z.imag)

@extend_math_func
def sinh(z):
    return math.sinh(z.real)*math.cos(z.imag) + 1j*math.cosh(z.real)*math.sin(z.imag)

@extend_math_func
def tan(z):
    return sin(z)/cos(z)

@extend_math_func
def tanh(z):
    return sinh(z)/cosh(z)
        

functions = {name:math.__getattribute__(name) for name in tokens.func_names if name != 'abs'}
functions['abs'] = abs
functions['re'] = lambda c: c.real
functions['im'] = lambda c: c.imag
functions['sin'], functions['cos'], functions['exp'] = sin, cos, exp
functions['cosh'], functions['sinh'], functions['tan'], functions['tanh'] = cosh, sinh, tan, tanh

class expression_tree:
    def __init__(self, tkn, left=None, right=None):
        self.token = tkn
        self.left, self.right = left, right

    def __call__(self, **kwargs):
        if self.token.type == token.NUM:
            if self.token.is_complex():
                return complex(self.token)