MCPcopy Create free account
hub / github.com/numpy/numpy / test_operations

Method test_operations

numpy/f2py/tests/test_symbolic.py:214–276  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

212 assert as_ge(x, y).tostring(language=language) == "x >= y"
213
214 def test_operations(self):
215 x = as_symbol("x")
216 y = as_symbol("y")
217 z = as_symbol("z")
218
219 assert x + x == Expr(Op.TERMS, {x: 2})
220 assert x - x == Expr(Op.INTEGER, (0, 4))
221 assert x + y == Expr(Op.TERMS, {x: 1, y: 1})
222 assert x - y == Expr(Op.TERMS, {x: 1, y: -1})
223 assert x * x == Expr(Op.FACTORS, {x: 2})
224 assert x * y == Expr(Op.FACTORS, {x: 1, y: 1})
225
226 assert +x == x
227 assert -x == Expr(Op.TERMS, {x: -1}), repr(-x)
228 assert 2 * x == Expr(Op.TERMS, {x: 2})
229 assert 2 + x == Expr(Op.TERMS, {x: 1, as_number(1): 2})
230 assert 2 * x + 3 * y == Expr(Op.TERMS, {x: 2, y: 3})
231 assert (x + y) * 2 == Expr(Op.TERMS, {x: 2, y: 2})
232
233 assert x**2 == Expr(Op.FACTORS, {x: 2})
234 assert (x + y)**2 == Expr(
235 Op.TERMS,
236 {
237 Expr(Op.FACTORS, {x: 2}): 1,
238 Expr(Op.FACTORS, {y: 2}): 1,
239 Expr(Op.FACTORS, {
240 x: 1,
241 y: 1
242 }): 2,
243 },
244 )
245 assert (x + y) * x == x**2 + x * y
246 assert (x + y)**2 == x**2 + 2 * x * y + y**2
247 assert (x + y)**2 + (x - y)**2 == 2 * x**2 + 2 * y**2
248 assert (x + y) * z == x * z + y * z
249 assert z * (x + y) == x * z + y * z
250
251 assert (x / 2) == as_apply(ArithOp.DIV, x, as_number(2))
252 assert (2 * x / 2) == x
253 assert (3 * x / 2) == as_apply(ArithOp.DIV, 3 * x, as_number(2))
254 assert (4 * x / 2) == 2 * x
255 assert (5 * x / 2) == as_apply(ArithOp.DIV, 5 * x, as_number(2))
256 assert (6 * x / 2) == 3 * x
257 assert ((3 * 5) * x / 6) == as_apply(ArithOp.DIV, 5 * x, as_number(2))
258 assert (30 * x**2 * y**4 / (24 * x**3 * y**3)) == as_apply(
259 ArithOp.DIV, 5 * y, 4 * x)
260 assert ((15 * x / 6) / 5) == as_apply(ArithOp.DIV, x,
261 as_number(2)), (15 * x / 6) / 5
262 assert (x / (5 / x)) == as_apply(ArithOp.DIV, x**2, as_number(5))
263
264 assert (x / 2.0) == Expr(Op.TERMS, {x: 0.5})
265
266 s = as_string('"ABC"')
267 t = as_string('"123"')
268
269 assert s // t == Expr(Op.STRING, ('"ABC123"', 1))
270 assert s // x == Expr(Op.CONCAT, (s, x))
271 assert x // s == Expr(Op.CONCAT, (x, s))

Callers

nothing calls this directly

Calls 7

as_symbolFunction · 0.90
ExprClass · 0.90
as_numberFunction · 0.90
as_applyFunction · 0.90
as_stringFunction · 0.90
as_complexFunction · 0.90
as_exprFunction · 0.90

Tested by

no test coverage detected