codeislife99 commented on a change in pull request #7562:
URL: https://github.com/apache/tvm/pull/7562#discussion_r585912110
##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -1515,6 +1516,95 @@ def verify_sparse_reshape(
)
[email protected]_gpu
[email protected](
+ "data_np, indices_np, num_segments",
+ [
+ (
+ np.array([5, 1, 7, 2, 3, 4], dtype=np.float32),
+ np.array([0, 0, 1, 1, 0, 1], dtype=np.int32),
+ None,
+ ),
+ (
+ np.array([[1, 2, 3, 4], [-1, -2, -3, -4], [5, 6, 7, 8]],
dtype=np.float64),
+ np.array([0, 0, 1], dtype=np.int32),
+ None,
+ ),
+ (
+ np.random.random((6, 4, 5)),
+ np.array([2, 0, 1, 0, 3, 2], dtype=np.int32),
+ None,
+ ),
+ (
+ np.array([[[1, 7]], [[3, 8]], [[2, 9]]], dtype=np.float32),
+ np.array([0, 0, 1], dtype=np.int32),
+ None,
+ ),
+ (
+ np.random.random((9, 4, 5, 7)),
+ np.array([5, 0, 1, 0, 3, 6, 8, 7, 7], dtype=np.int32),
+ 9,
+ ),
+ ],
+)
[email protected]("use_dyn", [True, False])
+def test_segment_sum(data_np, indices_np, num_segments, use_dyn):
+ def ref_segment_sum(
+ data: np.ndarray,
+ indices: np.ndarray,
+ num_segments: Optional[int] = None,
+ ):
+ """
+ This function calculates the expected output of sparseshape operator
given the inputs.
Review comment:
Done.
##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -1515,6 +1516,95 @@ def verify_sparse_reshape(
)
[email protected]_gpu
[email protected](
+ "data_np, indices_np, num_segments",
+ [
+ (
+ np.array([5, 1, 7, 2, 3, 4], dtype=np.float32),
+ np.array([0, 0, 1, 1, 0, 1], dtype=np.int32),
+ None,
+ ),
+ (
+ np.array([[1, 2, 3, 4], [-1, -2, -3, -4], [5, 6, 7, 8]],
dtype=np.float64),
+ np.array([0, 0, 1], dtype=np.int32),
+ None,
+ ),
+ (
+ np.random.random((6, 4, 5)),
+ np.array([2, 0, 1, 0, 3, 2], dtype=np.int32),
+ None,
+ ),
+ (
+ np.array([[[1, 7]], [[3, 8]], [[2, 9]]], dtype=np.float32),
+ np.array([0, 0, 1], dtype=np.int32),
+ None,
+ ),
+ (
+ np.random.random((9, 4, 5, 7)),
+ np.array([5, 0, 1, 0, 3, 6, 8, 7, 7], dtype=np.int32),
+ 9,
+ ),
+ ],
+)
[email protected]("use_dyn", [True, False])
+def test_segment_sum(data_np, indices_np, num_segments, use_dyn):
+ def ref_segment_sum(
+ data: np.ndarray,
+ indices: np.ndarray,
+ num_segments: Optional[int] = None,
+ ):
+ """
+ This function calculates the expected output of sparseshape operator
given the inputs.
+ """
+ if not num_segments:
+ num_segments = np.unique(indices).shape[0]
+
+ result = np.zeros((num_segments,) + data.shape[1:], data.dtype)
+ for i, index in enumerate(indices):
+ result[index] += data[i]
+ return result
+
+ def verify_segment_sum(
+ data_np: np.ndarray, indices_np: np.ndarray, num_segments:
Optional[int]
+ ):
+ """
+ This function verifies the relay output of sparse_reshape with its
expected output.
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]