def test_genexpr_op_genexpr(model): m, x, y, z = model genexpr = x**1.5 + y assert isinstance(genexpr, GenExpr) genexpr **= 2.2 assert isinstance(genexpr, GenExpr) genexpr += exp(x) assert isinstance(genexpr, GenExpr) genexpr -= exp(x) assert isinstance(genexpr, GenExpr) genexpr /= log(x + 1) assert isinstance(genexpr, GenExpr) genexpr *= (x + y)**1.2 assert isinstance(genexpr, GenExpr) genexpr /= exp(2) assert isinstance(genexpr, GenExpr) genexpr /= x + y assert isinstance(genexpr, GenExpr) genexpr = x**1.5 + y assert isinstance(genexpr, GenExpr) assert isinstance(sqrt(x) + genexpr, GenExpr) assert isinstance(exp(x) + genexpr, GenExpr) assert isinstance(1 / x + genexpr, GenExpr) assert isinstance(1 / x**1.5 - genexpr, GenExpr) assert isinstance(y / x - exp(genexpr), GenExpr) # sqrt(2) is not a constant expression and # we can only power to constant expressions! with pytest.raises(NotImplementedError): genexpr **= sqrt(2)
def test_genexpr_op_genexpr(model): m, x, y, z = model genexpr = x**1.5 + y assert isinstance(genexpr, GenExpr) genexpr **= 2.2 assert isinstance(genexpr, GenExpr) genexpr += exp(x) assert isinstance(genexpr, GenExpr) genexpr -= exp(x) assert isinstance(genexpr, GenExpr) genexpr /= log(x + 1) assert isinstance(genexpr, GenExpr) genexpr *= (x + y)**1.2 assert isinstance(genexpr, GenExpr) genexpr /= exp(2) assert isinstance(genexpr, GenExpr) genexpr /= x + y assert isinstance(genexpr, GenExpr) genexpr = x**1.5 + y assert isinstance(genexpr, GenExpr) assert isinstance(sqrt(x) + genexpr, GenExpr) assert isinstance(exp(x) + genexpr, GenExpr) assert isinstance(1/x + genexpr, GenExpr) assert isinstance(1/x**1.5 - genexpr, GenExpr) assert isinstance(y/x - exp(genexpr), GenExpr) # sqrt(2) is not a constant expression and # we can only power to constant expressions! with pytest.raises(NotImplementedError): genexpr **= sqrt(2)
def test_upgrade(model): m, x, y, z = model expr = x + y assert isinstance(expr, Expr) expr += exp(z) assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr -= exp(z) assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr /= x assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr *= sqrt(x) assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr **= 1.5 assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) assert isinstance(expr + exp(x), GenExpr) assert isinstance(expr - exp(x), GenExpr) assert isinstance(expr / x, GenExpr) assert isinstance(expr * x**1.2, GenExpr) assert isinstance(sqrt(expr), GenExpr) assert isinstance(abs(expr), GenExpr) assert isinstance(log(expr), GenExpr) assert isinstance(exp(expr), GenExpr) with pytest.raises(ZeroDivisionError): expr /= 0.0
def test_upgrade(model): m, x, y, z = model expr = x + y assert isinstance(expr, Expr) expr += exp(z) assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr -= exp(z) assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr /= x assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr *= sqrt(x) assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) expr **= 1.5 assert isinstance(expr, GenExpr) expr = x + y assert isinstance(expr, Expr) assert isinstance(expr + exp(x), GenExpr) assert isinstance(expr - exp(x), GenExpr) assert isinstance(expr/x, GenExpr) assert isinstance(expr * x**1.2, GenExpr) assert isinstance(sqrt(expr), GenExpr) assert isinstance(abs(expr), GenExpr) assert isinstance(log(expr), GenExpr) assert isinstance(exp(expr), GenExpr) with pytest.raises(ZeroDivisionError): expr /= 0.0