Skip to content
Snippets Groups Projects
Commit 632e3729 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

adapt SFG to changes in pystencils!443

parent 86ea72ea
1 merge request!14Adapt SFG to field typing changes in pystencils
Pipeline #73013 failed with stages
in 1 minute and 48 seconds
from typing import cast
from sympy import Symbol
from pystencils import Field
from pystencils import Field, DynamicType
from pystencils.types import (
PsType,
PsUnsignedIntegerType,
......@@ -115,10 +115,15 @@ class StdMdspan(SrcField):
)
super().__init__(dtype)
self._element_type = T
self._extents_type = extents_str
self._layout_type = layout_policy
self._dim = len(extents)
@property
def element_type(self) -> PsType:
return self._element_type
@property
def extents_type(self) -> str:
return self._extents_type
......@@ -166,6 +171,9 @@ class StdMdspan(SrcField):
const: bool = False,
):
"""Creates a `std::mdspan` instance for a given pystencils field."""
if isinstance(field.dtype, DynamicType):
raise ValueError("Cannot map dynamically typed field to std::mdspan")
extents: list[str | int] = []
for s in field.spatial_shape:
......
from pystencils.field import Field
from pystencils import Field, DynamicType
from pystencils.types import UserTypeSpec, create_type, PsType
from ...lang import SrcField, IFieldExtraction, AugExpr, cpptype
......@@ -44,6 +44,9 @@ class StdSpan(SrcField):
raise ValueError(
"Only one-dimensional fields with trivial index dimensions can be mapped onto `std::span`"
)
if isinstance(field.dtype, DynamicType):
raise ValueError("Cannot map dynamically typed field to std::span")
return StdSpan(field.dtype, ref=ref, const=const).var(field.name)
......
from pystencils.field import Field
from pystencils import Field, DynamicType
from pystencils.types import UserTypeSpec, create_type, PsType
from ...lang import SrcField, SrcVector, AugExpr, IFieldExtraction, cpptype
......@@ -59,7 +59,12 @@ class StdVector(SrcVector, SrcField):
f"Cannot create std::vector from more-than-one-dimensional field {field}."
)
return StdVector(field.dtype, unsafe=False, ref=ref, const=const).var(field.name)
if isinstance(field.dtype, DynamicType):
raise ValueError("Cannot map dynamically typed field to std::vector")
return StdVector(field.dtype, unsafe=False, ref=ref, const=const).var(
field.name
)
def std_vector_ref(field: Field):
......
from ...lang import SrcField, IFieldExtraction
from pystencils import Field
from pystencils import Field, DynamicType
from pystencils.types import UserTypeSpec, create_type
from ...lang import AugExpr, cpptype
......@@ -75,6 +75,9 @@ class SyclAccessor(SrcField):
def from_field(field: Field, ref: bool = True):
"""Creates a `sycl::accessor &` for a given pystencils field."""
if isinstance(field.dtype, DynamicType):
raise ValueError("Cannot map dynamically typed field to sycl::accessor")
return SyclAccessor(
field.dtype,
field.spatial_dimensions + field.index_dimensions,
......
......@@ -31,6 +31,17 @@ def test_stl_containers():
assert includes(expr) == {HeaderFile.parse("<span>")}
def test_mdspan_from_field():
f = ps.fields("f: float32[3D]")
f_mdspan = std.mdspan.from_field(f)
assert f_mdspan.element_type == ps.create_type("float32")
f = ps.fields("f: dyn[3D]")
with pytest.raises(ValueError):
f_mdspan = std.mdspan.from_field(f)
def test_vector_from_field():
f = ps.fields("f: float32[1D]")
f_vec = std.vector.from_field(f)
......@@ -52,6 +63,10 @@ def test_vector_from_field():
with pytest.raises(ValueError):
std.vector.from_field(f)
f = ps.fields("f(1): dyn[1D]")
with pytest.raises(ValueError):
std.vector.from_field(f)
def test_span_from_field():
f = ps.fields("f: float32[1D]")
......@@ -73,3 +88,7 @@ def test_span_from_field():
f = ps.fields("f(1): float32[2D]")
with pytest.raises(ValueError):
std.span.from_field(f)
f = ps.fields("f(1): dyn[1D]")
with pytest.raises(ValueError):
std.span.from_field(f)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment