Caffe2 - C++ API
A deep learning, cross platform ML framework
elementwise_div_op.cc
1 
17 #include "caffe2/operators/elementwise_op.h"
18 
19 namespace caffe2 {
20 
21 // See the operations supported here:
22 // https://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html
23 #define EIGEN_DIV(x, y) ((x) / (y))
24 EIGEN_FUNCTOR(Div, EIGEN_DIV, NumericTypes, SameTypeAsInput);
25 #undef EIGEN_DIV
26 
27 void ElementWiseDivide(
28  CPUContext& /* unused context */,
29  const int n,
30  float* dXdata,
31  float* dYdata,
32  const float* dZdata,
33  const float* Ydata,
34  const float* Zdata) {
35  ConstEigenVectorArrayMap<float> dZdataVec(dZdata, n);
36  ConstEigenVectorArrayMap<float> YdataVec(Ydata, n);
37  ConstEigenVectorArrayMap<float> ZdataVec(Zdata, n);
38  EigenVectorArrayMap<float>(dXdata, n) = dZdataVec / YdataVec;
39  EigenVectorArrayMap<float>(dYdata, n) = - (dZdataVec * ZdataVec) / YdataVec;
40 }
41 
42 REGISTER_CPU_OPERATOR(DivGradient, DivGradientOp<CPUContext>);
43 }
Copyright (c) 2016-present, Facebook, Inc.