Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple #7230

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/tvm/relay/frontend/mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,11 @@ def _mx_npi_stack(inputs, attrs):
else:
return _op.stack(tuple(inputs), axis=int(axis))

def mx_npi_advanced_indexing_multiple(inputs, attrs):
assert len(inputs) == 2
data = inputs[0]
indices = inputs[1]
return _op.adv_index([data] + indices)

def _mx_npx_reshape(inputs, attrs):
shape = attrs.get_int_tuple("newshape")
Expand Down Expand Up @@ -2709,6 +2714,7 @@ def _mx_npi_where_rscalar(inputs, attrs):
"_npi_tanh": _rename(_op.tanh),
"_npi_true_divide_scalar": _binop_scalar(_op.divide),
"_npi_stack": _mx_npi_stack,
"_npi_advanced_indexing_multiple": mx_npi_advanced_indexing_multiple,
}

# set identity list
Expand Down
37 changes: 37 additions & 0 deletions tests/python/frontend/mxnet/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,43 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))


@pytest.mark.parametrize(
"data_shape, row_sel, col",
[
(
(5, 7),
(
0,
1,
2,
3,
4,
),
2,
),
],
)
@pytest.mark.parametrize("dtype", ["float64", "float32"])
@tvm.testing.parametrize_targets
@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
def test_forward_npi_advanced_indexing_multiple(data_shape, row_sel, col, dtype, target, ctx, kind):
data_np = np.random.uniform(size=data_shape).astype(dtype)
ref_res = mx.np.array(data_np)[row_sel, col]

row_sel_sym = mx.sym.var("row_sel").as_np_ndarray()
data_sym = mx.sym.var("data").as_np_ndarray()
col_sym = mx.sym.var("col").as_np_ndarray()
mx_sym = data_sym[row_sel_sym, col_sym]

mod, _ = relay.frontend.from_mxnet(
mx_sym, shape={"data": data_shape, "row_sel": row_sel, "col": col}, dtype=dtype
)
intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
op_res = intrp.evaluate()(data_np)
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy(), rtol=1e-5)
tvm.testing.assert_allclose(ref_res.asnumpy(), ref_res.asnumpy(), rtol=1e-5)


@pytest.mark.skipif(not hasattr(mx.sym.np, "pad"), reason="mx.sym.np.pad hasn't been publish yet")
@pytest.mark.parametrize(
"data_shape, pad_width",
Expand Down