MCPcopy Index your code
hub / github.com/numpy/numpy / Expr

Class Expr

numpy/f2py/symbolic.py:157–787  ·  view source on GitHub ↗

Represents a Fortran expression as an op-data pair. Expr instances are hashable and sortable.

Source from the content-addressed store, hash-verified

155
156
157class Expr:
158 """Represents a Fortran expression as an op-data pair.
159
160 Expr instances are hashable and sortable.
161 """
162
163 @staticmethod
164 def parse(s, language=Language.C):
165 """Parse a Fortran expression to an Expr.
166 """
167 return fromstring(s, language=language)
168
169 def __init__(self, op, data):
170 assert isinstance(op, Op)
171
172 # sanity checks
173 if op is Op.INTEGER:
174 # data is a 2-tuple of numeric object and a kind value
175 # (default is 4)
176 assert isinstance(data, tuple) and len(data) == 2
177 assert isinstance(data[0], int)
178 assert isinstance(data[1], (int, str)), data
179 elif op is Op.REAL:
180 # data is a 2-tuple of numeric object and a kind value
181 # (default is 4)
182 assert isinstance(data, tuple) and len(data) == 2
183 assert isinstance(data[0], float)
184 assert isinstance(data[1], (int, str)), data
185 elif op is Op.COMPLEX:
186 # data is a 2-tuple of constant expressions
187 assert isinstance(data, tuple) and len(data) == 2
188 elif op is Op.STRING:
189 # data is a 2-tuple of quoted string and a kind value
190 # (default is 1)
191 assert isinstance(data, tuple) and len(data) == 2
192 assert (isinstance(data[0], str)
193 and data[0][::len(data[0]) - 1] in ('""', "''", '@@'))
194 assert isinstance(data[1], (int, str)), data
195 elif op is Op.SYMBOL:
196 # data is any hashable object
197 assert hash(data) is not None
198 elif op in (Op.ARRAY, Op.CONCAT):
199 # data is a tuple of expressions
200 assert isinstance(data, tuple)
201 assert all(isinstance(item, Expr) for item in data), data
202 elif op in (Op.TERMS, Op.FACTORS):
203 # data is {<term|base>:<coeff|exponent>} where dict values
204 # are nonzero Python integers
205 assert isinstance(data, dict)
206 elif op is Op.APPLY:
207 # data is (<function>, <operands>, <kwoperands>) where
208 # operands are Expr instances
209 assert isinstance(data, tuple) and len(data) == 3
210 # function is any hashable object
211 assert hash(data[0]) is not None
212 assert isinstance(data[1], tuple)
213 assert isinstance(data[2], dict)
214 elif op is Op.INDEXING:

Callers 15

test_tostring_fortranMethod · 0.90
test_tostring_cMethod · 0.90
test_operationsMethod · 0.90
__add__Method · 0.85
__mul__Method · 0.85
__pow__Method · 0.85
__floordiv__Method · 0.85
__getitem__Method · 0.85
substituteMethod · 0.85
traverseMethod · 0.85
normalizeFunction · 0.85
as_symbolFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_tostring_fortranMethod · 0.72
test_tostring_cMethod · 0.72
test_operationsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…