electriclilies commented on a change in pull request #9533:
URL: https://github.com/apache/tvm/pull/9533#discussion_r753538670
##########
File path: src/relay/ir/expr.cc
##########
@@ -76,6 +76,29 @@ TVM_REGISTER_NODE_TYPE(TupleNode);
TVM_REGISTER_GLOBAL("relay.ir.Tuple").set_body_typed([](tvm::Array<relay::Expr>
fields, Span span) {
return Tuple(fields, span);
});
+Tuple WithFields(Tuple tuple, Optional<Array<Expr>> opt_fields, Optional<Span>
opt_span) {
+ Array<Expr> fields = opt_fields.value_or(tuple->fields);
+ Span span = opt_span.value_or(tuple->span);
+
+ bool all_fields_unchanged = true;
+ if (fields.size() == tuple->fields.size()) {
+ for (uint i = 0; i < fields.size(); i++) {
+ all_fields_unchanged &= fields[i].same_as(tuple->fields[i]);
+ }
+ } else {
+ all_fields_unchanged = false;
+ }
+
+ all_fields_unchanged = all_fields_unchanged && span.same_as(tuple->span);
+ if (all_fields_unchanged) {
+ return std::move(tuple);
+ } else {
+ TupleNode* cow_tuple_node = tuple.CopyOnWrite();
+ cow_tuple_node->fields = fields;
+ cow_tuple_node->span = span;
+ return GetRef<Tuple>(cow_tuple_node);
Review comment:
Thanks for all your help with the subtleties!
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]