How to use the constructs.Condition function in constructs

To help you get started, we’ve selected a few constructs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bollu / polymage / sandbox / expression.py View on Github external
return True
                else:
                    return False
            elif(include_modulo and expr.op in ['%']):
                if (not (expr.right.has(constructs.Variable)) and \
                    not (expr.right.has(constructs.Parameter))):
                    return isAffine(expr.left, include_div, False)
                else:
                    return False
            else:
                return False
        else:
            return False
    elif (isinstance(expr, AbstractUnaryOpNode)):
        return isAffine(expr.child, include_div, include_modulo)
    elif (isinstance(expr, constructs.Condition)):
        return isAffine(expr.lhs, include_div, include_modulo) and \
               isAffine(expr.rhs, include_div, include_modulo)
    elif (isinstance(expr,
                     (constructs.Select, constructs.Cast, InbuiltFunction))):
        return False
    raise TypeError(type(expr))
github bollu / polymage / sandbox / expression.py View on Github external
affine *,/ affine = non-affine
    non-affine operand always results in a non-affine expression

    Divisions and modulo operators are considered affine if the appropriate
    option is specified.

    This function is meant to work on straight forward expressions it can be
    easily tricked into conservatively saying that the expression is not
    affine. For example -x^3 + x^3 will be non affine.

    Making the expression anaylsis more robust will require integration with
    a symbolic math package.
    """
    expr = Value.numericToValue(expr)
    assert(isinstance(expr, AbstractExpression)
           or isinstance(expr, constructs.Condition))
    if (isinstance(expr, Value)):
        return (expr.typ is Int) or (include_div and (expr.typ is Rational))
    elif (isinstance(expr, constructs.Variable)):
        return True
    elif (isinstance(expr, constructs.Reference)):
        return False
    elif (isinstance(expr, AbstractBinaryOpNode)):
        left_check = isAffine(expr.left, include_div, include_modulo)
        right_check = isAffine(expr.right, include_div, include_modulo)
        if (left_check and right_check):
            if (expr.op in ['+','-']):
                return True
            elif(expr.op in ['*']):
                if(not (expr.left.has(constructs.Variable) or \
                        expr.left.has(constructs.Parameter)) or \
                   not (expr.right.has(constructs.Variable) or \

constructs

A programming model for software-defined state

Apache-2.0
Latest version published 1 month ago

Package Health Score

94 / 100
Full package analysis