2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef __NNFW_CKER_SPACE_TO_DEPTH_H__
19 #define __NNFW_CKER_SPACE_TO_DEPTH_H__
21 #include "cker/Shape.h"
22 #include "cker/Types.h"
30 inline void SpaceToDepth(const SpaceToDepthParams ¶ms, const Shape &unextended_input_shape,
31 const T *input_data, const Shape &unextended_output_shape, T *output_data)
33 assert(unextended_input_shape.DimensionsCount() <= 4);
34 assert(unextended_output_shape.DimensionsCount() <= 4);
35 const Shape input_shape = Shape::ExtendedShape(4, unextended_input_shape);
36 const Shape output_shape = Shape::ExtendedShape(4, unextended_output_shape);
38 const int output_depth = output_shape.Dims(3);
39 const int output_width = output_shape.Dims(2);
40 const int output_height = output_shape.Dims(1);
42 const int input_depth = input_shape.Dims(3);
43 const int batch_size = input_shape.Dims(0);
45 // Number of continuous values that we can copy in one interation.
46 const int stride = params.block_size * input_depth;
48 for (int batch = 0; batch < batch_size; ++batch)
50 for (int out_h = 0; out_h < output_height; ++out_h)
52 T *output_ptr = output_data + Offset(output_shape, batch, out_h, 0, 0);
53 for (int offset_h = 0; offset_h < params.block_size; ++offset_h)
56 for (int out_w = 0; out_w < output_width; ++out_w)
58 memcpy(dst, input_data, stride * sizeof(T));
71 #endif // __NNFW_CKER_SPACE_TO_DEPTH_H__