NVukobrat opened a new issue, #12292:
URL: https://github.com/apache/tvm/issues/12292
Hi,
I’m trying to index the tensor in the following fashion:
```py
x[0, mask]
```
where x is the input tensor (e.g. (2, 3) shape), while the mask is a boolean
array (e.g. (3,) shape). For a better example, here are example values:
```py
x = [
[1, 2, 3],
[4, 5, 6]
]
mask = [True, True, False]
```
Therefore, when using NumPy as a reference, the results of `x[0, mask]`
should be `[1, 2]` tensor. However, as TVM output I’m getting something like
`[2, 2, 1]`. Can someone provide me with more information on this topic?
Also, for easier reproduction, below is TVM test similar to the example
below (test is added and run from the following test file):
```py
tests/python/relay/test_op_level3.py
```
Unit test:
```py
def test_adv_index_with_mask(target, dev, executor_kind):
def verify_adv_index(data_shape, index, bool_mask_shape):
dtype = "float32"
inputs = [relay.var("data", relay.TensorType(data_shape, dtype))]
np_data = np.random.uniform(size=data_shape).astype(dtype)
np_indices = np.ones(bool_mask_shape, dtype=bool)
np_indices[-1] = False
inputs.append(relay.var("index_{}".format(index), shape=(),
dtype="int"))
inputs.append(relay.var("mask_{}".format(index),
relay.TensorType(bool_mask_shape, "bool")))
np_out = np_data[index, np_indices]
np_args = [np_data] + [index, np_indices]
out = relay.op.adv_index(inputs)
func = relay.Function(inputs, out)
op_res = relay.create_executor(executor_kind, device=dev,
target=target).evaluate(func)(
*np_args
)
tvm.testing.assert_allclose(op_res.numpy(), np_out, rtol=1e-5)
verify_adv_index((2, 3), 1, (3,))
```
Lastly, this issue is also [posted yesterday on the discussion
board](https://discuss.tvm.apache.org/t/tensor-advanced-indexing-with-boolean-mask/13257)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]