Caffe2 - C++ API
A deep learning, cross platform ML framework
replace_nan_op.h
1 #ifndef CAFFE_OPERATORS_REPLACE_NAN_OP_H_
2 #define CAFFE_OPERATORS_REPLACE_NAN_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/logging.h"
6 #include "caffe2/core/operator.h"
7 #include "caffe2/utils/math.h"
8 
9 namespace caffe2 {
10 
11 template <class Context>
12 class ReplaceNaNOp final : public Operator<Context> {
13  public:
14  USE_OPERATOR_CONTEXT_FUNCTIONS;
15  ReplaceNaNOp(const OperatorDef& operator_def, Workspace* ws)
16  : Operator<Context>(operator_def, ws) {}
17 
18  bool RunOnDevice() override {
19  return DispatchHelper<TensorTypes<float, double>>::call(this, Input(0));
20  }
21 
22  template <typename T>
23  void ReplaceNaN(const T& value, const TIndex size, const T* X, T* Y);
24 
25  template <typename T>
26  bool DoRunWithType() {
27  T value = OperatorBase::GetSingleArgument<T>("value", 0);
28 
29  auto& input = Input(0);
30  auto* output = Output(0);
31  output->ResizeLike(input);
32 
33  const T* input_data = input.template data<T>();
34  T* output_data = output->template mutable_data<T>();
35 
36  ReplaceNaN<T>(value, input.size(), input_data, output_data);
37 
38  return true;
39  }
40 };
41 
42 } // namespace caffe2
43 
44 #endif // CAFFE_OPERATORS_REPLACE_NAN_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 ...