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_DEPTH_TO_SPACE_H__
19 #define __NNFW_CKER_DEPTH_TO_SPACE_H__
21 #include "cker/Shape.h"
22 #include "cker/Types.h"
30 inline void DepthToSpace(const Shape &unextended_input_shape, const T *input_data,
31 const Shape &unextended_output_shape, T *output_data, int32_t block_size)
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 input_depth = input_shape.Dims(3);
39 const int input_width = input_shape.Dims(2);
40 const int input_height = input_shape.Dims(1);
42 const int output_depth = output_shape.Dims(3);
43 const int batch_size = output_shape.Dims(0);
45 // Number of continuous values that we can copy in one interation.
46 const int stride = block_size * output_depth;
48 for (int batch = 0; batch < batch_size; ++batch)
50 for (int in_h = 0; in_h < input_height; ++in_h)
52 const T *input_ptr = input_data + Offset(input_shape, batch, in_h, 0, 0);
53 for (int offset_h = 0; offset_h < block_size; ++offset_h)
55 const T *src = input_ptr;
56 for (int in_w = 0; in_w < input_width; ++in_w)
58 memcpy(output_data, src, stride * sizeof(T));
59 output_data += stride;
71 #endif // __NNFW_CKER_SPACE_TO_DEPTH_H__