/
relational.py
230 lines (182 loc) · 6.38 KB
/
relational.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""User API to specify relationals."""
import sympy
__all__ = ['Le', 'Lt', 'Ge', 'Gt', 'Ne']
class Le(sympy.Le):
"""
A less-than or equal ("<=") relation between two objects, the left-hand side and the
right-hand side. It can be used to build conditionals but not directly to
construct an Operator.
Parameters
----------
lhs : expr-like
The left-hand side.
rhs : expr-like, optional
The right-hand side. Defaults to 0.
subdomain : SubDomain, optional
To restrict the evalaution of the relation to a particular sub-region in the
computational domain.
Examples
--------
`Le` may be used to express a relation (e.g. in a Subdomain).
>>> from devito import Grid, Function, ConditionalDimension, Eq, Operator, Le
>>> grid = Grid(shape=(8, 8))
>>> g = Function(name='g', grid=grid)
>>> Le(g, 1)
g(x, y) <= 1
"""
def __new__(cls, lhs, rhs=0, subdomain=None, **kwargs):
kwargs.update({'evaluate': False})
obj = sympy.Le.__new__(cls, lhs, rhs, **kwargs)
obj._subdomain = subdomain
return obj
@property
def subdomain(self):
"""The SubDomain in which the Le is defined."""
return self._subdomain
@property
def negated(self):
return ops.get(self.func)(*self.args)
class Lt(sympy.Lt):
"""
A less-than ("<") relation between two objects, the left-hand side and the
right-hand side.It can be used to build conditionals but not directly to
construct an Operator.
Parameters
----------
lhs : expr-like
The left-hand side.
rhs : expr-like, optional
The right-hand side. Defaults to 0.
subdomain : SubDomain, optional
To restrict the evalaution of the relation to a particular sub-region in the
computational domain.
Examples
--------
`Lt` may be used to express a relation (e.g. in a Subdomain).
>>> from devito import Grid, Function, ConditionalDimension, Eq, Operator, Lt
>>> grid = Grid(shape=(8, 8))
>>> g = Function(name='g', grid=grid)
>>> Lt(g, 1)
g(x, y) < 1
"""
def __new__(cls, lhs, rhs=0, subdomain=None, **kwargs):
kwargs.update({'evaluate': False})
obj = sympy.Lt.__new__(cls, lhs, rhs, **kwargs)
obj._subdomain = subdomain
return obj
@property
def subdomain(self):
"""The SubDomain in which the Lt is defined."""
return self._subdomain
@property
def negated(self):
return ops.get(self.func)(*self.args)
class Ge(sympy.Ge):
"""
A greater-than or equal (">=") relation between two objects, the left-hand side and
the right-hand side. It can be used to build conditionals but not directly to
construct an Operator.
Parameters
----------
lhs : expr-like
The left-hand side.
rhs : expr-like, optional
The right-hand side. Defaults to 0.
subdomain : SubDomain, optional
To restrict the evalaution of the relation to a particular sub-region in the
computational domain.
Examples
--------
`Ge` may be used to express a relation (e.g. in a Subdomain).
>>> from devito import Grid, Function, ConditionalDimension, Eq, Operator, Ge
>>> grid = Grid(shape=(8, 8))
>>> g = Function(name='g', grid=grid)
>>> Ge(g, 1)
g(x, y) >= 1
"""
def __new__(cls, lhs, rhs=0, subdomain=None, **kwargs):
kwargs.update({'evaluate': False})
obj = sympy.Ge.__new__(cls, lhs, rhs, **kwargs)
obj._subdomain = subdomain
return obj
@property
def subdomain(self):
"""The SubDomain in which the Ge is defined."""
return self._subdomain
@property
def negated(self):
return ops.get(self.func)(*self.args)
class Gt(sympy.Gt):
"""
A greater-than (">") relation between two objects, the left-hand side and the
right-hand side. It can be used to build conditionals but not directly to
construct an Operator.
Parameters
----------
lhs : expr-like
The left-hand side.
rhs : expr-like, optional
The right-hand side. Defaults to 0.
subdomain : SubDomain, optional
To restrict the evalaution of the relation to a particular sub-region in the
computational domain.
Examples
--------
`Gt` may be used to express a relation.
>>> from devito import Grid, Function, ConditionalDimension, Eq, Operator, Gt
>>> grid = Grid(shape=(8, 8))
>>> g = Function(name='g', grid=grid)
>>> Gt(g, 1)
g(x, y) > 1
"""
def __new__(cls, lhs, rhs=0, subdomain=None, **kwargs):
kwargs.update({'evaluate': False})
obj = sympy.Gt.__new__(cls, lhs, rhs, **kwargs)
obj._subdomain = subdomain
return obj
@property
def subdomain(self):
"""The SubDomain in which the Gt is defined."""
return self._subdomain
@property
def negated(self):
return ops.get(self.func)(*self.args)
class Ne(sympy.Ne):
"""
A not-equal ("!=") relation between two objects (see Notes below), the left-hand side
and the right-hand side. It can be used to build conditionals but not directly to
construct an Operator.
Parameters
----------
lhs : expr-like
The left-hand side.
rhs : expr-like, optional
The right-hand side. Defaults to 0.
subdomain : SubDomain, optional
To restrict the evalaution of the relation to a particular sub-region in the
computational domain.
Examples
--------
`Ne` may be used to express a relation.
>>> from devito import Grid, Function, ConditionalDimension, Eq, Operator, Ne
>>> grid = Grid(shape=(8, 8))
>>> g = Function(name='g', grid=grid)
>>> Ne(g, 0)
Ne(g(x, y), 0)
Notes
-----
This class is not the same as the != operator. The != operator tests for exact
structural equality between two expressions; this class compares expressions
mathematically. Source: https://docs.sympy.org/latest/modules/core.html
"""
is_Relational = False
def __new__(cls, lhs, rhs=0, subdomain=None, **kwargs):
kwargs.update({'evaluate': False})
obj = sympy.Ne.__new__(cls, lhs, rhs, **kwargs)
obj._subdomain = subdomain
return obj
@property
def subdomain(self):
"""The SubDomain in which the Ne is defined."""
return self._subdomain
ops = {Ge: Lt, Gt: Le, Le: Gt, Lt: Ge}