|
6 | 6 |
|
7 | 7 | from devito import NODE, Differentiable, Eq, Function, Grid, Operator |
8 | 8 | from devito.finite_differences.differentiable import ( |
9 | | - Add, EvalDerivative, Mul, Pow, SafeInv, diffify, interp_for_fd |
| 9 | + Add, EvalDerivative, Mul, Pow, SafeInv, deep_priority, diffify, highest_priority, |
| 10 | + interp_for_fd |
10 | 11 | ) |
11 | 12 |
|
12 | 13 |
|
@@ -224,6 +225,33 @@ def test_mul_three_funcs(self, interp_mode, targets): |
224 | 225 | assert b.name in evaluated_str |
225 | 226 | assert c.name in evaluated_str |
226 | 227 |
|
| 228 | + def test_mul_gather_priority(self): |
| 229 | + """ |
| 230 | + The gather lands on the highest-priority Function inside the operands. |
| 231 | +
|
| 232 | + Without `deep_priority` both operands report the `Differentiable` |
| 233 | + fallback, tie, and the winner comes down to SymPy's argument order. |
| 234 | + """ |
| 235 | + grid = Grid((11, 11)) |
| 236 | + funcs = self._all_funcs(grid) |
| 237 | + node, fx, fy, fxy = (funcs['node'], funcs['x'], |
| 238 | + funcs['y'], funcs['xy']) |
| 239 | + |
| 240 | + # Two sums, only the first carrying a NODE Function |
| 241 | + with_node = node * fxy + fxy |
| 242 | + staggered = fx + fy |
| 243 | + |
| 244 | + assert deep_priority(with_node) == node._fd_priority |
| 245 | + assert deep_priority(staggered) == fx._fd_priority |
| 246 | + assert deep_priority(with_node) > deep_priority(staggered) |
| 247 | + |
| 248 | + # Whichever way the product sorts, NODE wins |
| 249 | + for prod in (with_node * staggered, staggered * with_node): |
| 250 | + assert highest_priority( |
| 251 | + prod, candidates=[with_node, staggered] |
| 252 | + ) is node |
| 253 | + assert prod.indices_ref == node.indices_ref |
| 254 | + |
227 | 255 | @pytest.mark.parametrize('interp_mode', ['direct', 'symmetric']) |
228 | 256 | @pytest.mark.parametrize('targets', [ |
229 | 257 | ('node', 'x', 'xy'), |
|
0 commit comments