MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / operator()

Method operator()

src/backend/cpu/kernel/reduce.hpp:166–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164 common::Transform<data_t<Ti>, compute_t<To>, op> transform;
165 common::Binary<compute_t<To>, op> reduce;
166 void operator()(Param<To> out, CParam<Ti> in, bool change_nan,
167 double nanval) {
168 // Decrement dimension of select dimension
169 af::dim4 dims = in.dims();
170 af::dim4 strides = in.strides();
171 const data_t<Ti> *inPtr = in.get();
172 data_t<To> *const outPtr = out.get();
173
174 compute_t<To> out_val = common::Binary<compute_t<To>, op>::init();
175
176 for (dim_t l = 0; l < dims[3]; l++) {
177 dim_t off3 = l * strides[3];
178
179 for (dim_t k = 0; k < dims[2]; k++) {
180 dim_t off2 = k * strides[2];
181
182 for (dim_t j = 0; j < dims[1]; j++) {
183 dim_t off1 = j * strides[1];
184
185 for (dim_t i = 0; i < dims[0]; i++) {
186 dim_t idx = i + off1 + off2 + off3;
187
188 compute_t<To> in_val = transform(inPtr[idx]);
189 if (change_nan) {
190 in_val = IS_NAN(in_val) ? nanval : in_val;
191 }
192 out_val = reduce(in_val, out_val);
193 }
194 }
195 }
196 }
197
198 *outPtr = data_t<To>(out_val);
199 }
200};
201
202} // namespace kernel

Callers

nothing calls this directly

Calls 6

transformFunction · 0.70
initFunction · 0.50
reduceFunction · 0.50
dimsMethod · 0.45
stridesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected