ea374ab39656f09de7d988b19ecc528ce7452405
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_concat_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 "ie_built_in_impl.hpp"
9 #include <map>
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 namespace InferenceEngine {
15 namespace ShapeInfer {
16
17 /**
18  *@brief Implementation of Shape inference for Concat layer
19  */
20 class ConcatShapeProp : public BuiltInShapeInferImpl {
21 public:
22     explicit ConcatShapeProp(const std::string& type) : BuiltInShapeInferImpl(type) {}
23
24     void inferShapesImpl(const std::vector<SizeVector>& inShapes,
25                          const std::map<std::string, std::string>& params,
26                          const std::map<std::string, Blob::Ptr>& blobs,
27                          std::vector<SizeVector>& outShapes) override {
28         LayerParams lp{};
29         ConcatLayer concatLayer(lp);
30         concatLayer.params = params;
31         concatLayer.type = _type;
32         validate(&concatLayer, inShapes, params, blobs);
33
34         size_t sum(0);
35         size_t axis = concatLayer._axis;
36         outShapes.push_back(inShapes[0]);
37         for (const auto& inShape : inShapes) {
38             if (axis >= inShape.size())
39                 THROW_IE_EXCEPTION << "Axis can't be more then number of input shapes";
40             sum += inShape[axis];
41         }
42         outShapes[0][axis] = sum;
43     }
44 };
45
46 }  // namespace ShapeInfer
47 }  // namespace InferenceEngine