|
4 | 4 | import pytest |
5 | 5 | import numpy as np |
6 | 6 |
|
7 | | -from sympy import Expr, Symbol |
| 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 | 10 | Min, Max) |
|
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 | | - ReservedWord, ListInitializer, uxreplace, |
| 16 | + ReservedWord, ListInitializer, uxreplace, pow_to_mul, |
17 | 17 | retrieve_derivatives, BaseCast) |
18 | 18 | from devito.tools import as_tuple |
19 | 19 | from devito.types import (Array, Bundle, FIndexed, LocalObject, Object, |
@@ -636,6 +636,21 @@ def __new__(cls, name=None, arguments=None, p0=None, p1=None, p2=None): |
636 | 636 | assert func1.p1 == (g,) |
637 | 637 | assert func1.p2 == 'bar' |
638 | 638 |
|
| 639 | + def test_reduce_to_number(self): |
| 640 | + grid = Grid(shape=(4, 4)) |
| 641 | + x, _ = grid.dimensions |
| 642 | + h_x = x.spacing |
| 643 | + |
| 644 | + # Emulate lowered coefficient |
| 645 | + w = -0.0354212/(h_x*h_x) |
| 646 | + w_lowered = pow_to_mul(w) |
| 647 | + |
| 648 | + w_sub = uxreplace(w_lowered, {h_x: Number(3)}) |
| 649 | + |
| 650 | + assert np.isclose(w_sub, -0.003935689) |
| 651 | + assert not w_sub.is_Mul |
| 652 | + assert w_sub.is_Number |
| 653 | + |
639 | 654 |
|
640 | 655 | def test_minmax(): |
641 | 656 | grid = Grid(shape=(5, 5)) |
|
0 commit comments