codeislife99 commented on a change in pull request #7125:
URL: https://github.com/apache/tvm/pull/7125#discussion_r547086641



##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -1553,6 +1553,52 @@ RELAY_REGISTER_OP("meshgrid")
     .set_attr<FTVMCompute>("FTVMCompute", MeshgridCompute)
     .set_attr<TOpPattern>("TOpPattern", kInjective);
 
+TVM_REGISTER_NODE_TYPE(SparseReshapeAttrs);
+
+bool SparseReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& 
attrs,
+                      const TypeReporter& reporter) {
+  // types: [sparse_indices, sparse_values, result]
+  // ICHECK_EQ(types.size(), 3);

Review comment:
       Done.

##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -1553,6 +1553,52 @@ RELAY_REGISTER_OP("meshgrid")
     .set_attr<FTVMCompute>("FTVMCompute", MeshgridCompute)
     .set_attr<TOpPattern>("TOpPattern", kInjective);
 
+TVM_REGISTER_NODE_TYPE(SparseReshapeAttrs);
+
+bool SparseReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& 
attrs,
+                      const TypeReporter& reporter) {
+  // types: [sparse_indices, sparse_values, result]
+  // ICHECK_EQ(types.size(), 3);
+  auto sparse_indices = types[0].as<TensorTypeNode>();
+  const auto* param = attrs.as<SparseReshapeAttrs>();
+  CHECK(param != nullptr);

Review comment:
       Done.

##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -1553,6 +1553,52 @@ RELAY_REGISTER_OP("meshgrid")
     .set_attr<FTVMCompute>("FTVMCompute", MeshgridCompute)
     .set_attr<TOpPattern>("TOpPattern", kInjective);
 
+TVM_REGISTER_NODE_TYPE(SparseReshapeAttrs);
+
+bool SparseReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& 
attrs,
+                      const TypeReporter& reporter) {
+  // types: [sparse_indices, sparse_values, result]
+  // ICHECK_EQ(types.size(), 3);
+  auto sparse_indices = types[0].as<TensorTypeNode>();
+  const auto* param = attrs.as<SparseReshapeAttrs>();
+  CHECK(param != nullptr);
+  Array<PrimExpr> new_sparse_indices_shape{sparse_indices->shape[0],
+                                           
static_cast<int>((param->new_shape).size())};
+  reporter->Assign(types[2], TensorType(new_sparse_indices_shape, 
sparse_indices->dtype));
+  return true;
+}
+
+Array<te::Tensor> SparseReshapeCompute(const Attrs& attrs, const 
Array<te::Tensor>& inputs,
+                                       const Type& out_type) {
+  // ICHECK_EQ(inputs.size(), 2);

Review comment:
       Done.

##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -1553,6 +1553,52 @@ RELAY_REGISTER_OP("meshgrid")
     .set_attr<FTVMCompute>("FTVMCompute", MeshgridCompute)
     .set_attr<TOpPattern>("TOpPattern", kInjective);
 
+TVM_REGISTER_NODE_TYPE(SparseReshapeAttrs);
+
+bool SparseReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& 
attrs,
+                      const TypeReporter& reporter) {
+  // types: [sparse_indices, sparse_values, result]
+  // ICHECK_EQ(types.size(), 3);
+  auto sparse_indices = types[0].as<TensorTypeNode>();
+  const auto* param = attrs.as<SparseReshapeAttrs>();
+  CHECK(param != nullptr);
+  Array<PrimExpr> new_sparse_indices_shape{sparse_indices->shape[0],
+                                           
static_cast<int>((param->new_shape).size())};
+  reporter->Assign(types[2], TensorType(new_sparse_indices_shape, 
sparse_indices->dtype));
+  return true;
+}
+
+Array<te::Tensor> SparseReshapeCompute(const Attrs& attrs, const 
Array<te::Tensor>& inputs,
+                                       const Type& out_type) {
+  // ICHECK_EQ(inputs.size(), 2);
+  const auto* param = attrs.as<SparseReshapeAttrs>();
+  CHECK(param != nullptr);

Review comment:
       Done.

##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -1553,6 +1553,52 @@ RELAY_REGISTER_OP("meshgrid")
     .set_attr<FTVMCompute>("FTVMCompute", MeshgridCompute)
     .set_attr<TOpPattern>("TOpPattern", kInjective);
 
+TVM_REGISTER_NODE_TYPE(SparseReshapeAttrs);
+
+bool SparseReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& 
attrs,
+                      const TypeReporter& reporter) {
+  // types: [sparse_indices, sparse_values, result]
+  // ICHECK_EQ(types.size(), 3);
+  auto sparse_indices = types[0].as<TensorTypeNode>();
+  const auto* param = attrs.as<SparseReshapeAttrs>();
+  CHECK(param != nullptr);
+  Array<PrimExpr> new_sparse_indices_shape{sparse_indices->shape[0],
+                                           
static_cast<int>((param->new_shape).size())};
+  reporter->Assign(types[2], TensorType(new_sparse_indices_shape, 
sparse_indices->dtype));
+  return true;
+}
+
+Array<te::Tensor> SparseReshapeCompute(const Attrs& attrs, const 
Array<te::Tensor>& inputs,
+                                       const Type& out_type) {
+  // ICHECK_EQ(inputs.size(), 2);
+  const auto* param = attrs.as<SparseReshapeAttrs>();
+  CHECK(param != nullptr);
+  return {topi::SparseReshape(inputs[0], inputs[1], param->prev_shape, 
param->new_shape)};
+}
+
+Expr MakeSparseReshape(Expr sparse_indices, Expr sparse_values, Array<Integer> 
prev_shape,
+                       Array<Integer> new_shape) {
+  auto attrs = make_object<SparseReshapeAttrs>();
+  attrs->prev_shape = std::move(prev_shape);
+  attrs->new_shape = std::move(new_shape);
+  static const Op& op = Op::Get("sparsereshape");
+  return Call(op, {sparse_indices, sparse_values}, Attrs(attrs), {});
+}
+
+TVM_REGISTER_GLOBAL("relay.op._make.sparsereshape").set_body_typed(MakeSparseReshape);
+
+RELAY_REGISTER_OP("sparsereshape")
+    .describe(R"code(Return twice of normal addition of two tensors.

Review comment:
       Done.




----------------------------------------------------------------
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:
[email protected]


Reply via email to