Skip to content

Commit

Permalink
[RELAY][PASS] FoldScaleAxis Forward (apache#2020)
Browse files Browse the repository at this point in the history
* [RELAY][PASS] FoldScaleAxis Forward

* Introduce helper function type_as

* Update per review comment

* Fix according to comments
  • Loading branch information
tqchen authored and eqy committed Oct 29, 2018
1 parent 1931cc4 commit 38d867b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/tvm/relay/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ class TupleGetItemNode : public ExprNode {

RELAY_DEFINE_NODE_REF(TupleGetItem, TupleGetItemNode, Expr);

// implementataions
template<typename TTypeNode>
inline const TTypeNode* ExprNode::type_as() const {
static_assert(std::is_base_of<TypeNode, TTypeNode>::value,
"TType must be a special case of type");
CHECK(checked_type_.defined())
<< "Type inference for this Expr has not completed";
const TTypeNode* node = checked_type_.as<TTypeNode>();
CHECK(node != nullptr)
<< "Expected type to be " << TTypeNode::_type_key
<< ", but get " << checked_type_->type_key();
return node;
}

} // namespace relay
} // namespace tvm
#endif // TVM_RELAY_EXPR_H_
3 changes: 3 additions & 0 deletions python/tvm/relay/ir_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .expr import Expr
from .ty import Type


def infer_type(expr, env=None):
"""Infer the type of expr under the context of env.
Expand Down Expand Up @@ -166,6 +167,7 @@ def alpha_equal(lhs, rhs):
"""
return bool(_make._alpha_equal(lhs, rhs))


def graph_equal(lhs, rhs):
"""Compare two Relay expr for data-flow equivalence.
The difference between this and alpha-equality is that
Expand All @@ -187,6 +189,7 @@ def graph_equal(lhs, rhs):
"""
return bool(_make._graph_equal(lhs, rhs))


def structural_hash(value):
"""Hash a Relay expression structurally.
Expand Down

0 comments on commit 38d867b

Please sign in to comment.