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
2466bacd
Commit
2466bacd
authored
Dec 27, 2017
by
Robert Kimball
Committed by
Avijit
Dec 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bob/nan (#335)
* nan unit test * fix NAN issue * add INFINITY support
parent
556fda0a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
3 deletions
+104
-3
constant.cpp
src/ngraph/ops/constant.cpp
+28
-3
backend_test.in.cpp
test/backend_test.in.cpp
+76
-0
No files found.
src/ngraph/ops/constant.cpp
View file @
2466bacd
...
...
@@ -21,6 +21,32 @@
using
namespace
ngraph
;
using
namespace
std
;
template
<
typename
T
>
std
::
string
to_cpp_string
(
T
value
)
{
string
rc
;
if
(
isnan
(
value
))
{
rc
=
"NAN"
;
}
else
if
(
isinf
(
value
))
{
if
(
value
>
0
)
{
rc
=
"INFINITY"
;
}
else
{
rc
=
"-INFINITY"
;
}
}
else
{
rc
=
to_string
(
value
);
}
return
rc
;
}
op
::
Constant
::~
Constant
()
{
if
(
m_data
)
...
...
@@ -44,14 +70,14 @@ std::vector<std::string> op::Constant::get_value_strings() const
{
for
(
float
value
:
get_vector
<
float
>
())
{
rc
.
push_back
(
to_string
(
value
));
rc
.
push_back
(
to_
cpp_
string
(
value
));
}
}
else
if
(
m_element_type
==
element
::
f64
)
{
for
(
double
value
:
get_vector
<
double
>
())
{
rc
.
push_back
(
to_string
(
value
));
rc
.
push_back
(
to_
cpp_
string
(
value
));
}
}
else
if
(
m_element_type
==
element
::
i8
)
...
...
@@ -72,7 +98,6 @@ std::vector<std::string> op::Constant::get_value_strings() const
{
for
(
int32_t
value
:
get_vector
<
int32_t
>
())
{
NGRAPH_INFO
<<
value
;
rc
.
push_back
(
to_string
(
value
));
}
}
...
...
test/backend_test.in.cpp
View file @
2466bacd
...
...
@@ -4431,3 +4431,79 @@ TEST(${BACKEND_NAME}, not)
cf
->
call
({
a
},
{
result
});
EXPECT_EQ
((
vector
<
char
>
{
0
,
1
,
0
,
1
}),
result
->
get_vector
<
char
>
());
}
TEST
(
$
{
BACKEND_NAME
},
numeric_float_nan
)
{
auto
shape
=
Shape
{
5
};
auto
A
=
op
::
Constant
::
create
(
element
::
f32
,
shape
,
{
-
2.5
f
,
25.5
f
,
2.25
f
,
NAN
,
6.0
f
});
auto
B
=
op
::
Constant
::
create
(
element
::
f32
,
shape
,
{
10.0
f
,
5.0
f
,
2.25
f
,
10.0
f
,
NAN
});
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
boolean
,
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Equal
>
(
A
,
B
),
rt
,
op
::
Parameters
{});
auto
manager
=
runtime
::
Manager
::
get
(
"${BACKEND_NAME}"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
// Create some tensors for input/output
auto
result
=
backend
->
make_primary_tensor_view
(
element
::
boolean
,
shape
);
cf
->
call
({},
{
result
});
EXPECT_EQ
((
vector
<
char
>
{
false
,
false
,
true
,
false
,
false
}),
result
->
get_vector
<
char
>
());
}
TEST
(
$
{
BACKEND_NAME
},
numeric_double_nan
)
{
auto
shape
=
Shape
{
5
};
auto
A
=
op
::
Constant
::
create
(
element
::
f64
,
shape
,
{
-
2.5
f
,
25.5
f
,
2.25
f
,
NAN
,
6.0
f
});
auto
B
=
op
::
Constant
::
create
(
element
::
f64
,
shape
,
{
10.0
f
,
5.0
f
,
2.25
f
,
10.0
f
,
NAN
});
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
boolean
,
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Equal
>
(
A
,
B
),
rt
,
op
::
Parameters
{});
auto
manager
=
runtime
::
Manager
::
get
(
"${BACKEND_NAME}"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
// Create some tensors for input/output
auto
result
=
backend
->
make_primary_tensor_view
(
element
::
boolean
,
shape
);
cf
->
call
({},
{
result
});
EXPECT_EQ
((
vector
<
char
>
{
false
,
false
,
true
,
false
,
false
}),
result
->
get_vector
<
char
>
());
}
TEST
(
$
{
BACKEND_NAME
},
numeric_float_inf
)
{
auto
shape
=
Shape
{
5
};
auto
A
=
op
::
Constant
::
create
(
element
::
f32
,
shape
,
{
-
2.5
f
,
25.5
f
,
2.25
f
,
INFINITY
,
6.0
f
});
auto
B
=
op
::
Constant
::
create
(
element
::
f32
,
shape
,
{
10.0
f
,
5.0
f
,
2.25
f
,
10.0
f
,
-
INFINITY
});
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
boolean
,
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Equal
>
(
A
,
B
),
rt
,
op
::
Parameters
{});
auto
manager
=
runtime
::
Manager
::
get
(
"${BACKEND_NAME}"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
// Create some tensors for input/output
auto
result
=
backend
->
make_primary_tensor_view
(
element
::
boolean
,
shape
);
cf
->
call
({},
{
result
});
EXPECT_EQ
((
vector
<
char
>
{
false
,
false
,
true
,
false
,
false
}),
result
->
get_vector
<
char
>
());
}
TEST
(
$
{
BACKEND_NAME
},
numeric_double_inf
)
{
auto
shape
=
Shape
{
5
};
auto
A
=
op
::
Constant
::
create
(
element
::
f64
,
shape
,
{
-
2.5
f
,
25.5
f
,
2.25
f
,
INFINITY
,
6.0
f
});
auto
B
=
op
::
Constant
::
create
(
element
::
f64
,
shape
,
{
10.0
f
,
5.0
f
,
2.25
f
,
10.0
f
,
-
INFINITY
});
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
boolean
,
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Equal
>
(
A
,
B
),
rt
,
op
::
Parameters
{});
auto
manager
=
runtime
::
Manager
::
get
(
"${BACKEND_NAME}"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
// Create some tensors for input/output
auto
result
=
backend
->
make_primary_tensor_view
(
element
::
boolean
,
shape
);
cf
->
call
({},
{
result
});
EXPECT_EQ
((
vector
<
char
>
{
false
,
false
,
true
,
false
,
false
}),
result
->
get_vector
<
char
>
());
}
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