diff --git a/pystencils/field.py b/pystencils/field.py index 2c25dce4462feefd37dd26b930f1191978a75777..aa0d1d36318c334a2bda3eb6ba197a4213a1c374 100644 --- a/pystencils/field.py +++ b/pystencils/field.py @@ -357,6 +357,10 @@ class Field(AbstractField): def dtype(self): return self._dtype + @property + def itemsize(self): + return self.dtype.numpy_dtype.itemsize + def __repr__(self): return self._field_name diff --git a/pystencils_tests/test_field.py b/pystencils_tests/test_field.py index d4b9c6a38fba47648f1ae6cda1198ff45cfb3a83..49bd4486474b91caf90c7e405f1a2a2ac7d7e33d 100644 --- a/pystencils_tests/test_field.py +++ b/pystencils_tests/test_field.py @@ -3,8 +3,7 @@ import pytest import sympy as sp import pystencils as ps -from pystencils.field import Field, FieldType -from pystencils.field import layout_string_to_tuple +from pystencils.field import Field, FieldType, layout_string_to_tuple def test_field_basic(): @@ -117,3 +116,14 @@ def test_string_creation(): assert x.index_shape == (4,) assert y.index_shape == (3, 5) assert z.spatial_shape == (3, 47) + + +def test_itemsize(): + + x = ps.fields('x: float32[1d]') + y = ps.fields('y: float64[2d]') + i = ps.fields('i: int16[1d]') + + assert x.itemsize == 4 + assert y.itemsize == 8 + assert i.itemsize == 2