Unverified Commit 7cba0d0e authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Cyphers/26mig [MLIR] (#3716)

* Hotfix for negative axes in unsqueeze op (#3705)

* Hotfix for negative axes in unsqueeze op

* Review fix I

* Enable Gather with negative indices. (#3701)

* Enable Gather with negative indices.

* Address PR feedback.

* Remove GOE from Gather unit tests.

* merge error

* Disable test for MLIR
parent 7c84ad26
......@@ -17,6 +17,7 @@
#include "ngraph/op/fused/unsqueeze.hpp"
#include "ngraph/op/constant.hpp"
#include "squeeze.hpp"
#include "utils/common.hpp"
namespace ngraph
{
......@@ -30,8 +31,11 @@ namespace ngraph
{
auto data = node.get_ng_inputs().at(0);
auto axes = node.get_attribute_value<std::vector<std::int64_t>>("axes", {});
const auto expanded_rank = data->get_shape().size() + axes.size();
std::vector<std::size_t> valid_axes =
common::validate_axes(node, axes, expanded_rank);
auto axes_node = std::make_shared<ngraph::op::Constant>(
element::i64, Shape{axes.size()}, axes);
element::i64, Shape{valid_axes.size()}, valid_axes);
return {std::make_shared<ngraph::op::Unsqueeze>(data, axes_node)};
}
......
......@@ -68,6 +68,7 @@ namespace ngraph
{
Eigen::array<Eigen::Index, Rank1> in_dims;
Eigen::array<Eigen::Index, Rank2> out_dims;
auto axis_length = inputs_shape[axis];
for (size_t i = 0; i < Rank1; i++)
{
......@@ -84,6 +85,7 @@ namespace ngraph
static_cast<ElementType*>(inputs), in_dims);
auto indices_ptr = static_cast<IndicesType*>(indices);
IndicesType index_value;
auto indices_rank = indices_shape.size();
auto outer_loop_num = 1;
for (size_t i = 0; i < axis; i++)
......@@ -123,7 +125,10 @@ namespace ngraph
// at axis
in_extents[axis] = 1;
// at axis, get the value from indices arg
in_offsets[axis] = indices_ptr[0];
index_value = indices_ptr[0];
// take care of negative indices
in_offsets[axis] =
index_value >= 0 ? index_value : index_value + axis_length;
// before axis
for (size_t r = 0; r < axis; r++)
......@@ -195,7 +200,10 @@ namespace ngraph
}
// at axis, get the value from indices arg
int k = i % num_indices;
in_offsets[axis] = indices_ptr[k];
index_value = indices_ptr[k];
// take care of negative indices
in_offsets[axis] =
index_value >= 0 ? index_value : index_value + axis_length;
// indices_from_indices_arg depends on indices_shape and k.
// suppose the inputs has shape {3, 3, 3}, indices has shape {2, 2}, and
......
......@@ -64,6 +64,7 @@ gather_2d_indices_axis_1_2d_input
gather_scalar_indices_no_axis_2d_input
gather_1d_indices_no_axis_1d_input
gather_2d_indices_no_axis_2d_input
gather_2d_negative_and_positive_indices_no_axis_2d_input
gather_3d_indices_no_axis_2d_input
gather_4d_indices_no_axis_2d_input
gemm
......
......@@ -199,6 +199,7 @@ gather_4d_indices_no_axis_uint8
gather_4d_indices_no_axis_2d_input
gather_3d_indices_no_axis_2d_input
gather_2d_indices_no_axis_2d_input
gather_2d_negative_and_positive_indices_no_axis_2d_input
gather_1d_indices_no_axis_1d_input
gather_scalar_indices_no_axis_2d_input
gather_2d_indices_axis_1_2d_input
......
......@@ -83,6 +83,8 @@ namespace ngraph
for (size_t i = 0; i < slice_rank; i++)
{
U index = indices[indices_index];
// take care of negative indices
index = index >= 0 ? index : index + params_shape[i];
params_start_corner[i] = index;
params_end_corner[i] = index + 1;
indices_index++;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment