1 #include "caffe2/operators/mod_op.h" 3 #include "caffe2/core/operator.h" 4 #include "caffe2/core/tensor.h" 10 bool ModOp<CPUContext>::DoRunWithType() {
11 auto& data = Input(DATA);
13 const auto* data_ptr = data.template data<T>();
15 auto* output = Output(0);
16 output->ResizeLike(Input(DATA));
17 auto* output_ptr = output->template mutable_data<T>();
19 for (
auto i = 0; i < N; i++) {
20 output_ptr[i] = data_ptr[i] % divisor_;
21 if (output_ptr[i] && sign_follow_divisor_ &&
22 ((output_ptr[i] > 0) != (divisor_ > 0))) {
23 output_ptr[i] += divisor_;
31 REGISTER_CPU_OPERATOR(Mod, ModOp<CPUContext>);
35 .Arg(
"divisor",
"The divisor of the modulo operation. Must >= 1")
37 "sign_follow_divisor",
38 "The sign of output follows Dividend if set to `false`. \ 39 Otherwise follows Divisor")
40 .IdenticalTypeAndShape()
41 .AllowInplace({{0, 0}})
43 Elementwise modulo operation. Each element in the output is the modulo result 44 of the corresponding elment in the input data. The divisor of the modulo is 45 provided by the operator argument `divisor`. 47 .Input(0, "data",
"input int32 or int64 data")
48 .Output(0,
"output",
"output of data with modulo operation applied");
50 SHOULD_NOT_DO_GRADIENT(ModOp);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...