예제 #1
0
def SampledFunction1D(axis=Axis(float), **kw_args):
    axis = parseAxisArg(axis)
    type = popkey(kw_args, "type", float)
    
    result = _SampledFunction1D(axis, type)
    result.__dict__.update(kw_args)

    return result
예제 #2
0
def integrate(function, *region, **kw_args):
    """Numerically integrate 'function'.

    Performs multidimensional numerical integration of 'function' over a
    rectangular integration 'region'.

    'function' -- A callable or expression.

    '*region' -- One-dimensional ranges specifying a rectangular
    integration region.  Each range is a tuple of the form '(var_name,
    lo, hi)', where 'var_name' is the name of the integration variable
    and 'lo' and 'hi' are 'float' values specifying the interval to
    integrate over.

    'accuracy' -- Specify the desired accuracy with this keyword
    argument.

    returns -- The integral value."""

    # If 'function' isn't already callable, treat it as an expression. 
    import hep.expr
    if not callable(function):
        function = hep.expr.asExpression(function)

    if hep.expr.isExpression(function) \
       and not hep.expr.isCompiledExpression(function):
        function = hep.expr.setTypesFixed(function, None, float)
        function = hep.expr.compile(function)

    accuracy = float(popkey(kw_args, "accuracy", 1e-8))
    if len(kw_args) > 0:
        raise TypeError, \
              "'integrate' got an unexpected keyword argument '%s'" \
              % kw_args.keys()[0]

    # Perform the integration.
    return ext.integrate(function, region, accuracy)
예제 #3
0
def Function1D(expr, arg_name=None, axis=Axis(float), **kw_args):
    """Create a function of a single argument.

    The function may be specified by an expression object or a string
    formula for one.  The expression must have exactly one symbol name
    appearing in it that does not match a keyword argument; this is
    argument name, and may be specified as 'arg_name'.

    'expr' -- The expression to evaluate the function.  May be an
    expression object, a string formula for an expression, or a
    a callable object.

    'arg_name' -- If 'expr' is an expression or string formula for one,
    the name of the argument variable.  It must be a symbol appearing in
    the expression.

    'axis' -- The axis object; or, a sequence of the form '(type, name,
    units, (lo, hi))', where items after 'type' may be omitted.

    '**kw_args' -- Keyword arguments whose names match symbols in the
    expression are interpreted as parameter values for those symbols.
    Any other keyword arguments are added as attributes to the resulting
    function object.

    returns -- A function object."""

    # Convert arguments appropriately.
    expr = hep.expr.asExpression(expr)
    axis = parseAxisArg(axis)
   
    # Make sure each of the symbols in the expression binds either to
    # the function argument or a value provided as a keyword argument.
    symbol_names = hep.expr.getSymbolNames(expr)
    parameters = {}
    for symbol_name in symbol_names:
        if symbol_name == arg_name:
            # It's the argument name.  That's fine.
            pass
        elif symbol_name in kw_args:
            # Its value was provided as a keyword argument.  Store it as
            # a parameter
            parameters[symbol_name] = popkey(kw_args, symbol_name)
        elif arg_name is None:
            # No argument name was specified.  Since we don't have a
            # value for this symbol name, optimistically assume that it
            # is the argument variable and hope that all other symbol
            # names are resolved.
            arg_name = symbol_name
        else:
            # Couldn't bind this symbol name.
            raise KeyError, \
                  "unknown symbol %s in expression" % symbol_name
    
    # Use the name of the argument variable as the axis name, if no
    # other was provided.
    if not hasattr(axis, "name"):
        axis.name = arg_name
    # Build the function.
    result = _Function1D(
        axis, expr, arg_name, parameters)
    # Set the function name.
    result.name = popkey(kw_args, "name", str(expr))
    # Set other attributes.
    result.__dict__.update(kw_args)
    # All done.
    return result
예제 #4
0
 def __init__(self, style):
     self.header = hep.popkey(style, "header", None)
     self.footer = hep.popkey(style, "footer", None)
     Figure.__init__(self, style)