t-vi commented on a change in pull request #5946:
URL: https://github.com/apache/incubator-tvm/pull/5946#discussion_r447259517



##########
File path: src/relay/transforms/gradient.cc
##########
@@ -106,14 +106,67 @@ struct ADValueNode {
   }
 };
 
+Expr MultiZerosType(const Type& t) {
+  if (auto* tt = t.as<TensorTypeNode>()) {
+    return Zeros(tt->shape, tt->dtype);
+  } else if (auto* tt = t.as<TupleTypeNode>()) {
+    std::vector<Expr> res;
+    for (size_t i = 0; i < tt->fields.size(); i++) {
+      res.push_back(MultiZerosType(tt->fields[i]));
+    }
+    return Tuple(res);
+  } else {
+    LOG(FATAL) << "unsupported type to zero: " << tt;
+    throw;
+  }
+}
+
+Expr MultiZerosLike(const Expr& e, const Type& t) {
+  if (t.as<TensorTypeNode>()) {
+    return ZerosLike(e);
+  } else if (auto* tt = t.as<TupleTypeNode>()) {
+    return MultiZerosType(t);
+  } else {
+    LOG(FATAL) << "unsupported type to create zeros: " << tt;
+    throw;
+  }
+}
+
+Expr MultiOnesType(const Type& t) {
+  if (auto* tt = t.as<TensorTypeNode>()) {
+    return Ones(tt->shape, tt->dtype);
+  } else if (auto* tt = t.as<TupleTypeNode>()) {
+    std::vector<Expr> res;
+    for (size_t i = 0; i < tt->fields.size(); i++) {
+      res.push_back(MultiOnesType(tt->fields[i]));
+    }
+    return Tuple(res);
+  } else {
+    LOG(FATAL) << "unsupported type to zero: " << tt;

Review comment:
       This goes away with the unification...




----------------------------------------------------------------
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


Reply via email to