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