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
33a28e00
Unverified
Commit
33a28e00
authored
Apr 26, 2019
by
Michał Karzyński
Committed by
GitHub
Apr 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ONNX] Simplify the get_monotonic_range helper function (#2807)
parent
8da348f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
58 deletions
+16
-58
common.hpp
src/ngraph/frontend/onnx_import/utils/common.hpp
+16
-58
No files found.
src/ngraph/frontend/onnx_import/utils/common.hpp
View file @
33a28e00
...
...
@@ -16,11 +16,12 @@
#pragma once
#include <algorithm> // std::generate
#include <cmath> // std::floor, std::min
#include <cstddef> // std::size_t
#include <iterator> // std::begin, std::end
#include <memory> // std::shared_ptr, std::make_shared
#include <type_traits> // std::enable_if
, std::is_floating_point, std::is_integral
#include <type_traits> // std::enable_if
#include <vector>
#include "ngraph/op/constant.hpp"
...
...
@@ -33,38 +34,10 @@ namespace ngraph
{
namespace
common
{
namespace
detail
{
namespace
{
/// \brief Fill specified range with monotonic sequence.
///
/// \param[in] first The iterator to the beginning of the range.
/// \param[in] last The iterator to the past the end of the range.
/// \param[in] init_value The initial value for sequence.
/// \param[in] step The step value for sequence.
///
/// \tparam ForwardIterator The forward iterator class type.
/// \tparam T The sequence value type.
///
template
<
typename
ForwardIterator
,
typename
T
>
void
fill_monotonic_range
(
ForwardIterator
first
,
ForwardIterator
last
,
T
init_value
,
T
step
)
{
for
(;
first
!=
last
;
++
first
,
init_value
+=
step
)
{
*
first
=
init_value
;
}
}
}
// namespace anonymous
}
// namespace detail
/// \brief Return the monotonic sequence.
/// \brief Return a monotonic sequence.
///
/// \note Specialization for integral types.
/// \note Limitations: this function may not work for very large integer values
/// (near numerical limits).
///
/// \param[in] start_value The start value of the sequence.
/// \param[in] end_value The end value of the sequence.
...
...
@@ -72,36 +45,21 @@ namespace ngraph
///
/// \tparam T The data value type.
///
/// \return The vector with monotonic sequence.
template
<
typename
T
,
typename
std
::
enable_if
<
std
::
is_integral
<
T
>::
value
,
int
>::
type
=
0
>
/// \return The vector with monotonic sequence
template
<
typename
T
>
std
::
vector
<
T
>
get_monotonic_range
(
T
end_value
,
T
start_value
=
T
{
0
},
T
step
=
T
{
1
})
{
std
::
size_t
value_count
=
(
end_value
-
start_value
)
/
step
;
std
::
vector
<
T
>
range
(
value_count
);
detail
::
fill_monotonic_range
(
std
::
begin
(
range
),
std
::
end
(
range
),
start_value
,
step
);
return
range
;
}
auto
value_count
=
static_cast
<
std
::
size_t
>
(
std
::
floor
((
end_value
-
start_value
)
/
step
));
/// \brief Return the monotonic sequence.
///
/// \note Specialization for floating point types.
///
/// \param[in] start_value The start value of the sequence.
/// \param[in] end_value The end value of the sequence.
/// \param[in] step The step value for the sequence.
///
/// \tparam T The data value type.
///
/// \return The vector with monotonic sequence
template
<
typename
T
,
typename
std
::
enable_if
<
std
::
is_floating_point
<
T
>::
value
,
int
>::
type
=
0
>
std
::
vector
<
T
>
get_monotonic_range
(
T
end_value
,
T
start_value
=
T
{
0.
f
},
T
step
=
T
{
1.
f
})
{
std
::
size_t
value_count
=
reinterpret_cast
<
std
::
size_t
>
(
std
::
floor
((
end_value
-
start_value
)
/
step
));
std
::
vector
<
T
>
range
(
value_count
);
detail
::
fill_monotonic_range
(
std
::
begin
(
range
),
std
::
end
(
range
),
start_value
,
step
);
// Calculate initial value (one step below starting value)
size_t
n
=
start_value
-
step
;
// Generate a vector of values by adding step to previous value
std
::
generate
(
std
::
begin
(
range
),
std
::
end
(
range
),
[
&
n
,
&
step
]()
->
T
{
return
n
+=
step
;
});
return
range
;
}
...
...
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