BlockExpandOpTest.cpp 4.1 KB
Newer Older
H
hedaoyuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed 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. */

#include <gtest/gtest.h>
#include "FunctionTest.h"

namespace paddle {

20
TEST(BlockExpandForward, real) {
H
hedaoyuan 已提交
21 22 23 24
  for (size_t batchSize : {5}) {
    for (size_t channels : {1, 5}) {
      for (size_t inputHeight : {5, 33}) {
        for (size_t inputWidth : {5, 32}) {
H
hedaoyuan 已提交
25 26 27 28 29 30 31
          for (size_t block : {1, 3, 5}) {
            for (size_t stride : {1, 2}) {
              for (size_t padding : {0, 1}) {
                // init Test object
                std::vector<size_t> strides = {stride, stride};
                std::vector<size_t> paddings = {padding, padding};
                std::vector<size_t> blocks = {block, block};
32
                CpuGpuFuncCompare test("BlockExpand",
H
hedaoyuan 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
                                       FuncConfig()
                                           .set("strides", strides)
                                           .set("paddings", paddings)
                                           .set("blocks", blocks));

                size_t outputHeight =
                    1 +
                    (inputHeight + 2 * padding - block + stride - 1) / stride;
                size_t outputWidth =
                    1 +
                    (inputWidth + 2 * padding - block + stride - 1) / stride;
                TensorShape inputShape =
                    TensorShape({batchSize, channels, inputHeight, inputWidth});
                TensorShape outputShape =
                    TensorShape({batchSize,
                                 outputHeight * outputWidth,
                                 channels * block * block});
                test.addInputs(BufferArg(VALUE_TYPE_FLOAT, inputShape));
                test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, outputShape));
                // run Function
                test.run();
              }
            }
          }
        }
      }
    }
  }
}

63
TEST(BlockExpandBackward, real) {
H
hedaoyuan 已提交
64 65 66 67
  for (size_t batchSize : {5}) {
    for (size_t channels : {1, 5}) {
      for (size_t inputHeight : {5, 33}) {
        for (size_t inputWidth : {5, 32}) {
H
hedaoyuan 已提交
68 69 70 71 72 73 74
          for (size_t block : {1, 3, 5}) {
            for (size_t stride : {1, 2}) {
              for (size_t padding : {0, 1}) {
                // init Test object
                std::vector<size_t> strides = {stride, stride};
                std::vector<size_t> paddings = {padding, padding};
                std::vector<size_t> blocks = {block, block};
75
                CpuGpuFuncCompare test("BlockExpandGrad",
H
hedaoyuan 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                                       FuncConfig()
                                           .set("strides", strides)
                                           .set("paddings", paddings)
                                           .set("blocks", blocks));

                size_t outputHeight =
                    1 +
                    (inputHeight + 2 * padding - block + stride - 1) / stride;
                size_t outputWidth =
                    1 +
                    (inputWidth + 2 * padding - block + stride - 1) / stride;
                TensorShape inputShape =
                    TensorShape({batchSize, channels, inputHeight, inputWidth});
                TensorShape outputShape =
                    TensorShape({batchSize,
                                 outputHeight * outputWidth,
                                 channels * block * block});
                test.addInputs(BufferArg(VALUE_TYPE_FLOAT, outputShape));
                test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, inputShape),
                                ADD_TO);
                // run Function
                test.run();
              }
            }
          }
        }
      }
    }
  }
}

}  // namespace paddle