Skip to content

Commit 624bea2

Browse files
committed
compiler: fix division printing
1 parent 24422fa commit 624bea2

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

.github/workflows/pytest-core-nompi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
173173
- name: Test with pytest
174174
run: |
175-
${{ env.RUN_CMD }} pytest -k "${{ matrix.test-set }}" -m "not parallel" --cov --cov-config=.coveragerc --cov-report=xml ${{ env.TESTS }}
175+
${{ env.RUN_CMD }} pytest -k "${{ matrix.test-set }}" -m "not parallel" --cov --cov-config=.coveragerc --cov-report=xml tests/
176176
177177
- name: Upload coverage to Codecov
178178
if: "!contains(matrix.name, 'docker')"

devito/finite_differences/differentiable.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from devito.finite_differences.tools import make_shift_x0, coeff_priority
1818
from devito.logger import warning
1919
from devito.tools import (as_tuple, filter_ordered, flatten, frozendict,
20-
infer_dtype, is_integer, split)
20+
infer_dtype, is_integer, split, is_number)
2121
from devito.types import Array, DimensionTuple, Evaluable, StencilDimension
2222
from devito.types.basic import AbstractFunction
2323

@@ -549,8 +549,7 @@ def __new__(cls, *args, **kwargs):
549549
args = flatten(e.args for e in nested) + list(others)
550550

551551
# Gather all numbers and simplify
552-
nums, others = split(args, lambda e: isinstance(e, (int, float,
553-
sympy.Number, np.number)))
552+
nums, others = split(args, lambda e: is_number(e))
554553
scalar = sympy.Mul(*nums)
555554

556555
# a*0 -> 0

devito/symbolics/extended_sympy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ def __new__(cls, name, arguments=None, template=None, **kwargs):
622622

623623
return obj
624624

625+
def _eval_is_commutative(self):
626+
# DefFunction defaults to commutative
627+
return True
628+
625629
@property
626630
def name(self):
627631
return self._name

devito/tools/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'roundm', 'powerset', 'invert', 'flatten', 'single_or', 'filter_ordered',
1313
'as_mapper', 'filter_sorted', 'pprint', 'sweep', 'all_equal', 'as_list',
1414
'indices_to_slices', 'indices_to_sections', 'transitive_closure',
15-
'humanbytes', 'contains_val', 'sorted_priority', 'as_set']
15+
'humanbytes', 'contains_val', 'sorted_priority', 'as_set', 'is_number']
1616

1717

1818
def prod(iterable, initial=1):
@@ -82,6 +82,13 @@ def is_integer(value):
8282
return isinstance(value, (int, np.integer, sympy.Integer))
8383

8484

85+
def is_number(value):
86+
"""
87+
A thorough instance comparison for all number types.
88+
"""
89+
return isinstance(value, (int, float, np.number, sympy.Number))
90+
91+
8592
def contains_val(val, items):
8693
try:
8794
return val in items

tests/test_dse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_pow_to_mul(expr, expected):
8888

8989

9090
@pytest.mark.parametrize('expr,expected', [
91-
('s - SizeOf("int")*fa[x]', 's - fa[x]*sizeof(int)'),
91+
('s - SizeOf("int")*fa[x]', 's - sizeof(int)*fa[x]'),
9292
('foo(4*fa[x] + 4*fb[x])', 'foo(4*(fa[x] + fb[x]))'),
9393
('floor(0.1*a + 0.1*fa[x])', 'floor(0.1*(a + fa[x]))'),
9494
('floor(0.1*(a + fa[x]))', 'floor(0.1*(a + fa[x]))'),

tests/test_symbolics.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
CallFromPointer, Cast, DefFunction, FieldFromPointer,
1515
INT, FieldFromComposite, IntDiv, Namespace, Rvalue,
1616
ReservedWord, ListInitializer, uxreplace, pow_to_mul,
17-
retrieve_derivatives, BaseCast)
17+
retrieve_derivatives, BaseCast, SizeOf)
1818
from devito.tools import as_tuple
1919
from devito.types import (Array, Bundle, FIndexed, LocalObject, Object,
2020
ComponentAccess, StencilDimension, Symbol as dSymbol)
@@ -877,7 +877,6 @@ def test_assumptions(self, op, expr, assumptions, expected):
877877

878878

879879
def test_issue_2577a():
880-
881880
u = TimeFunction(name='u', grid=Grid((2,)))
882881
x = u.grid.dimensions[0]
883882
expr = Mul(-1, -1., x, u)
@@ -906,3 +905,10 @@ def define(self, dimensions):
906905

907906
op = Operator(eq_u)
908907
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

Comments
 (0)