|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 | import pytest |
3 | 5 | import sympy |
|
13 | 15 | from devito.ir.cgen.printer import BasePrinter, get_printer |
14 | 16 | from devito.passes.iet.langbase import LangBB |
15 | 17 | from devito.passes.iet.languages.C import CBB, CPrinter |
| 18 | +from devito.passes.iet.languages.CXX import CXXPrinter |
16 | 19 | from devito.passes.iet.languages.openacc import AccBB, AccPrinter |
17 | | -from devito.passes.iet.languages.openmp import OmpBB |
| 20 | +from devito.passes.iet.languages.openmp import CXXOmpBB, OmpBB |
18 | 21 | from devito.symbolics.extended_dtypes import ctypes_vector_mapper |
19 | 22 | from devito.tools import dtype_to_cstr |
20 | 23 | from devito.types.basic import Basic, Scalar, Symbol |
|
25 | 28 | _languages: dict[str, type[LangBB]] = { |
26 | 29 | 'C': CBB, |
27 | 30 | 'openmp': OmpBB, |
| 31 | + 'CXXopenmp': CXXOmpBB, |
28 | 32 | 'openacc': AccBB |
29 | 33 | } |
30 | 34 |
|
31 | 35 | _printers: dict[str, type[BasePrinter]] = { |
32 | 36 | 'C': CPrinter, |
33 | 37 | 'openmp': CPrinter, |
| 38 | + 'CXXopenmp': CXXPrinter, |
34 | 39 | 'openacc': AccPrinter |
35 | 40 | } |
36 | 41 |
|
@@ -147,6 +152,30 @@ def test_complex_headers(dtype: np.dtype[np.inexact], kwargs: dict[str, str]) -> |
147 | 152 | assert header not in op._includes |
148 | 153 |
|
149 | 154 |
|
| 155 | +@pytest.mark.parametrize('kwargs', _configs + [_config_kwargs('cpu64', 'CXXopenmp')], |
| 156 | + ids=kw_id) |
| 157 | +def test_complex_arith_header(kwargs: dict[str, str]) -> None: |
| 158 | + """ |
| 159 | + Tests that the extra complex arithmetic definitions some languages need are |
| 160 | + saved in full to a language-specific header the operator includes. |
| 161 | + """ |
| 162 | + langbb = _get_language(**kwargs) |
| 163 | + code = langbb.get('def-complex') |
| 164 | + if code is None: |
| 165 | + pytest.skip(f"`{kwargs['language']}` needs no complex arithmetic header") |
| 166 | + |
| 167 | + # Set up an operator |
| 168 | + grid = Grid(shape=(3, 3)) |
| 169 | + x, y = grid.dimensions |
| 170 | + |
| 171 | + u = Function(name='u', grid=grid, dtype=np.complex64) |
| 172 | + op = Operator(Eq(u, x*y + 1j), **kwargs) |
| 173 | + |
| 174 | + hfile, = [Path(i) for i in op._includes if 'complex_arith' in i] |
| 175 | + assert hfile.name == f"{langbb['name'].lower()}_complex_arith.h" |
| 176 | + assert hfile.read_text() == str(code) |
| 177 | + |
| 178 | + |
150 | 179 | @pytest.mark.parametrize('dtype', [np.complex64, np.complex128]) |
151 | 180 | @pytest.mark.parametrize('kwargs', _configs, ids=kw_id) |
152 | 181 | def test_imag_unit(dtype: np.complexfloating, kwargs: dict[str, str]) -> None: |
|
0 commit comments