siju-samuel commented on a change in pull request #5447: URL: https://github.com/apache/incubator-tvm/pull/5447#discussion_r428559052
########## File path: topi/python/topi/transform.py ########## @@ -676,3 +676,32 @@ def unravel_index(indices, shape): """ return cpp.unravel_index(indices, shape) + +def sparse_to_dense(sparse_indices, sparse_values, default_value, output_shape): Review comment: Can you please assign default_value=0 in all places so that it will be optional. ########## File path: topi/include/topi/transform.h ########## @@ -1309,5 +1309,57 @@ inline Tensor one_hot(const Tensor& indices, const PrimExpr on_value, const Prim name, tag); } +/*! + * \brief Get a dense tensor. + * \param sparse_indices sparse_indices[i] contains the complete index where sparse_values[i] will be placed. + * \param sparse_values is a 0-D or 1-D tensor. Values corresponding to each row of sparse_indices + * \param default_value is a 0-D tensor. Defaults to zero. + * \param output_shape is the shape of the dense output tensor + * \param name output tensor name. + * \param tag output tensor tag. + * \return Tensor of output_shape. + */ +inline Tensor sparse_to_dense(const Tensor& sparse_indices, + const Tensor& sparse_values, + const Tensor& default_value, + const Array<Integer>& output_shape, Review comment: is output_shape mandatory to compute the outputs? tf2.0 removed output_shape. if your topi func is compatible with all frameworks, then it will be better. ########## File path: topi/include/topi/transform.h ########## @@ -1309,5 +1309,57 @@ inline Tensor one_hot(const Tensor& indices, const PrimExpr on_value, const Prim name, tag); } +/*! + * \brief Get a dense tensor. + * \param sparse_indices sparse_indices[i] contains the complete index where sparse_values[i] will be placed. + * \param sparse_values is a 0-D or 1-D tensor. Values corresponding to each row of sparse_indices + * \param default_value is a 0-D tensor. Defaults to zero. + * \param output_shape is the shape of the dense output tensor + * \param name output tensor name. + * \param tag output tensor tag. + * \return Tensor of output_shape. + */ +inline Tensor sparse_to_dense(const Tensor& sparse_indices, + const Tensor& sparse_values, + const Tensor& default_value, + const Array<Integer>& output_shape, + const std::string name = "T_sparse_to_dense", + const std::string tag = kInjective) { + CHECK(sparse_indices->dtype.is_int()) + << "sparse_indices only accepts integer values"; + + CHECK_LE(sparse_indices->shape.size(), 3) + << "sparse_indices tensor should be 0D, 1D, or 2D only"; + + CHECK_LE(sparse_values->shape.size(), 2) + << "sparse_values tensor should be 0D or 1D only"; + + const auto rank_sparse_indices = static_cast<int>(sparse_indices->shape.size()); Review comment: validate_indices flag has any change in behavior? if so, consider that as well. [Reference](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/sparse/to_dense) ---------------------------------------------------------------- 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