def test_lazy_stencil(): """Test lazy stencil construction.""" builder = StencilBuilder(copy_stencil_definition).with_options( name="copy_stencil", module=copy_stencil_definition.__module__) lazy_s = LazyStencil(builder) assert lazy_s.backend.name == "debug"
def _decorator(func): _set_arg_dtypes(func, dtypes or {}) options = gt_definitions.BuildOptions( **{ **StencilBuilder.default_options_dict(func), **StencilBuilder.name_to_options_args(name), "rebuild": rebuild, "build_info": build_info, **StencilBuilder.nest_impl_options(kwargs), }) stencil = LazyStencil( StencilBuilder(func, backend=backend, options=options).with_externals(externals or {})) if eager: stencil = stencil.implementation elif check_syntax: stencil.check_syntax() return stencil
def test_lazy_syntax_check(frontend, backend): """Test syntax checking.""" lazy_pass = LazyStencil( StencilBuilder(copy_stencil_definition, frontend=frontend, backend=backend) ) lazy_fail = LazyStencil( StencilBuilder(wrong_syntax_stencil_definition, frontend=frontend, backend=backend) ) lazy_pass.check_syntax() with pytest.raises(GTScriptDefinitionError): lazy_fail.check_syntax()
def test_lazy_call(frontend, backend): """Test that the lazy stencil is callable like the compiled stencil object.""" import numpy a = gt4py.storage.from_array( numpy.array([[[1.0]]]), default_origin=(0, 0, 0), backend=backend.name ) b = gt4py.storage.from_array( numpy.array([[[0.0]]]), default_origin=(0, 0, 0), backend=backend.name ) lazy_s = LazyStencil( StencilBuilder(copy_stencil_definition, frontend=frontend, backend=backend).with_options( name="copy", module=copy_stencil_definition.__module__, rebuild=True ) ) lazy_s(b, a) assert b[0, 0, 0] == 1.0