-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CINN] Add Div to replace Recipical in DimExpr #70376
base: develop
Are you sure you want to change the base?
Conversation
…rity and functionality
你的PR提交成功,感谢你对开源项目的贡献! |
Call(lhs, DoEach, depth + 1, is_inversed); | ||
Call(rhs, DoEach, depth + 1, !is_inversed); | ||
} else { | ||
DoEach(expr, depth, is_inversed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什么情况下 is_inversed 为true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除VisitEachOperandStruct
/* | ||
* Simplify Example: | ||
* Mul(2, Reciprocal(2)) => 1 | ||
* Mul(2, Div(1, 2)) => 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mul(S0, Div(S1, S0)) => S1 现在不成立了
更新为
Mul(Div(1, S0), S0) => S0
Mul(S0, Div(1, S0) => S0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要论证下,能不能做为一个通用化简
if (lhs.Has<Div<DimExpr>>()) { | ||
auto div_expr = lhs.Get<Div<DimExpr>>(); | ||
if (!div_expr->lhs.Has<std::int64_t>()) { | ||
return false; | ||
} | ||
const auto& [lhs_num, lhs_dem] = GetConstRational(div_expr->lhs); | ||
if (lhs_dem != 1) { | ||
return false; | ||
} | ||
if (div_expr->rhs == rhs) { | ||
return true; | ||
} | ||
} | ||
if (rhs.Has<Reciprocal<DimExpr>>()) { | ||
const auto& rhs_operand = rhs.Get<Reciprocal<DimExpr>>()->data; | ||
return rhs_operand == lhs; | ||
if (rhs.Has<Div<DimExpr>>()) { | ||
auto div_expr = rhs.Get<Div<DimExpr>>(); | ||
if (!div_expr->lhs.Has<std::int64_t>()) { | ||
return false; | ||
} | ||
const auto& [rhs_num, rhs_dem] = GetConstRational(div_expr->lhs); | ||
if (rhs_dem != 1) { | ||
return false; | ||
} | ||
if (div_expr->rhs == lhs) { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mul(Div(1, S0), S0) -> S0
Mul(S0, Div(1, S0) -> S0
下同
static const_value_type MakeUnit() { return ConstRational{1, 1}; } | ||
static void Accumulate(const_value_type* value, const DimExpr& expr) { | ||
*value = MulConstRational( | ||
*value, GetConstRational(expr)); // The expr are in the denominator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expr在分母上有什么特殊之处吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方应该删掉,或者是DeadCode,因为Div修改为二元运算了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除Accumulate
@@ -1033,6 +1124,62 @@ struct SimplifyBroadcast { | |||
} | |||
}; | |||
|
|||
struct SimplifyDiv { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要补充一下 Simplify Example
Sorry to inform you that 4b4a22b's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
PR Category
CINN
PR Types
New features
Description
Pcard-67164