-
Notifications
You must be signed in to change notification settings - Fork 621
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
Add Expand dims operator #2800
Add Expand dims operator #2800
Conversation
std::vector<int>(), true) | ||
.AddOptionalArg("new_axis_names", R"code(Names of new dimensions in data layout. | ||
|
||
Size of ``new_axis_names`` should be equal to ``axe``s size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The length of new_axis_names
must match the length of axes
.
} | ||
out_layout += in_layout.empty() ? '?' : in_layout[d]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the input doesn't have a well defined layout, the output layout should also be empty.
The logic should be something like:
if (1) input has layout
if (2) new_axis_names_ match the length of axes:
output layout is a product of inserting new_axis_names at `axes`
else
either (3) reset layout to empty or (4) insert `?`
else
(5) output layout is empty
(1) - We should assume that 0D input with empty layout has proper layout
(2) - This differs from new_axis_names.empty()
in case when axes
are also empty
(3) - This is consistent with (5) for 0D and >0D
(4) - This is inconsistent
Elaborating on inconsistency between (4) and (5):
A 0D has both specified and empty layout (layout is not a nullable property).
Now, if we insert ?
, a 0D tensor will never be expanded to one with empty layout, even though it's very likely that the user wants it - instead, the tensor will get a (possibly invalid) layout with multiple ?
inserted.
Examples of the proposed logic:
ndim = 2
layout = HW
axes = [2]
axis_names = C
output layout HWC
ndim = 2
layout
axes = [2]
axis_names = 'C'
output: error - specifying axis names requires an input with a proper layuout
ndim = 2
layout = HW
axes = []
new_axis_names = ""
output layout = HW
ndim = 0
layout = ""
axes = [0, 1]
new_axis_names = "HW"
output layout = HW
ndim = 0
layout = ""
axes = [0, 1]
new_axis_names = ""
output layout = ""
ndim = 2
layout = "HW"
axes = [0]
new_axis_names = ""
output layout = ""
.DocStr(R"code(Insert new dimension[s] of extent 1 and inserts new entries in " | ||
"the layout (new_axis_names) at these indices in the layout.)code") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a shorter first description for the table of operators.
I'd say
.DocStr(R"code(Insert new dimension[s] of extent 1 and inserts new entries in " | |
"the layout (new_axis_names) at these indices in the layout.)code") | |
.DocStr(R"code(Insert new dimension(s) with extent 1 to the data shape. | |
The new dimensions are inserted at the positions specified by ``axes``. | |
If ``new_axis_names`` is provided, the new dimension names will be inserted in the data layout, at the positions specified by ``axes``. If ``new_axis_names`` is not provided, the output data layout will be empty.")code") |
.PassThrough({{0, 0}}) | ||
.AllowSequences() | ||
.SupportVolumetric() | ||
.AddOptionalArg<int>("axes", R"code(Indices where to put new dimensions of size 1.)code", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.AddOptionalArg<int>("axes", R"code(Indices where to put new dimensions of size 1.)code", | |
.AddOptionalArg<int>("axes", R"code(Indices representing the positions in the data shape where a new dimension with extent 1 will be inserted. | |
The indices should be in the range ``[0, ndim]``, where ``ndim`` is the number of dimensions in the input. Providing the index ``ndim`` results in a new dimension appended at the end of the shape.)code", |
.SupportVolumetric() | ||
.AddOptionalArg<int>("axes", R"code(Indices where to put new dimensions of size 1.)code", | ||
std::vector<int>(), true) | ||
.AddOptionalArg("new_axis_names", R"code(Names of new dimensions in data layout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.AddOptionalArg("new_axis_names", R"code(Names of new dimensions in data layout. | |
.AddOptionalArg("new_axis_names", R"code(Names of the new dimensions in the data layout. |
new_axis_names_ = spec.GetArgument<TensorLayout>("new_axis_names"); | ||
if (!new_axis_names_.empty()) { | ||
DALI_ENFORCE(new_axis_names_.size() == axes_.size(), make_string("Specified ", axes_.size(), | ||
" new dimensions, but layout specify ", new_axis_names_.size(), " new names")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" new dimensions, but layout specify ", new_axis_names_.size(), " new names")); | |
" new dimensions, but layout contains only ", new_axis_names_.size(), " new dimension names")); |
.PassThrough({{0, 0}}) | ||
.AllowSequences() | ||
.SupportVolumetric() | ||
.AddOptionalArg<int>("axes", R"code(Indices where to put new dimensions of size 1.)code", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.AddOptionalArg<int>("axes", R"code(Indices where to put new dimensions of size 1.)code", | |
.AddOptionalArg<int>("axes", R"code(Indices at which the new dimensions are inserted. | |
.)code", |
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
.AddOptionalArg("new_axis_names", R"code(Names of the new dimensions in the data layout. | ||
|
||
The length of ``new_axis_names`` must match the length of ``axes``. | ||
If argument won't be provided new dimensions will have layout '?')code", TensorLayout("")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If argument won't be provided new dimensions will have layout '?')code", TensorLayout("")); | |
If argument isn't be provided new dimensions will have layout '?')code", TensorLayout("")); |
.AddOptionalArg("new_axis_names", R"code(Names of the new dimensions in the data layout. | ||
|
||
The length of ``new_axis_names`` must match the length of ``axes``. | ||
If argument won't be provided layout will be cleared.)code", TensorLayout("")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If argument won't be provided layout will be cleared.)code", TensorLayout("")); | |
If argument is not provided, output layout will be cleared.)code", TensorLayout("")); |
or
If argument won't be provided layout will be cleared.)code", TensorLayout("")); | |
If argument is not provided, the layout will be cleared.)code", TensorLayout("")); |
ExpandDims<Backend>::ExpandDims(const OpSpec &spec) | ||
: Reshape<Backend>(spec, typename Reshape<Backend>::BypassInit()) { | ||
axes_ = spec.GetRepeatedArgument<int>("axes"); | ||
DALI_ENFORCE(spec.HasArgument("axes"), make_string("``axes`` argument should be provided.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary. Just make the argument mandatory in the schema.
.AddOptionalArg<int>("axes", R"code(Indices at which the new dimensions are inserted.)code", | ||
std::vector<int>(), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.AddOptionalArg<int>("axes", R"code(Indices at which the new dimensions are inserted.)code", | |
std::vector<int>(), true) | |
.AddArg("axes", R"code(Indices at which the new dimensions are inserted.)code", | |
DALI_INT_VEC, true) |
} | ||
std::sort(axes_.begin(), axes_.end()); | ||
DALI_ENFORCE(std::adjacent_find(axes_.begin(), axes_.end()) == axes_.end(), | ||
make_string("Specified at least twice same index to add new dimension.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make_string("Specified at least twice same index to add new dimension.")); | |
make_string("Duplicate axis index found.")); |
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
auto in_layout = in.GetLayout(); | ||
if (in_layout.empty() && ndim) { | ||
DALI_ENFORCE(!use_new_axis_names_arg_, | ||
make_string("Specifying ``new_axis_names`` requires an input with a proper layuout.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make_string("Specifying ``new_axis_names`` requires an input with a proper layuout.")); | |
make_string("Specifying ``new_axis_names`` requires an input with a proper layout.")); |
Signed-off-by: Rafal Maj <rmaj@nvidia.com>
!build |
CI MESSAGE: [2179748]: BUILD STARTED |
CI MESSAGE: [2179748]: BUILD PASSED |
Why we need this PR?
What happened in this PR?
NA
JIRA TASK: DALI-1851