mirror of
https://github.com/zebrajr/tensorflow.git
synced 2025-12-06 00:19:58 +01:00
Add SymbolicExpr::IsBinaryOp() method
This CL introduces a new helper method SymbolicExpr::IsBinaryOp() to quickly determine if a SymbolicExpr is a binary operation (i.e., not a constant or a variable). This is used in indexing_map.cc in several places for AffineMap and it will simplify the refactor. PiperOrigin-RevId: 826468454
This commit is contained in:
parent
718fe5695e
commit
f73a954906
|
|
@ -557,6 +557,12 @@ SymbolicExprContext* SymbolicExpr::GetContext() const { return impl_->ctx_; }
|
|||
|
||||
SymbolicExprType SymbolicExpr::GetType() const { return impl_->type_; }
|
||||
|
||||
bool SymbolicExpr::IsBinaryOp() const {
|
||||
auto type = GetType();
|
||||
return type != SymbolicExprType::kConstant &&
|
||||
type != SymbolicExprType::kVariable;
|
||||
}
|
||||
|
||||
SymbolicExpr SymbolicExpr::GetLHS() const { return impl_->lhs_; }
|
||||
|
||||
SymbolicExpr SymbolicExpr::GetRHS() const { return impl_->rhs_; }
|
||||
|
|
@ -732,12 +738,11 @@ SymbolicExpr SymbolicExpr::Replace(
|
|||
return it->second;
|
||||
}
|
||||
|
||||
SymbolicExprType type = GetType();
|
||||
if (type == SymbolicExprType::kConstant ||
|
||||
type == SymbolicExprType::kVariable) {
|
||||
if (!IsBinaryOp()) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
SymbolicExprType type = GetType();
|
||||
SymbolicExpr lhs = GetLHS();
|
||||
SymbolicExpr rhs = GetRHS();
|
||||
SymbolicExpr new_lhs = lhs.Replace(replacements);
|
||||
|
|
@ -779,12 +784,11 @@ SymbolicExpr SymbolicExpr::Canonicalize() const {
|
|||
return *this;
|
||||
}
|
||||
|
||||
SymbolicExprType type = GetType();
|
||||
if (type == SymbolicExprType::kConstant ||
|
||||
type == SymbolicExprType::kVariable) {
|
||||
if (!IsBinaryOp()) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
SymbolicExprType type = GetType();
|
||||
SymbolicExpr lhs = this->GetLHS().Canonicalize();
|
||||
SymbolicExpr rhs = this->GetRHS().Canonicalize();
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ class SymbolicExpr {
|
|||
|
||||
SymbolicExprContext* GetContext() const;
|
||||
SymbolicExprType GetType() const;
|
||||
bool IsBinaryOp() const;
|
||||
SymbolicExpr GetLHS() const;
|
||||
SymbolicExpr GetRHS() const;
|
||||
int64_t GetValue() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user