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 02:32:40 UTC

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

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



##########
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:
       Yeah I was thinking of that too, but then since the value of multipliers depends on its later index, it might be a bit non trivial to computer over multipliers. Am I missing something ? I am open to pseudo-code ideas to make it more clean.  




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