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
8ba7b324
Commit
8ba7b324
authored
Sep 05, 2017
by
Scott Cyphers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish broadcast type propagation, add tests.
parent
961b4e0a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
0 deletions
+92
-0
node.hpp
src/ngraph/node.hpp
+1
-0
broadcast.cpp
src/ops/broadcast.cpp
+4
-0
CMakeLists.txt
test/CMakeLists.txt
+1
-0
type_prop.cpp
test/type_prop.cpp
+86
-0
No files found.
src/ngraph/node.hpp
View file @
8ba7b324
...
...
@@ -94,6 +94,7 @@ namespace ngraph
size_t
get_instance_id
()
const
{
return
m_instance_id
;
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Node
&
);
protected
:
Nodes
m_arguments
;
...
...
src/ops/broadcast.cpp
View file @
8ba7b324
...
...
@@ -19,6 +19,10 @@ using namespace ngraph::op;
void
Broadcast
::
propagate_types
()
{
if
(
m_arguments
.
size
()
!=
1
){
throw
ngraph_error
(
"Wrong number of arguments."
);
}
auto
arg_type
=
m_arguments
.
at
(
0
)
->
get_value_type
();
if
(
nullptr
==
arg_type
)
{
...
...
test/CMakeLists.txt
View file @
8ba7b324
...
...
@@ -24,6 +24,7 @@ set (SRC
element_type.cpp
uuid.cpp
topological_sort.cpp
type_prop.cpp
op.cpp
)
...
...
test/type_prop.cpp
0 → 100644
View file @
8ba7b324
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include <memory>
using
namespace
std
;
using
namespace
ngraph
;
TEST
(
type_prop
,
broadcast_deduce
)
{
// Deduce type
auto
param
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
4
});
auto
bc
=
make_shared
<
op
::
Broadcast
>
(
param
,
Shape
{
2
,
3
,
4
},
AxisSet
{
1
});
bc
->
propagate_types
();
auto
bc_vt
=
bc
->
get_value_type
();
ASSERT_EQ
(
*
bc_vt
,
TensorViewType
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
3
,
4
}));
}
TEST
(
type_prop
,
broadcast_deduce_correct
)
{
// Check deduced type against correctly specified type
auto
param
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
4
});
auto
bc
=
make_shared
<
op
::
Broadcast
>
(
param
,
Shape
{
2
,
3
,
4
},
AxisSet
{
1
});
bc
->
set_value_type
(
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
3
,
4
}));
bc
->
propagate_types
();
auto
bc_vt
=
bc
->
get_value_type
();
ASSERT_EQ
(
*
bc_vt
,
TensorViewType
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
3
,
4
}));
}
TEST
(
type_prop
,
broadcast_deduce_incorrect
)
{
// Check deduced type against incorrectly specified type
auto
param
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
4
});
auto
bc
=
make_shared
<
op
::
Broadcast
>
(
param
,
Shape
{
2
,
4
,
3
},
AxisSet
{
1
});
bc
->
set_value_type
(
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
Shape
{
2
,
3
,
4
}));
try
{
bc
->
propagate_types
();
FAIL
()
<<
"Deduced type should disagree with specified type"
;
}
catch
(
const
ngraph_error
&
error
)
{
EXPECT_EQ
(
error
.
what
(),
std
::
string
(
"Broadcast arg, shape, and axes are incompatible"
));
}
catch
(...)
{
FAIL
()
<<
"Deduced type check failed for unexpected reason"
;
}
}
TEST
(
type_prop
,
broadcast_bad_arguments
)
{
// Check for bad arguments
auto
param
=
make_shared
<
op
::
Parameter
>
(
make_shared
<
TupleType
>
());
auto
bc
=
make_shared
<
op
::
Broadcast
>
(
param
,
Shape
{
2
,
4
,
3
},
AxisSet
{
1
});
try
{
bc
->
propagate_types
();
FAIL
()
<<
"Tuple argument to broadcast not detected."
;
}
catch
(
const
ngraph_error
&
error
)
{
EXPECT_EQ
(
error
.
what
(),
std
::
string
(
"Argument to broadcast is not a tensor view"
));
}
catch
(...)
{
FAIL
()
<<
"Deduced type check failed for unexpected reason"
;
}
}
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