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
db6e3052
Commit
db6e3052
authored
Aug 28, 2017
by
Scott Cyphers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for type upcasting.
parent
1b026daa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
type.hpp
src/ngraph/type.hpp
+2
-1
build_graph.cpp
test/build_graph.cpp
+19
-1
No files found.
src/ngraph/type.hpp
View file @
db6e3052
...
...
@@ -42,7 +42,8 @@ namespace ngraph
/**
** Unmanaged cast to a supertype. dynamic_cast cannot be used
** directly on a shared_ptr.
** directly on a shared_ptr. Can use dynamic_pointer_cast if
** a shared_ptr is needed.
**/
template
<
typename
T
>
T
as
()
{
return
dynamic_cast
<
T
>
(
this
);
}
};
...
...
test/build_graph.cpp
View file @
db6e3052
...
...
@@ -19,7 +19,7 @@
using
namespace
std
;
using
namespace
ngraph
;
TEST
(
n
graph
,
build_simple
)
TEST
(
build_
graph
,
build_simple
)
{
// Function with 4 parameters
auto
cluster_0
=
make_shared
<
Function
>
(
4
);
...
...
@@ -42,3 +42,21 @@ TEST(ngraph, build_simple)
ASSERT_EQ
(
cluster_0
->
result
()
->
value
(),
dot
);
}
// Check upcasting from ValueType.
TEST
(
build_graph
,
as_type
)
{
// Check upcasting a ValueType::ptr that is a TensorViewType to a TensorViewType and Tuple.
ValueType
::
ptr
tv_vt
=
make_shared
<
TensorViewType
>
(
element
::
float32_t
,
Shape
{
2
,
3
,
5
});
TensorViewType
*
tv_tv
=
tv_vt
->
as
<
TensorViewType
*>
();
ASSERT_EQ
(
tv_vt
.
get
(),
tv_tv
);
TupleType
*
tv_tp
=
tv_vt
->
as
<
TupleType
*>
();
ASSERT_EQ
(
nullptr
,
tv_tp
);
// Check upcasting a ValueType::ptr that is a TupleType to a TensorViewType and Tuple.
ValueType
::
ptr
tp_vt
=
make_shared
<
TupleType
>
(
vector
<
ValueType
::
ptr
>
{
tv_vt
,
tv_vt
});
TensorViewType
*
tp_tv
=
tp_vt
->
as
<
TensorViewType
*>
();
ASSERT_EQ
(
nullptr
,
tp_tv
);
TupleType
*
tp_tp
=
tp_vt
->
as
<
TupleType
*>
();
ASSERT_EQ
(
tp_vt
.
get
(),
tp_tp
);
}
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