Skip to content

Commit a60b12a

Browse files
committed
api: silence non-Expr warning for tensor (e.g staggering/name/..)
1 parent ecc53dd commit a60b12a

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

devito/data/allocators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def alloc(self, shape, dtype, padding=0):
112112
raise RuntimeError(f"Unable to allocate {size} elements in memory")
113113

114114
# Compute the pointer to the user data
115-
padleft_bytes = padleft * ctypes.sizeof(ctype)
115+
padleft_bytes = int(padleft * ctypes.sizeof(ctype))
116116
c_pointer = ctypes.c_void_p(padleft_pointer.value + padleft_bytes)
117117

118118
# Cast to 1D array of the specified `datasize`

devito/types/basic.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import abc
22
import inspect
3+
import warnings
34
from contextlib import suppress
45
from ctypes import POINTER, Structure, _Pointer, c_char, c_char_p
56
from functools import cached_property, reduce
@@ -9,6 +10,7 @@
910
import sympy
1011
from sympy.core.assumptions import _assume_rules
1112
from sympy.core.decorators import call_highest_priority
13+
from sympy.utilities.exceptions import SymPyDeprecationWarning
1214

1315
from devito.data import default_allocator
1416
from devito.parameters import configuration
@@ -1533,10 +1535,20 @@ def _sympify(self, arg):
15331535
# This is used internally by sympy to process arguments at rebuilt. And since
15341536
# some of our properties are non-sympyfiable we need to have a fallback
15351537
try:
1536-
return super()._sympify(arg)
1537-
except sympy.SympifyError:
1538+
# Pure sympy object
1539+
return arg._sympy_()
1540+
except AttributeError:
15381541
return arg
15391542

1543+
@classmethod
1544+
def _eval_from_dok(cls, rows, cols, dok):
1545+
with warnings.catch_warnings():
1546+
warnings.filterwarnings(
1547+
"ignore",
1548+
category=SymPyDeprecationWarning
1549+
)
1550+
return super()._eval_from_dok(rows, cols, dok)
1551+
15401552
@property
15411553
def grid(self):
15421554
"""

devito/types/dense.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,8 @@ def __staggered_setup__(cls, dimensions, staggered=None, **kwargs):
11571157
assert len(staggered) == len(dimensions)
11581158
processed = staggered
11591159
else:
1160+
# Staggering is not NODE or CELL or None
1161+
# therefore it's a tuple of dimensions
11601162
processed = []
11611163
for d in dimensions:
11621164
if d in as_tuple(staggered):

devito/types/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def on_node(self):
5959

6060
@property
6161
def _ref(self):
62-
if self.on_node:
62+
if not self:
63+
return None
64+
elif self.on_node:
6365
return NODE
6466
else:
6567
return tuple(d for d, s in zip(self.getters, self, strict=True) if s == 1)

tests/test_staggered_utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from sympy import simplify
44

55
from devito import (
6-
CELL, NODE, Dimension, Eq, Function, Grid, Operator, TimeFunction, VectorTimeFunction,
7-
div
6+
CELL, NODE, Eq, Function, Grid, Operator, TimeFunction, VectorTimeFunction, div
87
)
98
from devito.tools import as_tuple, powerset
109

@@ -173,16 +172,15 @@ def test_staggered_rebuild(stagg):
173172
f = Function(name='f', grid=grid, space_order=4, staggered=stagg)
174173
assert tuple(f.staggered.getters.keys()) == grid.dimensions
175174

176-
new_dims = (Dimension('x1'), Dimension('y1'), Dimension('z1'))
177-
f2 = f.func(dimensions=new_dims)
175+
f2 = f.func(name="f2")
178176

179-
assert f2.dimensions == new_dims
177+
assert f2.dimensions == f.dimensions
180178
assert tuple(f2.staggered) == tuple(f.staggered)
181-
assert tuple(f2.staggered.getters.keys()) == new_dims
179+
assert tuple(f2.staggered.getters.keys()) == f.dimensions
182180

183181
# Check that rebuild correctly set the staggered indices
184182
# with the new dimensions
185-
for (d, nd) in zip(grid.dimensions, new_dims, strict=True):
183+
for (d, nd) in zip(grid.dimensions, f.dimensions, strict=True):
186184
if d in as_tuple(stagg) or stagg is CELL:
187185
assert f2.indices[nd] == nd + nd.spacing / 2
188186
else:

0 commit comments

Comments
 (0)