ymwangg commented on pull request #7441:
URL: https://github.com/apache/tvm/pull/7441#issuecomment-780387355


   @masahi Thanks for the explanation and it is very helpful!
   It looks like the main thing we need to do is to implement a 
`topi.adjacent_difference` op similar to `thrust::adjacent_difference`. And in 
the frontend, we do something like:
   ```python
   sorted_data = relay.sort(data)
   argsort_indices = relay.argsort(data)
   adj_diff = relay.adjacent_difference(sorted_data, first_value=0, "not_equal")
   ex_scan = relay.cumsum(adj_diff, exclusive=True)
   inverse_indices = relay.scatter(data, argsort_indices, ex_scan)
   unique = relay.scatter(data, ex_scan, sorted_data)
   unique_sliced = relay.strided_slice(unique, [0], relay.take(ex_scan,[-1]), 
slice_mode="size")
   return unique_sliced, inverse_indices
   ```
   I saw PyTorch uses `thrust::unique` to get the `unique` array. I think we 
can use `relay.scatter` to do the same thing.
   
   To support counting, it looks like we need to implement a 
`topi.unique_by_key` op similar to `thrust::unique_by_key`. I think maybe we 
can do it in a different PR and focus on `adjacent_difference` in this PR.


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


Reply via email to