コード例 #1
0
 def newfunc(exprnode, indexedcols):
     result = getidxcmp(exprnode, indexedcols)
     if result[0] is not None:
         try:
             typeCompileAst(expressionToAST(exprnode))
         except NotImplementedError, nie:
             # Try to make this Numexpr error less cryptic.
             raise _unsupported_operation_error(nie)
コード例 #2
0
ファイル: _conditions_pro.py プロジェクト: dattatele/PyTables
 def newfunc(exprnode, indexedcols):
     result = getidxcmp(exprnode, indexedcols)
     if result[0] is not None:
         try:
             typeCompileAst(expressionToAST(exprnode))
         except NotImplementedError, nie:
             # Try to make this Numexpr error less cryptic.
             raise _unsupported_operation_error(nie)
コード例 #3
0
ファイル: conditions.py プロジェクト: dattatele/PyTables
def compile_condition(condition, typemap, indexedcols, copycols):
    """
    Compile a condition and extract usable index conditions.

    Looks for variable-constant comparisons in the `condition` string
    involving the indexed columns whose variable names appear in
    `indexedcols`.  The part of `condition` having usable indexes is
    returned as a compiled condition in a `CompiledCondition` container.

    Expressions such as '0 < c1 <= 1' do not work as expected.  The
    Numexpr types of *all* variables must be given in the `typemap`
    mapping.  The ``function`` of the resulting `CompiledCondition`
    instance is a Numexpr function object, and the ``parameters`` list
    indicates the order of its parameters.

    For columns whose variable names appear in `copycols`, an
    additional copy operation is inserted whenever the column is
    referenced.  This seems to accelerate access to unaligned,
    *unidimensional* arrays up to 2x (multidimensional arrays still
    need to be copied by `call_on_recarr()`.).
    """

    # Get the expression tree and extract index conditions.
    expr = stringToExpression(condition, typemap, {})
    if expr.astKind != 'bool':
        raise TypeError( "condition ``%s`` does not have a boolean type"
                         % condition )
    idxexprs = _get_idx_expr(expr, indexedcols)
    # Post-process the answer
    if type(idxexprs) == list:
        # Simple expression
        strexpr = ['e0']
    else:
        # Complex expression
        idxexprs, strexpr = idxexprs
    # Get rid of the unneccessary list wrapper for strexpr
    strexpr = strexpr[0]

    # Get the variable names used in the condition.
    # At the same time, build its signature.
    varnames = _get_variable_names(expr)
    signature = [(var, typemap[var]) for var in varnames]
    try:
        # See the comments in `numexpr.evaluate()` for the
        # reasons of inserting copy operators for unaligned,
        # *unidimensional* arrays.
        func = NumExpr(expr, signature, copy_args=copycols)
    except NotImplementedError, nie:
        # Try to make this Numexpr error less cryptic.
        raise _unsupported_operation_error(nie)