|
7 | 7 | from sympy import Expr, Number, Symbol |
8 | 8 | from devito import (Constant, Dimension, Grid, Function, solve, TimeFunction, Eq, # noqa |
9 | 9 | Operator, SubDimension, norm, Le, Ge, Gt, Lt, Abs, sin, cos, |
10 | | - Min, Max) |
11 | | -from devito.finite_differences.differentiable import SafeInv, Weights |
| 10 | + Min, Max, SubDomain) |
| 11 | +from devito.finite_differences.differentiable import SafeInv, Weights, Mul |
12 | 12 | from devito.ir import Expression, FindNodes, ccode |
13 | 13 | from devito.symbolics import (retrieve_functions, retrieve_indexed, evalrel, # noqa |
14 | 14 | CallFromPointer, Cast, DefFunction, FieldFromPointer, |
15 | 15 | INT, FieldFromComposite, IntDiv, Namespace, Rvalue, |
16 | 16 | ReservedWord, ListInitializer, uxreplace, pow_to_mul, |
17 | | - retrieve_derivatives, BaseCast) |
| 17 | + retrieve_derivatives, BaseCast, SizeOf) |
18 | 18 | from devito.tools import as_tuple |
19 | 19 | from devito.types import (Array, Bundle, FIndexed, LocalObject, Object, |
20 | 20 | ComponentAccess, StencilDimension, Symbol as dSymbol) |
@@ -874,3 +874,41 @@ def test_assumptions(self, op, expr, assumptions, expected): |
874 | 874 | assumptions = eval(assumptions) |
875 | 875 | expected = eval(expected) |
876 | 876 | assert evalrel(op, eqn, assumptions) == expected |
| 877 | + |
| 878 | + |
| 879 | +def test_issue_2577a(): |
| 880 | + u = TimeFunction(name='u', grid=Grid((2,))) |
| 881 | + x = u.grid.dimensions[0] |
| 882 | + expr = Mul(-1, -1., x, u) |
| 883 | + assert expr.args == (x, u) |
| 884 | + eq = Eq(u.forward, expr) |
| 885 | + op = Operator(eq) |
| 886 | + |
| 887 | + assert '--' not in str(op.ccode) |
| 888 | + |
| 889 | + |
| 890 | +def test_issue_2577b(): |
| 891 | + class SD0(SubDomain): |
| 892 | + name = 'sd0' |
| 893 | + |
| 894 | + def define(self, dimensions): |
| 895 | + x, = dimensions |
| 896 | + return {x: ('middle', 1, 1)} |
| 897 | + |
| 898 | + grid = Grid(shape=(11,)) |
| 899 | + |
| 900 | + sd0 = SD0(grid=grid) |
| 901 | + |
| 902 | + u = Function(name='u', grid=grid, space_order=2) |
| 903 | + |
| 904 | + eq_u = Eq(u, -(u*u).dxc, subdomain=sd0) |
| 905 | + |
| 906 | + op = Operator(eq_u) |
| 907 | + assert '--' not in str(op.ccode) |
| 908 | + |
| 909 | + |
| 910 | +def test_print_div(): |
| 911 | + a = SizeOf(np.int32) |
| 912 | + b = SizeOf(np.int64) |
| 913 | + cstr = ccode(a / b) |
| 914 | + assert cstr == 'sizeof(int)/sizeof(long)' |
0 commit comments