Caffe2 - C++ API
A deep learning, cross platform ML framework
scale_op.h
1 #ifndef CAFFE2_OPERATORS_SCALE_OP_H_
2 #define CAFFE2_OPERATORS_SCALE_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/operator.h"
6 #include "caffe2/utils/math.h"
7 
8 namespace caffe2 {
9 
10 template <class Context>
11 class ScaleOp final : public Operator<Context> {
12  public:
13  USE_OPERATOR_CONTEXT_FUNCTIONS;
14  ScaleOp(const OperatorDef& operator_def, Workspace* ws)
15  : Operator<Context>(operator_def, ws),
16  scale_(OperatorBase::GetSingleArgument<float>("scale", 1.0)) {}
17 
18  template <typename T>
19  bool DoRunWithType() {
20  auto& X = Input(0);
21  auto* Y = Output(0);
22  Y->ResizeLike(X);
23  math::Scale<T, Context>(
24  X.size(),
25  scale_,
26  X.template data<T>(),
27  Y->template mutable_data<T>(),
28  &context_);
29  return true;
30  }
31 
32  bool RunOnDevice() override {
33  return DispatchHelper<TensorTypes<float>>::call(this, Input(0));
34  }
35 
36  protected:
37  float scale_;
38 };
39 
40 } // namespace caffe2
41 
42 #endif // CAFFE2_OPERATORS_SCALE_OP_H_
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...