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

[Relay] add ShapeFunc for one_hot op #7490

Merged
merged 3 commits into from
Mar 8, 2021
Merged
Changes from 2 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
25 changes: 25 additions & 0 deletions python/tvm/relay/op/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,31 @@ def strided_slice_shape_func(attrs, inputs, _):
]


@script
def _one_hot_shape_func(indices_shape, depth, axis):
in_ndim = indices_shape.shape[0]
out_ndim = in_ndim + 1
true_axis = in_ndim if axis == -1 else axis
indices_i = 0
out = output_tensor((out_ndim,), "int64")
for i in range(out_ndim):
if i == true_axis:
out[i] = int64(depth)
else:
out[i] = int64(indices_shape[indices_i])
indices_i += 1
return out


@_reg.register_shape_func("one_hot", False)
def one_hot_shape_func(attrs, inputs, _):
"""
Shape func for one_hot
"""
shape_func = [_one_hot_shape_func(inputs[0], convert(attrs.depth), convert(attrs.axis))]
return shape_func


@script
def _concatenate_shape_func(inputs, axis):
ndim = inputs[0].shape[0]
Expand Down