def test_resolve_AUTO_from_literal_to_temporary(): testee = (StencilBuilder().add_vertical_loop( VerticalLoopBuilder().add_temporary("tmp", DataType.AUTO).add_stmt( ParAssignStmt( left=FieldAccessBuilder("tmp").dtype(None).build(), right=Literal(value="0", dtype=A_ARITHMETIC_TYPE), )).build()).build()) resolve_dtype_and_validate(testee, {"tmp": A_ARITHMETIC_TYPE})
def copy_assign(): yield ParAssignStmt( loc=SourceLocation(line=3, column=2, source="copy_gtir"), left=FieldAccess.centered( name="a", loc=SourceLocation(line=3, column=1, source="copy_gtir") ), right=FieldAccess.centered( name="b", loc=SourceLocation(line=3, column=3, source="copy_gtir") ), )
def test_resolve_AUTO_from_FieldDecl_to_FieldAccess_to_temporary_to_FieldAccess_to_temporary( ): testee = (StencilBuilder().add_param( FieldDecl(name="field", dtype=A_ARITHMETIC_TYPE) ).add_vertical_loop(VerticalLoopBuilder().add_temporary( "tmp1", DataType.AUTO).add_temporary("tmp2", DataType.AUTO).add_stmt( ParAssignStmt( left=FieldAccessBuilder("tmp1").dtype(None).build(), right=FieldAccessBuilder("field").dtype(None).build(), )).add_stmt( ParAssignStmt( left=FieldAccessBuilder("tmp2").dtype(None).build(), right=FieldAccessBuilder("tmp1").dtype(None).build(), ), ).build()).build()) resolve_dtype_and_validate( testee, { "field": A_ARITHMETIC_TYPE, "tmp1": A_ARITHMETIC_TYPE, "tmp2": A_ARITHMETIC_TYPE })
def test_resolve_dtype_to_FieldAccess(): testee = (StencilBuilder().add_param( FieldDecl(name="field", dtype=A_ARITHMETIC_TYPE)).add_par_assign_stmt( ParAssignStmt( left=FieldAccessBuilder("field").dtype(None).build(), right=FieldAccessBuilder("field").dtype(None).build(), )).build()) resolve_dtype_and_validate( testee, {"field": A_ARITHMETIC_TYPE}, )
def build(self) -> ParAssignStmt: return ParAssignStmt(left=self._left, right=self._right)
def test_can_have_vertical_offset(): ParAssignStmt( left=FieldAccessBuilder("foo").offset(CartesianOffset(i=0, j=0, k=1)).build(), right=DummyExpr(), )
with pytest.raises(TypeError): invalid_node() def test_can_have_vertical_offset(): ParAssignStmt( left=FieldAccessBuilder("foo").offset(CartesianOffset(i=0, j=0, k=1)).build(), right=DummyExpr(), ) @pytest.mark.parametrize( "assign_stmt_with_offset", [ lambda: ParAssignStmt( left=FieldAccessBuilder("foo").offset(CartesianOffset(i=1, j=0, k=0)).build(), right=DummyExpr(), ), lambda: ParAssignStmt( left=FieldAccessBuilder("foo").offset(CartesianOffset(i=0, j=1, k=0)).build(), right=DummyExpr(), ), ], ) def test_no_horizontal_offset_allowed(assign_stmt_with_offset): with pytest.raises(ValidationError, match=r"must not have .*horizontal offset"): assign_stmt_with_offset() def test_symbolref_without_decl(): with pytest.raises(ValidationError, match=r"Symbols.*not found"): StencilBuilder().add_par_assign_stmt(
def test_upcast_ParAssignStmt(): testee = ParAssignStmt(left=FieldAccessBuilder("out").dtype( DataType.FLOAT64).build(), right=A_INT64_LITERAL) upcast_and_validate(testee, [Cast(dtype=DataType.FLOAT64, expr=A_INT64_LITERAL)])
def test_upcast_ParAssignStmt(): testee = ParAssignStmt(left=FieldAccessFactory(dtype=DataType.FLOAT64), right=A_INT64_LITERAL) upcast_and_validate(testee, [Cast(dtype=DataType.FLOAT64, expr=A_INT64_LITERAL)])