[GitHub] [incubator-tvm] mbaret commented on a change in pull request #5106: [Relay][MergeComposite] Support TupleGetItem in body of pattern

2020-03-25 Thread GitBox
mbaret commented on a change in pull request #5106: [Relay][MergeComposite] 
Support TupleGetItem in body of pattern
URL: https://github.com/apache/incubator-tvm/pull/5106#discussion_r398110062
 
 

 ##
 File path: src/relay/transforms/merge_composite.cc
 ##
 @@ -66,6 +66,31 @@ class MergeCompositeWrapper : public ExprMutator {
 return root;
   }
 
+  Expr ExtractPattern(const TupleGetItem& pattern, const Expr& root,
+  Map>* var_map, Map* call_map) {
+if (!root->IsInstance()) {
+  return Expr();
+}
+auto root_node = Downcast(root);
+if (pattern->index != root_node->index) {
+  return Expr();
+}
+if (pattern->tuple->IsInstance() &&
+root_node->tuple->IsInstance()) {
+  Expr new_arg;
+  if (call_map->find(pattern->tuple) != call_map->end()) {
+new_arg = (*call_map)[pattern->tuple];
+  } else {
+new_arg = ExtractPattern(Downcast(pattern->tuple),
+ Downcast(root_node->tuple),
+ var_map, call_map);
+call_map->Set(pattern->tuple, new_arg);
 
 Review comment:
   Alright, we'll leave it for now then (I'll probably change it in a later PR).


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] mbaret commented on a change in pull request #5106: [Relay][MergeComposite] Support TupleGetItem in body of pattern

2020-03-25 Thread GitBox
mbaret commented on a change in pull request #5106: [Relay][MergeComposite] 
Support TupleGetItem in body of pattern
URL: https://github.com/apache/incubator-tvm/pull/5106#discussion_r398109720
 
 

 ##
 File path: src/relay/transforms/merge_composite.cc
 ##
 @@ -66,6 +66,31 @@ class MergeCompositeWrapper : public ExprMutator {
 return root;
   }
 
+  Expr ExtractPattern(const TupleGetItem& pattern, const Expr& root,
+  Map>* var_map, Map* call_map) {
+if (!root->IsInstance()) {
+  return Expr();
+}
+auto root_node = Downcast(root);
+if (pattern->index != root_node->index) {
+  return Expr();
+}
+if (pattern->tuple->IsInstance() &&
+root_node->tuple->IsInstance()) {
+  Expr new_arg;
+  if (call_map->find(pattern->tuple) != call_map->end()) {
+new_arg = (*call_map)[pattern->tuple];
+  } else {
+new_arg = ExtractPattern(Downcast(pattern->tuple),
 
 Review comment:
   Ah, I get it now, thanks.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] mbaret commented on a change in pull request #5106: [Relay][MergeComposite] Support TupleGetItem in body of pattern

2020-03-24 Thread GitBox
mbaret commented on a change in pull request #5106: [Relay][MergeComposite] 
Support TupleGetItem in body of pattern
URL: https://github.com/apache/incubator-tvm/pull/5106#discussion_r397085411
 
 

 ##
 File path: src/relay/transforms/merge_composite.cc
 ##
 @@ -66,6 +66,31 @@ class MergeCompositeWrapper : public ExprMutator {
 return root;
   }
 
+  Expr ExtractPattern(const TupleGetItem& pattern, const Expr& root,
+  Map>* var_map, Map* call_map) {
+if (!root->IsInstance()) {
+  return Expr();
+}
+auto root_node = Downcast(root);
+if (pattern->index != root_node->index) {
+  return Expr();
+}
+if (pattern->tuple->IsInstance() &&
+root_node->tuple->IsInstance()) {
+  Expr new_arg;
+  if (call_map->find(pattern->tuple) != call_map->end()) {
+new_arg = (*call_map)[pattern->tuple];
+  } else {
+new_arg = ExtractPattern(Downcast(pattern->tuple),
+ Downcast(root_node->tuple),
+ var_map, call_map);
+call_map->Set(pattern->tuple, new_arg);
 
 Review comment:
   I think call_map should now be renamed to expr_map so this is a bit easier 
to follow.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] mbaret commented on a change in pull request #5106: [Relay][MergeComposite] Support TupleGetItem in body of pattern

2020-03-24 Thread GitBox
mbaret commented on a change in pull request #5106: [Relay][MergeComposite] 
Support TupleGetItem in body of pattern
URL: https://github.com/apache/incubator-tvm/pull/5106#discussion_r397086345
 
 

 ##
 File path: src/relay/transforms/merge_composite.cc
 ##
 @@ -66,6 +66,31 @@ class MergeCompositeWrapper : public ExprMutator {
 return root;
   }
 
+  Expr ExtractPattern(const TupleGetItem& pattern, const Expr& root,
+  Map>* var_map, Map* call_map) {
+if (!root->IsInstance()) {
+  return Expr();
+}
+auto root_node = Downcast(root);
+if (pattern->index != root_node->index) {
+  return Expr();
+}
+if (pattern->tuple->IsInstance() &&
+root_node->tuple->IsInstance()) {
+  Expr new_arg;
+  if (call_map->find(pattern->tuple) != call_map->end()) {
+new_arg = (*call_map)[pattern->tuple];
+  } else {
+new_arg = ExtractPattern(Downcast(pattern->tuple),
 
 Review comment:
   I'm not sure I understand why there's a downcast to a Call here, shouldn't 
it be a Tuple?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services