Commit f8c4a44e authored by Adam Procter's avatar Adam Procter

Add test generator for DynSlice

parent 080d4f95
......@@ -240,7 +240,15 @@ void op::DynSlice::validate_and_infer_types()
shared_ptr<Node> op::DynSlice::copy_with_new_args(const NodeVector& new_args) const
{
check_new_args_count(this, new_args);
return make_shared<DynSlice>(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3));
return make_shared<DynSlice>(new_args.at(0),
new_args.at(1),
new_args.at(2),
new_args.at(3),
m_lower_bounds_mask,
m_upper_bounds_mask,
m_new_axis,
m_shrink_axis,
m_ellipsis_mask);
}
void op::DynSlice::generate_adjoints(autodiff::Adjoints& adjoints, const NodeVector& deltas)
......
......@@ -153,7 +153,11 @@ static SlicePlan make_plan(const Shape& input_shape,
}
}
NGRAPH_CHECK(num_real_axes <= input_shape.size());
NGRAPH_CHECK(num_real_axes <= input_shape.size(),
"num_real_axes=",
num_real_axes,
", input_shape=",
input_shape);
// Figure out how many axes need to be inserted when the ellipsis (which
// may be an implicit ellipsis at the end) is expanded.
......
......@@ -170,6 +170,7 @@ set(MULTI_TEST_SRC
backend_test.in.cpp
backend_unary_elementwise.in.cpp
convolution_test.in.cpp
dyn_slice_test.in.cpp
dynamic.in.cpp
)
......
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
// !!!!!!!!!!!!!! THIS FILE IS AUTOGENERATED OUTSIDE OF THE BUILD PROCESS !!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT EDIT THIS FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// DO NOT EDIT THIS FILE. If you want to add new tests, you should edit
// test/ref_generators/generate_dyn_slice_ref.py and regenerate this file.
//
// To regenerate:
//
// $ cd <ngraph source dir>/test
// $ ./update_dyn_slice_reference.sh
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT EDIT THIS FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!! THIS FILE IS AUTOGENERATED OUTSIDE OF THE BUILD PROCESS !!!!!!!!!!!!!!
//
// clang-format off
#include <cmath>
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/test_tools.hpp"
#include "util/autodiff/numeric_compare.hpp"
#include "util/all_close_f.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, dyn_slice)
{
{
auto arg = std::make_shared<op::Parameter>(element::i32, Shape{4});
auto lb = std::make_shared<op::Parameter>(element::i64, Shape{2});
auto ub = std::make_shared<op::Parameter>(element::i64, Shape{2});
auto strides = std::make_shared<op::Parameter>(element::i64, Shape{2});
std::vector<int32_t> input_values{0,1,2,3};
std::vector<int64_t> lb_values{0,3};
std::vector<int64_t> ub_values{0,0};
std::vector<int64_t> strides_values{1,-1};
AxisSet lb_mask{};
AxisSet ub_mask{};
AxisSet new_mask{0};
AxisSet shrink_mask{};
AxisSet ellipsis_mask{};
auto slice = std::make_shared<op::DynSlice>(arg, lb, ub, strides, lb_mask, ub_mask, new_mask, shrink_mask, ellipsis_mask);
auto f = std::make_shared<Function>(NodeVector{slice},ParameterVector{arg, lb, ub, strides});
auto backend = runtime::Backend::create("${BACKEND_NAME}",true);
auto ex = backend->compile(f);
auto input_arg = backend->create_tensor(element::i32,Shape{4});
auto input_lb = backend->create_tensor(element::i64,Shape{2});
auto input_ub = backend->create_tensor(element::i64,Shape{2});
auto input_strides = backend->create_tensor(element::i64,Shape{2});
copy_data(input_arg, input_values);
copy_data(input_lb, lb_values);
copy_data(input_ub, ub_values);
copy_data(input_strides, strides_values);
auto output = backend->create_dynamic_tensor(element::i32,PartialShape::dynamic());
ex->call({output}, {input_arg, input_lb, input_ub, input_strides});
EXPECT_EQ(output->get_element_type(), (element::i32));
EXPECT_EQ(output->get_shape(), (Shape{1,3}));
auto output_values = read_vector<int32_t>(output);
std::vector<int32_t> expected_values{3,2,1};
EXPECT_EQ(output_values, expected_values);
}
}
// clang-format on
This diff is collapsed.
#!/bin/bash
# ******************************************************************************
# Copyright 2017-2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
declare THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
python ${THIS_SCRIPT_DIR}/ref_generators/generate_dyn_slice_ref.py ${THIS_SCRIPT_DIR}/dyn_slice_test.in.cpp
#!/bin/bash
# ******************************************************************************
# Copyright 2017-2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
declare THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
python ${THIS_SCRIPT_DIR}/ref_generators/generate_convolution_ref.py ${THIS_SCRIPT_DIR}/convolution_test.in.cpp
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