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
02405796
Unverified
Commit
02405796
authored
Nov 06, 2017
by
Jai Menon
Committed by
GitHub
Nov 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into jmenon/cpu_kernels
parents
f80e1d0c
69a2d4aa
Hide whitespace changes
Inline
Side-by-side
Showing
52 changed files
with
876 additions
and
74 deletions
+876
-74
Makefile
examples/Makefile
+0
-29
main.cpp
examples/main.cpp
+0
-40
node.hpp
src/ngraph/node.hpp
+5
-1
abs.hpp
src/ngraph/ops/abs.hpp
+10
-0
acos.hpp
src/ngraph/ops/acos.hpp
+10
-0
add.hpp
src/ngraph/ops/add.hpp
+11
-0
asin.hpp
src/ngraph/ops/asin.hpp
+10
-0
atan.hpp
src/ngraph/ops/atan.hpp
+10
-0
broadcast.hpp
src/ngraph/ops/broadcast.hpp
+9
-1
ceiling.hpp
src/ngraph/ops/ceiling.hpp
+8
-0
concatenate.hpp
src/ngraph/ops/concatenate.hpp
+8
-0
constant.hpp
src/ngraph/ops/constant.hpp
+18
-2
convert.hpp
src/ngraph/ops/convert.hpp
+9
-0
cos.hpp
src/ngraph/ops/cos.hpp
+8
-0
cosh.hpp
src/ngraph/ops/cosh.hpp
+8
-0
divide.hpp
src/ngraph/ops/divide.hpp
+8
-0
dot.hpp
src/ngraph/ops/dot.hpp
+8
-0
equal.hpp
src/ngraph/ops/equal.hpp
+9
-0
exp.hpp
src/ngraph/ops/exp.hpp
+8
-0
floor.hpp
src/ngraph/ops/floor.hpp
+8
-0
function_call.hpp
src/ngraph/ops/function_call.hpp
+6
-0
get_tuple_element.hpp
src/ngraph/ops/get_tuple_element.hpp
+8
-0
greater.hpp
src/ngraph/ops/greater.hpp
+9
-0
greater_eq.hpp
src/ngraph/ops/greater_eq.hpp
+9
-0
less.hpp
src/ngraph/ops/less.hpp
+9
-0
less_eq.hpp
src/ngraph/ops/less_eq.hpp
+9
-0
log.hpp
src/ngraph/ops/log.hpp
+8
-0
maximum.hpp
src/ngraph/ops/maximum.hpp
+9
-0
minimum.hpp
src/ngraph/ops/minimum.hpp
+9
-0
multiply.hpp
src/ngraph/ops/multiply.hpp
+8
-0
negative.hpp
src/ngraph/ops/negative.hpp
+8
-0
not_equal.hpp
src/ngraph/ops/not_equal.hpp
+9
-0
parameter.hpp
src/ngraph/ops/parameter.hpp
+8
-0
power.hpp
src/ngraph/ops/power.hpp
+9
-0
reduce.hpp
src/ngraph/ops/reduce.hpp
+9
-0
remainder.hpp
src/ngraph/ops/remainder.hpp
+9
-0
reshape.hpp
src/ngraph/ops/reshape.hpp
+8
-0
select.hpp
src/ngraph/ops/select.hpp
+9
-0
sign.hpp
src/ngraph/ops/sign.hpp
+8
-0
sin.hpp
src/ngraph/ops/sin.hpp
+8
-0
sinh.hpp
src/ngraph/ops/sinh.hpp
+8
-0
slice.hpp
src/ngraph/ops/slice.hpp
+9
-0
subtract.hpp
src/ngraph/ops/subtract.hpp
+8
-0
sum.hpp
src/ngraph/ops/sum.hpp
+8
-0
tan.hpp
src/ngraph/ops/tan.hpp
+8
-0
tanh.hpp
src/ngraph/ops/tanh.hpp
+8
-0
tuple.hpp
src/ngraph/ops/tuple.hpp
+6
-0
ndarray.hpp
src/ngraph/runtime/ndarray.hpp
+2
-0
type.cpp
src/ngraph/types/type.cpp
+5
-0
type.hpp
src/ngraph/types/type.hpp
+4
-1
CMakeLists.txt
test/CMakeLists.txt
+1
-0
copy.cpp
test/copy.cpp
+475
-0
No files found.
examples/Makefile
deleted
100644 → 0
View file @
f80e1d0c
# 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
# limitations under the License.
NGRAPH_DIST_DIR
=
${
HOME
}
/ngraph_dist
CXXFLAGS
+=
-std
=
c++11
CPPFLAGS
+=
-I
$(NGRAPH_DIST_DIR)
LDFLAGS
=
-L
$(NGRAPH_DIST_DIR)
OBJ
=
main.o
%.o
:
%.cpp $(DEPS)
$(CXX)
-c
-o
$@
$<
$(CXXFLAGS)
$(CPPFLAGS)
ngraph-test
:
$(OBJ)
$(CXX)
-o
$@
$(OBJ)
$(LDFLAGS)
-lngraph
.PHONY
:
clean
clean
:
rm
-f
$(OBJ)
ngraph-test
examples/main.cpp
deleted
100644 → 0
View file @
f80e1d0c
// ----------------------------------------------------------------------------
// 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 <stdio.h>
#include "ngraph/ngraph.hpp"
#include "ngraph/ops/dot.hpp"
using
namespace
std
;
using
namespace
ngraph
;
int
main
(
int
argc
,
char
**
argv
)
{
printf
(
"Building graph
\n
"
);
// Function with 4 parameters
auto
arg0
=
op
::
parameter
(
element
::
Float
::
type
,
{
7
,
3
});
auto
arg1
=
op
::
parameter
(
element
::
Float
::
type
,
{
3
});
auto
arg2
=
op
::
parameter
(
element
::
Float
::
type
,
{
32
,
7
});
auto
arg3
=
op
::
parameter
(
element
::
Float
::
type
,
{
32
,
7
});
auto
broadcast_1
=
op
::
broadcast
(
arg3
,
{
10
,
32
,
7
},
{
0
});
auto
dot
=
op
::
dot
(
arg2
,
arg0
);
auto
cluster_0
=
op
::
function
(
dot
,
{
arg0
,
arg1
,
arg2
,
arg3
});
auto
result
=
cluster_0
->
result
();
printf
(
"Finished
\n
"
);
}
\ No newline at end of file
src/ngraph/node.hpp
View file @
02405796
...
...
@@ -117,8 +117,12 @@ namespace ngraph
std
::
shared_ptr
<
Node
>
backprop_node
(
const
std
::
shared_ptr
<
Node
>&
x
,
const
std
::
shared_ptr
<
Node
>&
c
);
/// Returns the shape if this node has tensor type, othe
twise error
.
/// Returns the shape if this node has tensor type, othe
rwise an ngraph-error is thrown
.
const
Shape
&
get_shape
()
const
{
return
m_value_type
->
get_shape
();
}
const
element
::
Type
&
get_element_type
()
const
{
return
m_value_type
->
get_element_type
();
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
=
0
;
protected
:
Nodes
m_arguments
;
std
::
shared_ptr
<
const
ValueType
>
m_value_type
;
...
...
src/ngraph/ops/abs.hpp
View file @
02405796
...
...
@@ -14,6 +14,8 @@
#pragma once
#include <memory>
#include "ngraph/ops/op.hpp"
namespace
ngraph
...
...
@@ -50,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Abs
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Abs"
;
}
};
}
...
...
src/ngraph/ops/acos.hpp
View file @
02405796
...
...
@@ -14,6 +14,8 @@
#pragma once
#include <memory>
#include "ngraph/ops/op.hpp"
namespace
ngraph
...
...
@@ -50,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Acos
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Acos"
;
}
};
}
...
...
src/ngraph/ops/add.hpp
View file @
02405796
...
...
@@ -14,6 +14,8 @@
#pragma once
#include <memory>
#include "ngraph/ops/op.hpp"
namespace
ngraph
...
...
@@ -51,6 +53,15 @@ namespace ngraph
:
BinaryElementwiseArithmetic
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Add
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Add"
;
}
protected
:
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
...
...
src/ngraph/ops/asin.hpp
View file @
02405796
...
...
@@ -14,6 +14,8 @@
#pragma once
#include <memory>
#include "ngraph/ops/op.hpp"
namespace
ngraph
...
...
@@ -50,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Asin
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Asin"
;
}
};
}
...
...
src/ngraph/ops/atan.hpp
View file @
02405796
...
...
@@ -14,6 +14,8 @@
#pragma once
#include <memory>
#include "ngraph/ops/op.hpp"
namespace
ngraph
...
...
@@ -50,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Atan
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Atan"
;
}
};
}
...
...
src/ngraph/ops/broadcast.hpp
View file @
02405796
...
...
@@ -74,12 +74,20 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Broadcast
>
(
new_args
.
at
(
0
),
m_shape
,
m_broadcast_axes
);
}
virtual
std
::
string
description
()
const
override
{
return
"Broadcast"
;
}
virtual
void
propagate_types
()
override
;
/// \return An set containing the indices of the broadcast axes (0-based).
const
AxisSet
&
get_broadcast_axes
()
const
{
return
m_broadcast_axes
;
}
protected
:
const
Shape
&
get_broadcast_shape
()
const
{
return
m_shape
;
}
protected
:
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
std
::
shared_ptr
<
Node
>&
delta
)
override
;
...
...
src/ngraph/ops/ceiling.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Ceiling
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Ceiling"
;
}
};
}
...
...
src/ngraph/ops/concatenate.hpp
View file @
02405796
...
...
@@ -14,6 +14,8 @@
#pragma once
#include <memory>
#include "ngraph/ops/op.hpp"
namespace
ngraph
...
...
@@ -74,6 +76,12 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
return
std
::
make_shared
<
Concat
>
(
new_args
,
m_concatenation_axis
);
}
virtual
std
::
string
description
()
const
override
{
return
"Concatenate"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/constant.hpp
View file @
02405796
...
...
@@ -82,12 +82,20 @@ namespace ngraph
/// \param value The value of the tensor constant.
ParameterizedConstant
(
const
Shape
&
shape
,
typename
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
T
>>&
value
)
const
typename
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
T
>>&
value
)
:
ConstantBase
(
std
::
make_shared
<
TensorViewType
>
(
T
::
element_type
(),
shape
))
,
m_value
(
value
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
0
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
ParameterizedConstant
<
T
>>
(
get_shape
(),
m_value
);
}
virtual
std
::
string
description
()
const
override
{
return
"ParameterizedConstant"
;
}
virtual
std
::
string
get_node_id
()
const
override
{
...
...
@@ -103,7 +111,7 @@ namespace ngraph
}
protected
:
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
T
>>
m_value
;
const
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
T
>>
m_value
;
};
/// \brief A 32-bit floating-point tensor constant.
...
...
@@ -171,6 +179,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
0
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Constant
>
(
get_element_type
(),
get_shape
(),
m_value_strings
);
}
virtual
std
::
string
description
()
const
override
{
return
"Constant"
;
}
virtual
std
::
string
get_node_id
()
const
override
{
...
...
src/ngraph/ops/convert.hpp
View file @
02405796
...
...
@@ -61,8 +61,17 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Convert
>
(
new_args
.
at
(
0
),
m_element_type
);
}
virtual
const
element
::
Type
&
propagate_element_types
(
const
element
::
Type
&
arg_element_type
)
const
override
;
const
element
::
Type
&
get_convert_element_type
()
const
{
return
m_element_type
;
}
virtual
std
::
string
description
()
const
override
{
return
"Convert"
;
}
protected
:
const
ngraph
::
element
::
Type
&
m_element_type
;
...
...
src/ngraph/ops/cos.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Cos
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Cos"
;
}
};
}
...
...
src/ngraph/ops/cosh.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Cosh
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Cosh"
;
}
};
}
...
...
src/ngraph/ops/divide.hpp
View file @
02405796
...
...
@@ -52,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Divide
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
std
::
shared_ptr
<
Node
>&
delta
)
override
;
...
...
src/ngraph/ops/dot.hpp
View file @
02405796
...
...
@@ -114,6 +114,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Dot
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Dot"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/equal.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseComparison
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Equal
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Equal"
;
}
};
}
...
...
src/ngraph/ops/exp.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Exp
>
(
new_args
.
at
(
0
));
}
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
std
::
shared_ptr
<
Node
>&
delta
)
override
;
...
...
src/ngraph/ops/floor.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Floor
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Floor"
;
}
};
}
...
...
src/ngraph/ops/function_call.hpp
View file @
02405796
...
...
@@ -60,6 +60,12 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
return
std
::
make_shared
<
FunctionCall
>
(
m_function
,
new_args
);
}
virtual
std
::
string
description
()
const
override
{
return
"FunctionCall"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/get_tuple_element.hpp
View file @
02405796
...
...
@@ -60,6 +60,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
GetTupleElement
>
(
new_args
.
at
(
0
),
m_n
);
}
virtual
void
propagate_types
()
override
;
virtual
std
::
string
description
()
const
override
{
return
"GetTupleElement"
;
}
/// \return The index of the tuple element to get.
...
...
src/ngraph/ops/greater.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseComparison
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Greater
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Greater"
;
}
};
}
...
...
src/ngraph/ops/greater_eq.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseComparison
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
GreaterEq
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"GreaterEq"
;
}
};
}
...
...
src/ngraph/ops/less.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseComparison
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Less
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Less"
;
}
};
}
...
...
src/ngraph/ops/less_eq.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseComparison
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
LessEq
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"LessEq"
;
}
};
}
...
...
src/ngraph/ops/log.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Log
>
(
new_args
.
at
(
0
));
}
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
std
::
shared_ptr
<
Node
>&
delta
)
override
;
...
...
src/ngraph/ops/maximum.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseArithmetic
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Maximum
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Maximum"
;
}
protected
:
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
...
...
src/ngraph/ops/minimum.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseArithmetic
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Minimum
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Minimum"
;
}
protected
:
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
...
...
src/ngraph/ops/multiply.hpp
View file @
02405796
...
...
@@ -52,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Multiply
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Multiply"
;
}
protected
:
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
...
...
src/ngraph/ops/negative.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Negative
>
(
new_args
.
at
(
0
));
}
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
std
::
shared_ptr
<
Node
>&
delta
)
override
;
...
...
src/ngraph/ops/not_equal.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseComparison
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
NotEqual
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"NotEqual"
;
}
};
}
...
...
src/ngraph/ops/parameter.hpp
View file @
02405796
...
...
@@ -62,6 +62,14 @@ namespace ngraph
/// \param shape The shape of the parameter.
Parameter
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
);
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
0
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Parameter
>
(
get_value_type
());
}
std
::
string
description
()
const
override
{
return
"Parameter"
;
}
virtual
void
propagate_types
()
override
;
};
...
...
src/ngraph/ops/power.hpp
View file @
02405796
...
...
@@ -51,6 +51,15 @@ namespace ngraph
:
BinaryElementwiseArithmetic
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Power
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Power"
;
}
};
}
...
...
src/ngraph/ops/reduce.hpp
View file @
02405796
...
...
@@ -106,6 +106,15 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Reduce
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
),
m_reduction_function
,
m_reduction_axes
);
}
virtual
std
::
string
description
()
const
override
{
return
"Reduce"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/remainder.hpp
View file @
02405796
...
...
@@ -53,6 +53,15 @@ namespace ngraph
:
BinaryElementwiseArithmetic
(
arg0
,
arg1
)
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Remainder
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
std
::
string
description
()
const
override
{
return
"Remainder"
;
}
};
}
...
...
src/ngraph/ops/reshape.hpp
View file @
02405796
...
...
@@ -78,6 +78,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Reshape
>
(
new_args
.
at
(
0
),
m_input_order
,
m_output_shape
);
}
virtual
std
::
string
description
()
const
override
{
return
"Reshape"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/select.hpp
View file @
02405796
...
...
@@ -55,6 +55,15 @@ namespace ngraph
:
Builtin
(
Nodes
{
arg0
,
arg1
,
arg2
})
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
3
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Select
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
),
new_args
.
at
(
2
));
}
virtual
std
::
string
description
()
const
override
{
return
"Select"
;
}
virtual
void
propagate_types
()
override
;
};
...
...
src/ngraph/ops/sign.hpp
View file @
02405796
...
...
@@ -52,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Sign
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Sign"
;
}
};
}
...
...
src/ngraph/ops/sin.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Sin
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Sin"
;
}
};
}
...
...
src/ngraph/ops/sinh.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Sinh
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Sinh"
;
}
};
}
...
...
src/ngraph/ops/slice.hpp
View file @
02405796
...
...
@@ -88,6 +88,15 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Slice
>
(
new_args
.
at
(
0
),
m_lower_bounds
,
m_upper_bounds
,
m_step
);
}
virtual
std
::
string
description
()
const
override
{
return
"Slice"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/subtract.hpp
View file @
02405796
...
...
@@ -52,6 +52,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
2
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Subtract
>
(
new_args
.
at
(
0
),
new_args
.
at
(
1
));
}
virtual
void
generate_adjoints
(
autodiff
::
Adjoints
&
adjoints
,
const
std
::
shared_ptr
<
Node
>&
delta
)
override
;
...
...
src/ngraph/ops/sum.hpp
View file @
02405796
...
...
@@ -93,6 +93,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Sum
>
(
new_args
.
at
(
0
),
m_reduction_axes
);
}
virtual
std
::
string
description
()
const
override
{
return
"Sum"
;
}
virtual
void
propagate_types
()
override
;
...
...
src/ngraph/ops/tan.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Tan
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Tan"
;
}
};
}
...
...
src/ngraph/ops/tanh.hpp
View file @
02405796
...
...
@@ -50,6 +50,14 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
if
(
new_args
.
size
()
!=
1
)
throw
ngraph_error
(
"Incorrect number of new arguments"
);
return
std
::
make_shared
<
Tanh
>
(
new_args
.
at
(
0
));
}
virtual
std
::
string
description
()
const
override
{
return
"Tanh"
;
}
};
}
...
...
src/ngraph/ops/tuple.hpp
View file @
02405796
...
...
@@ -50,6 +50,12 @@ namespace ngraph
{
}
virtual
std
::
shared_ptr
<
Node
>
copy_with_new_args
(
const
std
::
vector
<
std
::
shared_ptr
<
Node
>>&
new_args
)
const
override
{
return
std
::
make_shared
<
Tuple
>
(
new_args
);
}
virtual
std
::
string
description
()
const
override
{
return
"Tuple"
;
}
virtual
void
propagate_types
()
override
;
};
...
...
src/ngraph/runtime/ndarray.hpp
View file @
02405796
...
...
@@ -177,6 +177,8 @@ namespace ngraph
const_iterator
end
()
const
{
return
m_elements
.
end
();
}
vtype
get_vector
()
{
return
m_elements
;
}
const
vtype
get_vector
()
const
{
return
m_elements
;
}
operator
const
vtype
()
const
{
return
m_elements
;
}
operator
vtype
()
{
return
m_elements
;
}
bool
operator
==
(
const
NDArrayBase
<
T
>&
other
)
const
{
return
m_shape
==
other
.
m_shape
&&
m_elements
==
other
.
m_elements
;
...
...
src/ngraph/types/type.cpp
View file @
02405796
...
...
@@ -70,6 +70,11 @@ const Shape& TupleType::get_shape() const
throw
ngraph_error
(
"get_shape() called on Tuple"
);
}
const
element
::
Type
&
TupleType
::
get_element_type
()
const
{
throw
ngraph_error
(
"get_element_type() called on Tuple"
);
}
std
::
ostream
&
ngraph
::
operator
<<
(
std
::
ostream
&
out
,
const
ValueType
&
obj
)
{
out
<<
"ValueType()"
;
...
...
src/ngraph/types/type.hpp
View file @
02405796
...
...
@@ -43,6 +43,7 @@ namespace ngraph
virtual
void
collect_tensor_views
(
std
::
vector
<
std
::
shared_ptr
<
const
TensorViewType
>>&
views
)
const
=
0
;
virtual
const
Shape
&
get_shape
()
const
=
0
;
virtual
const
element
::
Type
&
get_element_type
()
const
=
0
;
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
ValueType
&
);
};
...
...
@@ -59,7 +60,7 @@ namespace ngraph
{
}
const
element
::
Type
&
get_element_type
()
const
{
return
m_element_type
;
}
virtual
const
element
::
Type
&
get_element_type
()
const
override
{
return
m_element_type
;
}
virtual
const
Shape
&
get_shape
()
const
override
{
return
m_shape
;
}
virtual
bool
operator
==
(
const
ValueType
&
that
)
const
override
;
virtual
void
collect_tensor_views
(
...
...
@@ -93,6 +94,8 @@ namespace ngraph
return
m_element_types
;
}
virtual
const
element
::
Type
&
get_element_type
()
const
override
;
virtual
bool
operator
==
(
const
ValueType
&
that
)
const
override
;
virtual
void
collect_tensor_views
(
std
::
vector
<
std
::
shared_ptr
<
const
TensorViewType
>>&
views
)
const
override
;
...
...
test/CMakeLists.txt
View file @
02405796
...
...
@@ -23,6 +23,7 @@ include_directories(
set
(
SRC
autodiff.cpp
copy.cpp
build_graph.cpp
eigen.cpp
input_output_assign.cpp
...
...
test/copy.cpp
0 → 100644
View file @
02405796
// ----------------------------------------------------------------------------
// 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 <memory>
#include <string>
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
using
namespace
std
;
using
namespace
ngraph
;
template
<
typename
OP
>
bool
check_unary
()
{
Shape
shape
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
node
=
make_shared
<
OP
>
(
arg0
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
OP
>
(
new_node
);
return
(
nullptr
!=
new_node
)
&&
(
new_args
==
new_node
->
get_arguments
());
}
template
<
typename
OP
>
bool
check_binary
()
{
Shape
shape
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
arg1
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
node
=
make_shared
<
OP
>
(
arg0
,
arg1
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
OP
>
(
new_node
);
return
(
nullptr
!=
new_node
)
&&
(
new_args
==
new_node
->
get_arguments
());
}
TEST
(
copy
,
abs
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Abs
>
());
}
TEST
(
copy
,
acos
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Acos
>
());
}
TEST
(
copy
,
add
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Add
>
());
}
TEST
(
copy
,
asin
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Asin
>
());
}
TEST
(
copy
,
atan
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Atan
>
());
}
TEST
(
copy
,
broadcast
)
{
Shape
shape1
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape1
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape1
)};
Shape
shape
{
4
,
1
,
3
};
AxisSet
axes
{
0
,
2
};
auto
node
=
make_shared
<
op
::
Broadcast
>
(
arg0
,
shape
,
axes
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Broadcast
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
shape
==
node_cast
->
get_broadcast_shape
());
ASSERT_TRUE
(
axes
==
node_cast
->
get_broadcast_axes
());
}
TEST
(
copy
,
ceiling
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Ceiling
>
());
}
TEST
(
copy
,
concat
)
{
Shape
shape
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
arg1
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
size_t
axis
=
1
;
auto
node
=
make_shared
<
op
::
Concat
>
(
Nodes
{
arg0
,
arg1
},
axis
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Concat
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
node_cast
->
get_concatenation_axis
()
==
axis
);
}
TEST
(
copy
,
parameterized_constant
)
{
auto
manager
=
runtime
::
Manager
::
get
(
"NGVM"
);
auto
backend
=
manager
->
allocate_backend
();
// Create some tensors for input/output
auto
c
=
backend
->
make_parameterized_tensor_view
<
element
::
Float32
>
(
runtime
::
NDArray
<
float
,
2
>
({{
1
,
2
},
{
3
,
4
}}));
Shape
shape
{
2
,
2
};
auto
node
=
make_shared
<
op
::
ParameterizedConstant
<
element
::
Float32
>>
(
shape
,
c
);
auto
new_node
=
node
->
copy_with_new_args
(
Nodes
{});
auto
node_cast
=
dynamic_pointer_cast
<
op
::
ParameterizedConstant
<
element
::
Float32
>>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
Nodes
{}
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
node_cast
->
get_value
()
==
c
);
ASSERT_TRUE
(
node_cast
->
get_shape
()
==
shape
);
}
TEST
(
copy
,
constant
)
{
Shape
shape
{};
vector
<
string
>
c
{
"2.4"
};
auto
&
et
=
element
::
Float32
::
element_type
();
auto
node
=
make_shared
<
op
::
Constant
>
(
et
,
shape
,
c
);
auto
new_node
=
node
->
copy_with_new_args
(
Nodes
{});
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Constant
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
Nodes
{}
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
node_cast
->
get_value_strings
()
==
c
);
ASSERT_TRUE
(
node_cast
->
get_shape
()
==
shape
);
ASSERT_TRUE
(
node_cast
->
get_element_type
()
==
et
);
}
TEST
(
copy
,
convert
)
{
Shape
shape
;
auto
&
et
=
element
::
Float64
::
element_type
();
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
node
=
make_shared
<
op
::
Convert
>
(
arg0
,
et
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Convert
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
et
==
node_cast
->
get_convert_element_type
());
}
TEST
(
copy
,
cos
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Cos
>
());
}
TEST
(
copy
,
cosh
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Cosh
>
());
}
TEST
(
copy
,
divide
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Divide
>
());
}
TEST
(
copy
,
dot
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Dot
>
());
}
TEST
(
copy
,
equal
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Equal
>
());
}
TEST
(
copy
,
exp
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Exp
>
());
}
TEST
(
copy
,
floor
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Floor
>
());
}
TEST
(
copy
,
FunctionCall
)
{
Shape
shape
{
1
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
C
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
((
A
+
B
)
*
C
,
rt
,
op
::
Parameters
{
A
,
B
,
C
});
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
arg1
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
node
=
make_shared
<
op
::
FunctionCall
>
(
f
,
Nodes
{
arg0
,
arg1
});
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
FunctionCall
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
node_cast
->
get_function
()
==
f
);
}
TEST
(
copy
,
GetTupleElement
)
{
Shape
shape
{
1
};
size_t
n
=
0
;
auto
tuple_type
=
make_shared
<
TupleType
>
(
vector
<
shared_ptr
<
const
ValueType
>>
{
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
)});
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
tuple_type
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
tuple_type
)};
auto
node
=
make_shared
<
op
::
GetTupleElement
>
(
arg0
,
n
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
GetTupleElement
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
node_cast
->
get_n
()
==
n
);
}
TEST
(
copy
,
greater_eq
)
{
ASSERT_TRUE
(
check_binary
<
op
::
GreaterEq
>
());
}
TEST
(
copy
,
greater
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Greater
>
());
}
TEST
(
copy
,
less_eq
)
{
ASSERT_TRUE
(
check_binary
<
op
::
LessEq
>
());
}
TEST
(
copy
,
less
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Less
>
());
}
TEST
(
copy
,
log
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Log
>
());
}
TEST
(
copy
,
maximum
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Maximum
>
());
}
TEST
(
copy
,
minimum
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Minimum
>
());
}
TEST
(
copy
,
multiply
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Multiply
>
());
}
TEST
(
copy
,
negative
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Negative
>
());
}
TEST
(
copy
,
not_equal
)
{
ASSERT_TRUE
(
check_binary
<
op
::
NotEqual
>
());
}
TEST
(
copy
,
parameter
)
{
Shape
shape
{
1
};
auto
node
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
new_node
=
node
->
copy_with_new_args
({});
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Parameter
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_node
->
get_arguments
().
size
()
==
0
);
ASSERT_TRUE
(
node
->
get_value_type
()
==
new_node
->
get_value_type
());
}
TEST
(
copy
,
power
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Power
>
());
}
TEST
(
copy
,
reduce
)
{
Shape
scalar_shape
{};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
scalar_shape
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
scalar_shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
scalar_shape
);
auto
f
=
make_shared
<
Function
>
(
A
+
B
,
rt
,
op
::
Parameters
{
A
,
B
});
Shape
shape
{
4
,
3
};
AxisSet
axes
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
arg_init
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
scalar_shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
scalar_shape
)};
auto
node
=
make_shared
<
op
::
Reduce
>
(
arg0
,
arg_init
,
f
,
axes
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Reduce
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
f
==
node_cast
->
get_reduction_function
());
ASSERT_TRUE
(
axes
==
node_cast
->
get_reduction_axes
());
}
TEST
(
copy
,
remainder
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Remainder
>
());
}
TEST
(
copy
,
reshape
)
{
Shape
shape_in
{
2
,
3
,
4
};
AxisVector
axes
{
0
,
1
,
2
};
Shape
shape_out
{
6
,
4
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape_in
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape_in
)};
auto
node
=
make_shared
<
op
::
Reshape
>
(
arg0
,
axes
,
shape_out
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Reshape
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
axes
==
node_cast
->
get_input_order
());
ASSERT_TRUE
(
shape_out
==
node_cast
->
get_output_shape
());
}
TEST
(
copy
,
select
)
{
Shape
shape
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Bool
::
element_type
(),
shape
);
auto
arg1
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
arg2
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Bool
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
node
=
make_shared
<
op
::
Select
>
(
arg0
,
arg1
,
arg2
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Select
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
}
TEST
(
copy
,
sign
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Sign
>
());
}
TEST
(
copy
,
sin
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Sin
>
());
}
TEST
(
copy
,
sinh
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Sinh
>
());
}
TEST
(
copy
,
slice
)
{
Shape
shape_in
{
2
,
3
,
4
};
Coordinate
lower
{
0
,
0
,
0
};
Coordinate
upper
{
2
,
3
,
4
};
Coordinate
step
{
1
,
1
,
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape_in
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape_in
)};
auto
node
=
make_shared
<
op
::
Slice
>
(
arg0
,
lower
,
upper
,
step
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Slice
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
lower
==
node_cast
->
get_lower_bounds
());
ASSERT_TRUE
(
upper
==
node_cast
->
get_upper_bounds
());
ASSERT_TRUE
(
step
==
node_cast
->
get_step
());
}
TEST
(
copy
,
subtract
)
{
ASSERT_TRUE
(
check_binary
<
op
::
Subtract
>
());
}
TEST
(
copy
,
sum
)
{
Shape
shape
{
4
,
3
};
AxisSet
axes
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
node
=
make_shared
<
op
::
Sum
>
(
arg0
,
axes
);
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Sum
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
ASSERT_TRUE
(
axes
==
node_cast
->
get_reduction_axes
());
}
TEST
(
copy
,
tan
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Tan
>
());
}
TEST
(
copy
,
tanh
)
{
ASSERT_TRUE
(
check_unary
<
op
::
Tanh
>
());
}
TEST
(
copy
,
tuple
)
{
Shape
shape
{
1
};
auto
arg0
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
arg1
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
std
::
vector
<
std
::
shared_ptr
<
Node
>>
new_args
{
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
),
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
)};
auto
node
=
make_shared
<
op
::
Tuple
>
(
Nodes
{
arg0
,
arg1
});
auto
new_node
=
node
->
copy_with_new_args
(
new_args
);
auto
node_cast
=
dynamic_pointer_cast
<
op
::
Tuple
>
(
new_node
);
ASSERT_TRUE
(
nullptr
!=
new_node
);
ASSERT_TRUE
(
new_args
==
new_node
->
get_arguments
());
}
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