Publishing R3
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_permute_shape_infer.hpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #pragma once
7
8 #include <description_buffer.hpp>
9 #include <ie_layer_validators.hpp>
10 #include "impl_register.hpp"
11 #include <ie_layers.h>
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16
17 namespace InferenceEngine {
18 namespace ShapeInfer {
19
20 /**
21  *@brief Implementation of Shape inference for Permute layer
22  */
23 class PermuteShapeProp : public BuiltInShapeInferImpl {
24 public:
25     explicit PermuteShapeProp(const std::string& type) : BuiltInShapeInferImpl(type) {}
26
27     void inferShapesImpl(const std::vector<SizeVector>& inShapes,
28                          const std::map<std::string, std::string>& params,
29                          const std::map<std::string, Blob::Ptr>& blobs,
30                          std::vector<SizeVector>& outShapes) override {
31         LayerParams lp{};
32         CNNLayer permuteLayer(lp);
33         permuteLayer.params = params;
34         permuteLayer.type = _type;
35         validate(&permuteLayer, inShapes, params, blobs);
36
37         std::vector<size_t> order;
38         std::vector<int> layerOrder = permuteLayer.GetParamAsInts("order");
39         for (auto ord : layerOrder)
40             order.push_back(static_cast<size_t>(ord));
41
42         SizeVector outShape;
43         for (size_t i = 0; i < inShapes[0].size(); i++) {
44             outShape.push_back(inShapes[0][order[i]]);
45         }
46         outShapes.emplace_back(outShape);
47     }
48 };
49
50 }  // namespace ShapeInfer
51 }  // namespace InferenceEngine