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
d5e93b65
Commit
d5e93b65
authored
Oct 17, 2017
by
Adam Procter
Committed by
Scott Cyphers
Oct 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Elementwise sign operation (#201)
* Elementwise sign operation * Formatting
parent
73aaf05d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
0 deletions
+112
-0
ngraph.hpp
src/ngraph/ngraph.hpp
+1
-0
sign.hpp
src/ngraph/ops/sign.hpp
+34
-0
sign.hpp
src/ngraph/runtime/ngvm/eigen/sign.hpp
+53
-0
external_function.cpp
src/ngraph/runtime/ngvm/external_function.cpp
+3
-0
execute.cpp
test/execute.cpp
+21
-0
No files found.
src/ngraph/ngraph.hpp
View file @
d5e93b65
...
...
@@ -84,6 +84,7 @@
#include "ngraph/ops/remainder.hpp"
#include "ngraph/ops/reshape.hpp"
#include "ngraph/ops/select.hpp"
#include "ngraph/ops/sign.hpp"
#include "ngraph/ops/sin.hpp"
#include "ngraph/ops/sinh.hpp"
#include "ngraph/ops/slice.hpp"
...
...
src/ngraph/ops/sign.hpp
0 → 100644
View file @
d5e93b65
// ----------------------------------------------------------------------------
// 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
// ----------------------------------------------------------------------------
#pragma once
#include "ngraph/ops/op.hpp"
namespace
ngraph
{
namespace
op
{
class
Sign
:
public
UnaryElementwiseArithmetic
{
public
:
Sign
(
const
std
::
shared_ptr
<
Node
>&
arg
)
:
UnaryElementwiseArithmetic
(
arg
)
{
}
virtual
std
::
string
description
()
const
override
{
return
"Sign"
;
}
};
}
}
src/ngraph/runtime/ngvm/eigen/sign.hpp
0 → 100644
View file @
d5e93b65
// ----------------------------------------------------------------------------
// 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
// ----------------------------------------------------------------------------
#pragma once
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
template
<
typename
ET
>
class
SignInstruction
:
public
Instruction
{
public
:
SignInstruction
(
TensorViewInfo
arg
,
TensorViewInfo
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_arg
).
sign
();
}
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
};
}
}
}
}
src/ngraph/runtime/ngvm/external_function.cpp
View file @
d5e93b65
...
...
@@ -52,6 +52,7 @@
#include "ngraph/ops/reduce.hpp"
#include "ngraph/ops/reshape.hpp"
#include "ngraph/ops/select.hpp"
#include "ngraph/ops/sign.hpp"
#include "ngraph/ops/sin.hpp"
#include "ngraph/ops/sinh.hpp"
#include "ngraph/ops/slice.hpp"
...
...
@@ -103,6 +104,7 @@
#include "ngraph/runtime/ngvm/eigen/return.hpp"
#include "ngraph/runtime/ngvm/eigen/scalar_tensor_product.hpp"
#include "ngraph/runtime/ngvm/eigen/select.hpp"
#include "ngraph/runtime/ngvm/eigen/sign.hpp"
#include "ngraph/runtime/ngvm/eigen/sin.hpp"
#include "ngraph/runtime/ngvm/eigen/sinh.hpp"
#include "ngraph/runtime/ngvm/eigen/subtract.hpp"
...
...
@@ -353,6 +355,7 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map()
REGISTER_NUMERIC_UNOP
(
op
::
Exp
,
eigen
::
ExpInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Log
,
eigen
::
LogInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Negative
,
eigen
::
NegateInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Sign
,
eigen
::
SignInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Sin
,
eigen
::
SinInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Sinh
,
eigen
::
SinhInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Tan
,
eigen
::
TanInstruction
);
...
...
test/execute.cpp
View file @
d5e93b65
...
...
@@ -2478,3 +2478,24 @@ TEST(execute, sum_matrix_to_scalar_zero_by_zero)
// input tensors, so let's do this too.
ASSERT_EQ
((
vector
<
float
>
{}),
a
->
get_vector
());
}
TEST
(
execute
,
sign
)
{
auto
shape
=
Shape
{
2
,
3
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
result_type
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Sign
>
(
A
),
result_type
,
op
::
Parameters
{
A
});
auto
manager
=
runtime
::
Manager
::
get
(
"NGVM"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
// Create some tensors for input/output
auto
a
=
backend
->
make_parameterized_tensor_view
<
element
::
Float32
>
(
shape
);
*
a
=
vector
<
float
>
{
1
,
-
2
,
0
,
-
4.8
f
,
4.8
f
,
-
0.0
};
auto
result
=
backend
->
make_parameterized_tensor_view
<
element
::
Float32
>
(
shape
);
(
*
cf
)({
a
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
1
,
-
1
,
0
,
-
1
,
1
,
0
}),
result
->
get_vector
());
}
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