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
d734d6d6
Commit
d734d6d6
authored
Apr 04, 2019
by
Tomasz Dołbniak
Committed by
Adam Straw
Apr 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TopK: return the lower index for equivalent values (#2710)
TopK: return the lower index for equivalent values
parent
0890cc86
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
0 deletions
+37
-0
unit_test.manifest
src/ngraph/runtime/intelgpu/unit_test.manifest
+1
-0
topk.hpp
src/ngraph/runtime/reference/topk.hpp
+10
-0
backend_topk.in.cpp
test/backend_topk.in.cpp
+26
-0
No files found.
src/ngraph/runtime/intelgpu/unit_test.manifest
View file @
d734d6d6
...
...
@@ -30,6 +30,7 @@ topk_1d_min_one
topk_1d_min_partial
topk_2d_max_all
topk_2d_max_one
topk_2d_max_one_with_equal_values
topk_2d_max_partial
topk_2d_min_all
topk_2d_min_one
...
...
src/ngraph/runtime/reference/topk.hpp
View file @
d734d6d6
...
...
@@ -33,6 +33,16 @@ namespace ngraph
template
<
typename
T
,
typename
U
>
static
bool
compare_max
(
const
std
::
tuple
<
T
,
U
>&
a
,
const
std
::
tuple
<
T
,
U
>&
b
)
{
// this is intentional to be able to compare floats directly
// without using relative or absolute tolerance
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
if
(
std
::
get
<
0
>
(
a
)
==
std
::
get
<
0
>
(
b
))
{
return
std
::
get
<
1
>
(
a
)
<
std
::
get
<
1
>
(
b
);
}
#pragma clang diagnostic pop
return
a
>
b
;
}
template
<
typename
T
,
typename
U
>
...
...
test/backend_topk.in.cpp
View file @
d734d6d6
...
...
@@ -522,6 +522,32 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_max_one)
(
vector
<
float
>
{
12
,
11
,
10
}),
read_vector
<
float
>
(
result1
),
MIN_FLOAT_TOLERANCE_BITS
));
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
topk_2d_max_one_with_equal_values
)
{
Shape
shape
{
2
,
4
};
Shape
rshape
{
2
,
1
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shape
);
auto
B
=
make_shared
<
op
::
TopK
>
(
A
,
1
,
element
::
i32
,
1
,
true
);
auto
f0
=
make_shared
<
Function
>
(
make_shared
<
op
::
GetOutputElement
>
(
B
,
0
),
ParameterVector
{
A
});
auto
f1
=
make_shared
<
Function
>
(
make_shared
<
op
::
GetOutputElement
>
(
B
,
1
),
ParameterVector
{
A
});
auto
backend
=
runtime
::
Backend
::
create
(
"${BACKEND_NAME}"
);
// Create some tensors for input/output
auto
a
=
backend
->
create_tensor
(
element
::
f32
,
shape
);
copy_data
(
a
,
vector
<
float
>
{
1
,
3
,
2
,
4
,
1
,
3
,
3
,
2
});
auto
result0
=
backend
->
create_tensor
(
element
::
i32
,
rshape
);
auto
result1
=
backend
->
create_tensor
(
element
::
f32
,
rshape
);
auto
h0
=
backend
->
compile
(
f0
);
h0
->
call_with_validate
({
result0
},
{
a
});
EXPECT_EQ
((
vector
<
int32_t
>
{
3
,
1
}),
read_vector
<
int32_t
>
(
result0
));
auto
h1
=
backend
->
compile
(
f1
);
h1
->
call_with_validate
({
result1
},
{
a
});
EXPECT_TRUE
(
test
::
all_close_f
(
(
vector
<
float
>
{
4
,
3
}),
read_vector
<
float
>
(
result1
),
MIN_FLOAT_TOLERANCE_BITS
));
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
topk_2d_min_all
)
{
Shape
shape
{
4
,
3
};
...
...
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