From c527f5edd2f1c3964186e3b48f95167cb11f9ae2 Mon Sep 17 00:00:00 2001 From: Steve Wang Date: Mon, 16 Oct 2023 14:54:45 +0700 Subject: [PATCH] Fixed LHS auto typing conversion for Expr arithmetic (#146) Now Expr arithmetic doesn't require LHS to be Expr but can be ToExpr as well. Thanks to Sandro for pointing out this error. --- Cargo.toml | 2 +- src/frontend/python/chiquito/expr.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 33ff5091..c15cf949 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chiquito" -version = "0.1.2023092400" +version = "0.1.2023101100" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Leo Lara "] diff --git a/src/frontend/python/chiquito/expr.py b/src/frontend/python/chiquito/expr.py index 52f99364..22e11396 100644 --- a/src/frontend/python/chiquito/expr.py +++ b/src/frontend/python/chiquito/expr.py @@ -26,6 +26,7 @@ def __add__(self: Expr, rhs: ToExpr) -> Sum: return Sum([self, rhs]) def __radd__(self: Expr, lhs: ToExpr) -> Sum: + lhs = to_expr(lhs) return Expr.__add__(lhs, self) def __sub__(self: Expr, rhs: ToExpr) -> Sum: @@ -33,6 +34,7 @@ def __sub__(self: Expr, rhs: ToExpr) -> Sum: return Sum([self, Neg(rhs)]) def __rsub__(self: Expr, lhs: ToExpr) -> Sum: + lhs = to_expr(lhs) return Expr.__sub__(lhs, self) def __mul__(self: Expr, rhs: ToExpr) -> Mul: @@ -40,6 +42,7 @@ def __mul__(self: Expr, rhs: ToExpr) -> Mul: return Mul([self, rhs]) def __rmul__(self: Expr, lhs: ToExpr) -> Mul: + lhs = to_expr(lhs) return Expr.__mul__(lhs, self) def __pow__(self: Expr, rhs: int) -> Pow: