Caffe2 - C++ API
A deep learning, cross platform ML framework
replace_nan_op.cc
1 #include "caffe2/operators/replace_nan_op.h"
2 
3 namespace caffe2 {
4 
5 template <>
6 template <typename T>
7 void ReplaceNaNOp<CPUContext>::ReplaceNaN(
8  const T& value,
9  const int64_t size,
10  const T* X,
11  T* Y) {
12  for (int64_t i = 0; i < size; i++) {
13  if (std::isnan(X[i])) {
14  Y[i] = value;
15  } else {
16  Y[i] = X[i];
17  }
18  }
19 }
20 
21 REGISTER_CPU_OPERATOR(ReplaceNaN, ReplaceNaNOp<CPUContext>);
22 
23 OPERATOR_SCHEMA(ReplaceNaN)
24  .NumInputs(1)
25  .NumOutputs(1)
26  .AllowInplace({{0, 0}})
27  .IdenticalTypeAndShape()
28  .SetDoc(R"DOC(
29 Replace the NaN (not a number) element in the input tensor with argument `value`
30 )DOC")
31  .Arg("value (optional)", "the value to replace NaN, the default is 0")
32  .Input(0, "input", "Input tensor")
33  .Input(1, "output", "Output tensor");
34 
35 SHOULD_NOT_DO_GRADIENT(ReplaceNaN);
36 
37 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13