def test_upcast_BinaryOp_nested_casting(): outer_expr = BinaryOp(op=ArithmeticOperator.ADD, left=A_BOOL_LITERAL, right=A_INT64_LITERAL) testee = BinaryOp(op=ArithmeticOperator.ADD, left=outer_expr, right=A_FLOAT64_LITERAL) expected = [ Cast(dtype=DataType.INT64, expr=A_BOOL_LITERAL), Cast(dtype=DataType.FLOAT64, expr=Placeholder()), ] upcast_and_validate(testee, expected)
def test_upcast_in_cond_of_TernaryOp(): testee = TernaryOp( cond=BinaryOp(op=ComparisonOperator.GE, left=A_INT64_LITERAL, right=A_FLOAT64_LITERAL), true_expr=AN_UNIMPORTANT_LITERAL, false_expr=AN_UNIMPORTANT_LITERAL, ) upcast_and_validate(testee, [Cast(dtype=DataType.FLOAT64, expr=A_INT64_LITERAL)])
ParAssignStmtBuilder("b") .right(FieldAccessBuilder("a").offset(CartesianOffset(i=1, j=0, k=0)).build()) .build() ) .add_stmt( ParAssignStmtBuilder("a").right(make_Literal("1.0", dtype=ARITHMETIC_TYPE)).build() ) .build(), # nested rhs lambda: VerticalLoopBuilder() .add_stmt( ParAssignStmtBuilder("b") .right( BinaryOp( op=A_ARITHMETIC_OPERATOR, left=FieldAccessBuilder("a").build(), right=FieldAccessBuilder("a").offset(CartesianOffset(i=1, j=0, k=0)).build(), ) ) .build() ) .add_stmt( ParAssignStmtBuilder("a").right(make_Literal("1.0", dtype=ARITHMETIC_TYPE)).build() ) .build(), # offset access in condition lambda: VerticalLoopBuilder() .add_stmt( FieldIfStmtBuilder() .cond( FieldAccessBuilder("a")
def test_upcast_BinaryOp_INT_to_FLOAT(): testee = BinaryOp(op=ArithmeticOperator.ADD, left=A_INT64_LITERAL, right=A_FLOAT64_LITERAL) upcast_and_validate(testee, [Cast(dtype=DataType.FLOAT64, expr=A_INT64_LITERAL)])