Caffe2 - C++ API
A deep learning, cross platform ML framework
Related Pages
Modules
Data Structures
Files
C++ API
Python API
GitHub
File List
Globals
caffe2
operators
abs_op.cc
1
#include "caffe2/operators/elementwise_op.h"
2
#include "caffe2/utils/math.h"
3
4
namespace
caffe2
{
5
6
struct
AbsCPUFunctor
{
7
template
<
typename
T>
8
inline
void
9
operator()(
const
int
n,
const
T* x, T* y,
CPUContext
* device_context) {
10
math::Abs<T, CPUContext>(n, x, y, device_context);
11
}
12
};
13
14
struct
AbsGradientCPUFunctor
{
15
template
<
typename
T>
16
inline
void
17
Run(
const
int
n,
const
T* x,
const
T* dy, T* dx,
CPUContext
*
/* unused */
) {
18
ConstEigenVectorArrayMap<T> dyM(dy, n);
19
ConstEigenVectorArrayMap<T> xM(x, n);
20
EigenVectorMap<T>(dx, n) =
21
(xM == T(0)).select(T(0), (xM > T(0)).select(dyM, -dyM));
22
}
23
};
24
25
REGISTER_CPU_OPERATOR(
26
Abs,
27
UnaryElementwiseOp
<
TensorTypes<float>
,
CPUContext
,
AbsCPUFunctor
>);
28
REGISTER_CPU_OPERATOR(
29
AbsGradient,
30
BinaryElementwiseOp
<
31
TensorTypes<float>
,
32
CPUContext
,
33
WithoutBroadcast<AbsGradientCPUFunctor>
>);
34
35
OPERATOR_SCHEMA(Abs)
36
.NumInputs(1)
37
.NumOutputs(1)
38
.IdenticalTypeAndShape()
39
.SetDoc(R
"DOC(
40
Calculates the absolute value of the given input tensor, element-wise.
41
)DOC")
42
.Input(0,
"input"
,
"Input tensor"
)
43
.Output(
44
0,
45
"output"
,
46
"The absolute value of the input tensor computed element-wise"
)
47
.InheritOnnxSchema(
"Abs"
);
48
49
OPERATOR_SCHEMA(AbsGradient).NumInputs(2).NumOutputs(1).IdenticalTypeAndShape();
50
51
class
GetAbsGradient
:
public
GradientMakerBase
{
52
using
GradientMakerBase::GradientMakerBase;
53
vector<OperatorDef> GetGradientDefs()
override
{
54
return
SingleGradientDef(
55
"AbsGradient"
,
56
""
,
57
std::vector<string>{I(0), GO(0)},
58
std::vector<string>{GI(0)});
59
}
60
};
61
REGISTER_GRADIENT(Abs,
GetAbsGradient
);
62
}
// namespace caffe2
caffe2::GradientMakerBase
Definition:
operator_gradient.h:47
caffe2::AbsGradientCPUFunctor
Definition:
abs_op.cc:14
caffe2::CPUContext
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition:
context.h:66
caffe2::GetAbsGradient
Definition:
abs_op.cc:51
caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition:
convert_encoded_to_raw_leveldb.cc:47
caffe2::BinaryElementwiseOp
Performs a binary operation (e.g.
Definition:
elementwise_op.h:159
caffe2::TensorTypes
Definition:
operator.h:547
caffe2::UnaryElementwiseWithArgsOp
Definition:
elementwise_op.h:36
caffe2::AbsCPUFunctor
Definition:
abs_op.cc:6
caffe2::WithoutBroadcast
Definition:
elementwise_op.h:246
Generated on Thu Apr 19 2018 13:03:54 for Caffe2 - C++ API by
1.8.11