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
cos_op.cc
1
#include "caffe2/operators/elementwise_op.h"
2
#include "caffe2/utils/math.h"
3
4
namespace
caffe2
{
5
6
struct
CosCPUFunctor
{
7
template
<
typename
T>
8
inline
void
9
operator()(
const
int
n,
const
T* x, T* y,
CPUContext
* device_context) {
10
math::Cos<T, CPUContext>(n, x, y, device_context);
11
}
12
};
13
14
struct
CosGradientCPUFunctor
{
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) = -dyM * sin(xM);
21
}
22
};
23
24
REGISTER_CPU_OPERATOR(
25
Cos,
26
UnaryElementwiseOp
<
TensorTypes<float>
,
CPUContext
,
CosCPUFunctor
>);
27
REGISTER_CPU_OPERATOR(
28
CosGradient,
29
BinaryElementwiseOp
<
30
TensorTypes<float>
,
31
CPUContext
,
32
WithoutBroadcast<CosGradientCPUFunctor>
>);
33
34
OPERATOR_SCHEMA(Cos)
35
.NumInputs(1)
36
.NumOutputs(1)
37
.IdenticalTypeAndShape()
38
.SetDoc(R
"DOC(
39
Calculates the cosine of the given input tensor, element-wise.
40
)DOC")
41
.Input(0,
"input"
,
"Input tensor"
)
42
.Output(
43
0,
44
"output"
,
45
"The cosine of the input tensor computed element-wise"
);
46
47
OPERATOR_SCHEMA(CosGradient).NumInputs(2).NumOutputs(1).IdenticalTypeAndShape();
48
49
class
GetCosGradient
:
public
GradientMakerBase
{
50
using
GradientMakerBase::GradientMakerBase;
51
vector<OperatorDef> GetGradientDefs()
override
{
52
return
SingleGradientDef(
53
"CosGradient"
,
54
""
,
55
std::vector<string>{I(0), GO(0)},
56
std::vector<string>{GI(0)});
57
}
58
};
59
REGISTER_GRADIENT(Cos,
GetCosGradient
);
60
}
// namespace caffe2
caffe2::GradientMakerBase
Definition:
operator_gradient.h:47
caffe2::GetCosGradient
Definition:
cos_op.cc:49
caffe2::CPUContext
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition:
context.h:66
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::CosCPUFunctor
Definition:
cos_op.cc:6
caffe2::WithoutBroadcast
Definition:
elementwise_op.h:246
caffe2::CosGradientCPUFunctor
Definition:
cos_op.cc:14
Generated on Thu Apr 19 2018 13:03:55 for Caffe2 - C++ API by
1.8.11