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



##########
File path: python/tvm/relay/op/transform.py
##########
@@ -1320,3 +1320,47 @@ def adv_index(inputs):
         Output tensor.
     """
     return _make.adv_index(Tuple(inputs))
+
+
+def sparsereshape(sparse_indices, sparse_values, prev_shape, new_shape):
+    """
+    Reshape a Sparse Tensor
+
+    Parameters
+    ----------
+    inputs : List[relay.Expr]
+        Input tensor and indices.
+        The first tensor is input data and rests are indices.
+
+    Returns
+    -------
+    result: relay.Expr
+        Output tensor.
+    Examples
+        --------
+        .. code-block:: python
+
+            sparse_indices = [[0, 0, 0],
+                              [0, 0, 1],
+                              [0, 1, 0],
+                              [1, 0, 0],
+                              [1, 2, 3]]
+
+            sparse_values = [7, 5, 6, 3, 9]
+
+            prev_shape = [2, 3, 4]
+
+            new_shape = [9, -1]
+
+            relay.sparsereshape(sparse_indices,
+                                sparse_values,
+                                prev_shape,
+                                new_shape)
+             =   [[0, 0],
+                  [0, 1],
+                  [1, 2],
+                  [4, 2],
+                  [8, 1]]
+

Review comment:
       Done.

##########
File path: python/tvm/topi/transform.py
##########
@@ -931,3 +931,47 @@ def adv_index(data, indices):
         Output tensor
     """
     return cpp.adv_index(data, indices)
+
+
+def sparsereshape(sparse_indices, sparse_values, prev_shape, new_shape):
+    """
+    Reshape a Sparse Tensor
+
+    Parameters
+    ----------
+    inputs : List[relay.Expr]
+        Input tensor and indices.
+        The first tensor is input data and rests are indices.
+
+    Returns
+    -------
+    result: relay.Expr
+        Output tensor.
+    Examples
+        --------
+        .. code-block:: python
+
+            sparse_indices = [[0, 0, 0],
+                              [0, 0, 1],
+                              [0, 1, 0],
+                              [1, 0, 0],
+                              [1, 2, 3]]
+
+            sparse_values = [7, 5, 6, 3, 9]
+
+            prev_shape = [2, 3, 4]
+
+            new_shape = [9, -1]
+
+            relay.sparsereshape(sparse_indices,
+                                sparse_values,
+                                prev_shape,
+                                new_shape)
+             =   [[0, 0],
+                  [0, 1],
+                  [1, 2],
+                  [4, 2],
+                  [8, 1]]
+

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


Reply via email to