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
328ff806
Unverified
Commit
328ff806
authored
Feb 08, 2018
by
Robert Kimball
Committed by
GitHub
Feb 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
INFINITY working for float and double (#460)
parent
bce27b39
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
0 deletions
+54
-0
util.cpp
src/ngraph/util.cpp
+29
-0
util.hpp
src/ngraph/util.hpp
+7
-0
serialize.cpp
test/serialize.cpp
+1
-0
util.cpp
test/util.cpp
+17
-0
No files found.
src/ngraph/util.cpp
View file @
328ff806
...
...
@@ -270,3 +270,32 @@ ngraph::FpropCache ngraph::cache_fprop(std::shared_ptr<ngraph::Function> fprop,
return
fprop_cache
;
}
namespace
ngraph
{
template
<>
float
parse_string
<
float
>
(
const
std
::
string
&
s
)
{
const
char
*
tmp
=
s
.
c_str
();
char
*
end
;
float
result
=
strtof
(
tmp
,
&
end
);
if
(
*
end
!=
0
)
{
throw
std
::
runtime_error
(
"Could not parse literal '"
+
s
+
"'"
);
}
return
result
;
}
template
<>
double
parse_string
<
double
>
(
const
std
::
string
&
s
)
{
const
char
*
tmp
=
s
.
c_str
();
char
*
end
;
double
result
=
strtod
(
tmp
,
&
end
);
if
(
*
end
!=
0
)
{
throw
std
::
runtime_error
(
"Could not parse literal '"
+
s
+
"'"
);
}
return
result
;
}
}
src/ngraph/util.hpp
View file @
328ff806
...
...
@@ -183,6 +183,13 @@ namespace ngraph
return
result
;
}
/// template specializations for float and double to handle INFINITY, -INFINITY
/// and NaN values.
template
<>
float
parse_string
<
float
>
(
const
std
::
string
&
s
);
template
<>
double
parse_string
<
double
>
(
const
std
::
string
&
s
);
/// Parses a list of strings containing literals of the underlying type.
template
<
typename
T
>
std
::
vector
<
T
>
parse_string
(
const
std
::
vector
<
std
::
string
>&
ss
)
...
...
test/serialize.cpp
View file @
328ff806
...
...
@@ -26,6 +26,7 @@
using
namespace
std
;
using
namespace
ngraph
;
using
json
=
nlohmann
::
json
;
TEST
(
serialize
,
main
)
{
...
...
test/util.cpp
View file @
328ff806
...
...
@@ -340,3 +340,20 @@ TEST(util, round_up)
EXPECT_EQ
(
4
,
round_up
(
4
,
4
));
EXPECT_EQ
(
8
,
round_up
(
5
,
4
));
}
TEST
(
util
,
parse_string
)
{
EXPECT_FLOAT_EQ
(
2
,
parse_string
<
float
>
(
"2"
));
EXPECT_FLOAT_EQ
(
2.125
,
parse_string
<
float
>
(
"2.125"
));
EXPECT_FLOAT_EQ
(
numeric_limits
<
float
>::
infinity
(),
parse_string
<
float
>
(
"INFINITY"
));
EXPECT_FLOAT_EQ
(
numeric_limits
<
float
>::
infinity
(),
parse_string
<
float
>
(
"infinity"
));
EXPECT_FLOAT_EQ
(
-
numeric_limits
<
float
>::
infinity
(),
parse_string
<
float
>
(
"-INFINITY"
));
EXPECT_TRUE
(
isnan
(
parse_string
<
float
>
(
"NaN"
)));
EXPECT_FLOAT_EQ
(
2
,
parse_string
<
double
>
(
"2"
));
EXPECT_FLOAT_EQ
(
2.125
,
parse_string
<
double
>
(
"2.125"
));
EXPECT_FLOAT_EQ
(
numeric_limits
<
double
>::
infinity
(),
parse_string
<
double
>
(
"INFINITY"
));
EXPECT_FLOAT_EQ
(
numeric_limits
<
double
>::
infinity
(),
parse_string
<
double
>
(
"infinity"
));
EXPECT_FLOAT_EQ
(
-
numeric_limits
<
double
>::
infinity
(),
parse_string
<
double
>
(
"-INFINITY"
));
EXPECT_TRUE
(
isnan
(
parse_string
<
double
>
(
"NaN"
)));
}
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