You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/12/18 01:49:34 UTC

[GitHub] [tvm] trevor-m commented on a change in pull request #7125: Sparse reshape op

trevor-m commented on a change in pull request #7125:
URL: https://github.com/apache/tvm/pull/7125#discussion_r545520606



##########
File path: include/tvm/topi/transform.h
##########
@@ -1386,6 +1386,85 @@ inline Array<Tensor> meshgrid(const Array<Tensor>& inputs, const std::string& in
   return result;
 }
 
+/*!
+ * \brief Compute new sparse indices and return them after the sparsereshape operation
+ *
+ * \param sparse_indices Indices where values of the dense tensor exist
+ * \param sparse_values Values at the above indices respectively
+ * \param prev_shape Old Shape of the sparse tensor corresponding to sparse_indices
+ * \param new_shape Desired Shape of the sparse tensor which will correspond to output
+ * \param name The name of the operation
+ * \param tag The tag to mark the operation
+ *
+ * \return A Tensor whose op member is the sparsereshape operation
+ */
+
+inline Array<Tensor> SparseReshape(const Tensor& sparse_indices, const Tensor& sparse_values,
+                                   const Tensor& prev_shape, const Tensor& new_shape,
+                                   const std::string name = "T_sparsereshape",
+                                   std::string tag = kInjective) {
+  Array<Tensor> result;
+  Array<PrimExpr> new_sparse_indices_shape{sparse_indices->shape[0], new_shape->shape[0]};
+  std::vector<PrimExpr> multipliers(GetConstInt(prev_shape->shape[0]), 1);
+  std::vector<PrimExpr> dividers(GetConstInt(new_shape->shape[0]), 1);
+
+  tvm::te::compute(Array<PrimExpr>{1}, [&](const Array<Var>& indices) {

Review comment:
       This compute looks weird to me since it isn’t returning anything. I think it’s better to determine multipliers shape, do a compute over that shape to initialize multipliers, rather than a compute over [1] which has internal loops. And same for dividers.
   
   Can someone with more experience here chime in?




----------------------------------------------------------------
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:
users@infra.apache.org