cjolivier01 commented on a change in pull request #9688: [MXNET-108] Adding BilinearResize2D and AdaptiveAvgPool2d operators URL: https://github.com/apache/incubator-mxnet/pull/9688#discussion_r175573325
########## File path: src/operator/adaptive_avg_pooling.cc ########## @@ -0,0 +1,222 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*! + * Copyright (c) 2018 by Contributors + * \file adaptive_avg_pooling.cc + * \brief adaptive average pooling operator + * \author Hang Zhang +*/ +#include "adaptive_avg_pooling-inl.h" +#include "elemwise_op_common.h" + +#define START_IND(a, b, c) static_cast<int>(floor(static_cast<float>(a * c) / b)) +#define END_IND(a, b, c) static_cast<int>(ceil(static_cast<float>((a + 1) * c) / b)) + +namespace mxnet { +namespace op { + +using namespace mshadow; + +template<typename real> +static void SpatialAdaptiveAveragePooling_updateOutput_frame( + real *input_p, + real *output_p, + int64_t sizeD, + int64_t isizeH, + int64_t isizeW, + int64_t osizeH, + int64_t osizeW, + int64_t istrideD, + int64_t istrideH, + int64_t istrideW) { + int64_t d; +#pragma omp parallel for private(d) + for (d = 0; d < sizeD; d++) { + /* loop over output */ + int64_t oh, ow; + for (oh = 0; oh < osizeH; oh++) { + int istartH = START_IND(oh, osizeH, isizeH); + int iendH = END_IND(oh, osizeH, isizeH); + int kH = iendH - istartH; + + for (ow = 0; ow < osizeW; ow++) { + int istartW = START_IND(ow, osizeW, isizeW); + int iendW = END_IND(ow, osizeW, isizeW); + int kW = iendW - istartW; + + /* local pointers */ + real *ip = input_p + d*istrideD + istartH*istrideH + istartW*istrideW; + real *op = output_p + d*osizeH*osizeW + oh*osizeW + ow; + + /* compute local average: */ + real sum = 0; + int ih, iw; Review comment: not: int declaration inside for statement since it isn;t used outside of the for loop, so that scope isn't required ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
