Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
3f68b549
Commit
3f68b549
authored
Jun 07, 2019
by
Adam Procter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests (one not passing)
parent
f8c4a44e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
912 additions
and
17 deletions
+912
-17
dyn_slice_test.in.cpp
test/dyn_slice_test.in.cpp
+864
-7
generate_dyn_slice_ref.py
test/ref_generators/generate_dyn_slice_ref.py
+48
-10
No files found.
test/dyn_slice_test.in.cpp
View file @
3f68b549
...
...
@@ -30,6 +30,7 @@
//
// clang-format off
#include <algorithm>
#include <cmath>
#include "gtest/gtest.h"
...
...
@@ -53,7 +54,8 @@ NGRAPH_TEST(${BACKEND_NAME}, dyn_slice)
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
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
,
3
};
std
::
vector
<
int64_t
>
ub_values
{
0
,
0
};
std
::
vector
<
int64_t
>
strides_values
{
1
,
-
1
};
...
...
@@ -65,21 +67,21 @@ NGRAPH_TEST(${BACKEND_NAME}, dyn_slice)
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
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
});
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
());
auto
output
=
backend
->
create_dynamic_tensor
(
element
::
i32
,
PartialShape
::
dynamic
());
ex
->
call
({
output
},
{
input_arg
,
input_lb
,
input_ub
,
input_strides
});
...
...
@@ -91,6 +93,861 @@ NGRAPH_TEST(${BACKEND_NAME}, dyn_slice)
std
::
vector
<
int32_t
>
expected_values
{
3
,
2
,
1
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
1
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
AxisSet
shrink_mask
{};
AxisSet
ellipsis_mask
{
0
};
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
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
4
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
1
,
2
,
3
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
1
};
std
::
vector
<
int64_t
>
ub_values
{
3
};
std
::
vector
<
int64_t
>
strides_values
{
1
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
1
,
2
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
2
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
1
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
AxisSet
shrink_mask
{
0
};
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
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
2
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
3
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
-
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
3
,
1
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
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
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
,
4
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
1
,
2
,
3
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
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
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
,
0
};
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
,
1
};
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
,
1
,
4
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
1
,
2
,
3
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
4
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
4
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
4
});
std
::
vector
<
int32_t
>
input_values
(
4
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
,
0
,
0
,
0
};
std
::
vector
<
int64_t
>
ub_values
{
0
,
0
,
0
,
0
};
std
::
vector
<
int64_t
>
strides_values
{
1
,
1
,
1
,
1
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{
0
,
1
,
3
};
AxisSet
shrink_mask
{};
AxisSet
ellipsis_mask
{
2
};
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
{
4
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
4
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
4
});
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
,
1
,
4
,
1
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
1
,
2
,
3
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
3
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
-
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
3
,
1
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
3
};
std
::
vector
<
int64_t
>
strides_values
{
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
2
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
4
};
std
::
vector
<
int64_t
>
strides_values
{
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
2
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
5
};
std
::
vector
<
int64_t
>
strides_values
{
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
3
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
2
,
4
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
6
};
std
::
vector
<
int64_t
>
strides_values
{
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
3
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
2
,
4
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
};
std
::
vector
<
int64_t
>
ub_values
{
100
};
std
::
vector
<
int64_t
>
strides_values
{
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
3
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
0
,
2
,
4
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
4
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
-
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
4
,
2
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
4
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
-
3
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
4
,
1
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
5
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
1
});
std
::
vector
<
int32_t
>
input_values
(
5
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
4
};
std
::
vector
<
int64_t
>
ub_values
{
0
};
std
::
vector
<
int64_t
>
strides_values
{
-
2
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{
0
};
AxisSet
new_mask
{};
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
{
5
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
1
});
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
{
3
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
4
,
2
,
0
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
2
,
3
,
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
(
24
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
1
,
0
};
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
{
1
};
AxisSet
shrink_mask
{
0
};
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
{
2
,
3
,
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
,
4
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
2
,
3
,
4
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
3
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
3
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
3
});
std
::
vector
<
int32_t
>
input_values
(
24
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
-
1
,
-
1
,
0
};
std
::
vector
<
int64_t
>
ub_values
{
0
,
0
,
0
};
std
::
vector
<
int64_t
>
strides_values
{
1
,
1
,
1
};
AxisSet
lb_mask
{};
AxisSet
ub_mask
{};
AxisSet
new_mask
{
2
};
AxisSet
shrink_mask
{
0
,
1
};
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
{
2
,
3
,
4
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
3
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
3
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
3
});
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
,
4
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
20
,
21
,
22
,
23
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
{
auto
arg
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i32
,
Shape
{
2
,
4
,
6
,
8
,
2
,
2
,
2
});
auto
lb
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
7
});
auto
ub
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
7
});
auto
strides
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
i64
,
Shape
{
7
});
std
::
vector
<
int32_t
>
input_values
(
3072
);
std
::
iota
(
input_values
.
begin
(),
input_values
.
end
(),
static_cast
<
int32_t
>
(
0
));
std
::
vector
<
int64_t
>
lb_values
{
0
,
0
,
2
,
7
,
0
,
0
,
1
};
std
::
vector
<
int64_t
>
ub_values
{
0
,
4
,
6
,
3
,
0
,
0
,
0
};
std
::
vector
<
int64_t
>
strides_values
{
1
,
1
,
2
,
-
2
,
1
,
1
,
1
};
AxisSet
lb_mask
{
1
};
AxisSet
ub_mask
{
0
};
AxisSet
new_mask
{
4
};
AxisSet
shrink_mask
{
6
};
AxisSet
ellipsis_mask
{
5
};
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
{
2
,
4
,
6
,
8
,
2
,
2
,
2
});
auto
input_lb
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
7
});
auto
input_ub
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
7
});
auto
input_strides
=
backend
->
create_tensor
(
element
::
i64
,
Shape
{
7
});
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
{
2
,
4
,
2
,
2
,
1
,
2
,
2
}));
auto
output_values
=
read_vector
<
int32_t
>
(
output
);
std
::
vector
<
int32_t
>
expected_values
{
185
,
187
,
189
,
191
,
169
,
171
,
173
,
175
,
313
,
315
,
317
,
319
,
297
,
299
,
301
,
303
,
569
,
571
,
573
,
575
,
553
,
555
,
557
,
559
,
697
,
699
,
701
,
703
,
681
,
683
,
685
,
687
,
953
,
955
,
957
,
959
,
937
,
939
,
941
,
943
,
1081
,
1083
,
1085
,
1087
,
1065
,
1067
,
1069
,
1071
,
1337
,
1339
,
1341
,
1343
,
1321
,
1323
,
1325
,
1327
,
1465
,
1467
,
1469
,
1471
,
1449
,
1451
,
1453
,
1455
,
1721
,
1723
,
1725
,
1727
,
1705
,
1707
,
1709
,
1711
,
1849
,
1851
,
1853
,
1855
,
1833
,
1835
,
1837
,
1839
,
2105
,
2107
,
2109
,
2111
,
2089
,
2091
,
2093
,
2095
,
2233
,
2235
,
2237
,
2239
,
2217
,
2219
,
2221
,
2223
,
2489
,
2491
,
2493
,
2495
,
2473
,
2475
,
2477
,
2479
,
2617
,
2619
,
2621
,
2623
,
2601
,
2603
,
2605
,
2607
,
2873
,
2875
,
2877
,
2879
,
2857
,
2859
,
2861
,
2863
,
3001
,
3003
,
3005
,
3007
,
2985
,
2987
,
2989
,
2991
};
EXPECT_EQ
(
output_values
,
expected_values
);
}
}
// clang-format on
test/ref_generators/generate_dyn_slice_ref.py
View file @
3f68b549
...
...
@@ -210,15 +210,24 @@ class SliceTestWriter:
self
.
_stream
=
stream
def
__getitem__
(
self
,
slices
):
self
.
write_test
(
slices
)
def
write_test
(
self
,
slices
):
data_in
=
np
.
linspace
(
0
,
np
.
prod
(
self
.
_shape
)
-
1
,
np
.
prod
(
self
.
_shape
),
dtype
=
self
.
_dtype
)
.
reshape
(
self
.
_shape
)
data_out
=
data_in
.
__getitem__
(
slices
)
n_slices
=
1
try
:
n_slices
=
len
(
slices
)
except
TypeError
:
pass
self
.
_stream
.
write
(
' {
\n
'
)
self
.
_stream
.
write
(
' auto arg = std::make_shared<op::Parameter>(
%
s,
%
s);
\n
'
%
(
np_dt_to_ng
(
self
.
_dtype
),
print_shape
(
self
.
_shape
)))
self
.
_stream
.
write
(
' auto lb = std::make_shared<op::Parameter>(element::i64,
%
s);
\n
'
%
print_shape
((
len
(
slices
)
,)))
self
.
_stream
.
write
(
' auto ub = std::make_shared<op::Parameter>(element::i64,
%
s);
\n
'
%
print_shape
((
len
(
slices
)
,)))
self
.
_stream
.
write
(
' auto strides = std::make_shared<op::Parameter>(element::i64,
%
s);
\n
'
%
print_shape
((
len
(
slices
)
,)))
self
.
_stream
.
write
(
' auto lb = std::make_shared<op::Parameter>(element::i64,
%
s);
\n
'
%
print_shape
((
n_slices
,)))
self
.
_stream
.
write
(
' auto ub = std::make_shared<op::Parameter>(element::i64,
%
s);
\n
'
%
print_shape
((
n_slices
,)))
self
.
_stream
.
write
(
' auto strides = std::make_shared<op::Parameter>(element::i64,
%
s);
\n
'
%
print_shape
((
n_slices
,)))
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' std::vector<
%
s> input_values{
%
s};
\n
'
%
(
np_dt_to_c
(
self
.
_dtype
),
print_values
(
data_in
.
reshape
(
-
1
))))
self
.
_stream
.
write
(
' std::vector<
%
s> input_values(
%
s);
\n
'
%
(
np_dt_to_c
(
self
.
_dtype
),
np
.
prod
(
self
.
_shape
)))
self
.
_stream
.
write
(
' std::iota(input_values.begin(), input_values.end(), static_cast<
%
s>(0));
\n
'
%
np_dt_to_c
(
self
.
_dtype
))
self
.
_stream
.
write
(
' std::vector<int64_t> lb_values{
%
s};
\n
'
%
print_lb_values
(
slices
))
self
.
_stream
.
write
(
' std::vector<int64_t> ub_values{
%
s};
\n
'
%
print_ub_values
(
slices
))
self
.
_stream
.
write
(
' std::vector<int64_t> strides_values{
%
s};
\n
'
%
print_stride_values
(
slices
))
...
...
@@ -230,21 +239,21 @@ class SliceTestWriter:
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' auto slice = std::make_shared<op::DynSlice>(arg, lb, ub, strides, lb_mask, ub_mask, new_mask, shrink_mask, ellipsis_mask);
\n
'
)
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' auto f = std::make_shared<Function>(NodeVector{slice},ParameterVector{arg, lb, ub, strides});
\n
'
)
self
.
_stream
.
write
(
' auto f = std::make_shared<Function>(NodeVector{slice},
ParameterVector{arg, lb, ub, strides});
\n
'
)
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' auto backend = runtime::Backend::create("${BACKEND_NAME}",true);
\n
'
)
self
.
_stream
.
write
(
' auto ex = backend->compile(f);
\n
'
)
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' auto input_arg = backend->create_tensor(
%
s,
%
s);
\n
'
%
(
np_dt_to_ng
(
self
.
_dtype
),
print_shape
(
self
.
_shape
)))
self
.
_stream
.
write
(
' auto input_lb = backend->create_tensor(element::i64,
%
s);
\n
'
%
print_shape
((
len
(
slices
)
,)))
self
.
_stream
.
write
(
' auto input_ub = backend->create_tensor(element::i64,
%
s);
\n
'
%
print_shape
((
len
(
slices
)
,)))
self
.
_stream
.
write
(
' auto input_strides = backend->create_tensor(element::i64,
%
s);
\n
'
%
print_shape
((
len
(
slices
)
,)))
self
.
_stream
.
write
(
' auto input_arg = backend->create_tensor(
%
s,
%
s);
\n
'
%
(
np_dt_to_ng
(
self
.
_dtype
),
print_shape
(
self
.
_shape
)))
self
.
_stream
.
write
(
' auto input_lb = backend->create_tensor(element::i64,
%
s);
\n
'
%
print_shape
((
n_slices
,)))
self
.
_stream
.
write
(
' auto input_ub = backend->create_tensor(element::i64,
%
s);
\n
'
%
print_shape
((
n_slices
,)))
self
.
_stream
.
write
(
' auto input_strides = backend->create_tensor(element::i64,
%
s);
\n
'
%
print_shape
((
n_slices
,)))
self
.
_stream
.
write
(
' copy_data(input_arg, input_values);
\n
'
)
self
.
_stream
.
write
(
' copy_data(input_lb, lb_values);
\n
'
)
self
.
_stream
.
write
(
' copy_data(input_ub, ub_values);
\n
'
)
self
.
_stream
.
write
(
' copy_data(input_strides, strides_values);
\n
'
)
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' auto output = backend->create_dynamic_tensor(
%
s,PartialShape::dynamic());
\n
'
%
np_dt_to_ng
(
self
.
_dtype
))
self
.
_stream
.
write
(
' auto output = backend->create_dynamic_tensor(
%
s,
PartialShape::dynamic());
\n
'
%
np_dt_to_ng
(
self
.
_dtype
))
self
.
_stream
.
write
(
'
\n
'
)
self
.
_stream
.
write
(
' ex->call({output}, {input_arg, input_lb, input_ub, input_strides});
\n
'
)
self
.
_stream
.
write
(
'
\n
'
)
...
...
@@ -299,6 +308,7 @@ def main():
//
// clang-format off
#include <algorithm>
#include <cmath>
#include "gtest/gtest.h"
...
...
@@ -321,8 +331,36 @@ NGRAPH_TEST(${BACKEND_NAME}, dyn_slice)
t
=
SliceTestWriter
(
stream
=
f
)
t
.
set_dtype
(
'int32'
)
t
.
set_shape
((
4
,))
t
[
np
.
newaxis
,
3
:
0
:
-
1
]
t
[
...
]
t
[
1
:
3
]
t
[
2
]
t
[
3
:
0
:
-
2
]
t
[
np
.
newaxis
]
t
[
np
.
newaxis
,
np
.
newaxis
]
t
[
np
.
newaxis
,
np
.
newaxis
,
...
,
np
.
newaxis
]
t
.
set_shape
((
5
,))
t
[
3
:
0
:
-
2
]
t
[
0
:
3
:
2
]
t
[
0
:
4
:
2
]
t
[
0
:
5
:
2
]
t
[
0
:
6
:
2
]
t
[
0
:
100
:
2
]
t
[
4
:
0
:
-
2
]
t
[
4
:
0
:
-
3
]
# FIXME: DynElimination is not properly handling this (end < begin).
# t[3:2:1]
t
[
4
::
-
2
]
t
.
set_shape
((
2
,
3
,
4
))
t
[
1
,
np
.
newaxis
]
t
[
-
1
,
-
1
,
np
.
newaxis
]
t
.
set_shape
((
2
,
4
,
6
,
8
,
2
,
2
,
2
))
t
[
0
:,:
4
,
2
:
6
:
2
,
7
:
3
:
-
2
,
np
.
newaxis
,
...
,
1
]
f
.
write
(
'''
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment