Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_eltwise_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 "ie_built_in_impl.hpp"
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 #include <algorithm>
13
14 namespace InferenceEngine {
15 namespace ShapeInfer {
16
17 /**
18  *@brief Implementation of Shape inference for EltWise layer
19  */
20 class EltWiseShapeProp : public BuiltInShapeInferImpl {
21 public:
22     explicit EltWiseShapeProp(const std::string& type) : BuiltInShapeInferImpl(type) {}
23
24     void inferShapesImpl(const std::vector<Blob::CPtr>& inBlobs,
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         EltwiseLayer eltwiseLayer(lp);
30         eltwiseLayer.params = params;
31         eltwiseLayer.type = _type;
32         validate(&eltwiseLayer, inBlobs, params, blobs);
33
34         if (inShapes.size() == 1) {
35             outShapes.push_back(inShapes[0]);
36         } else {
37             SizeVector outShape((std::max)(inShapes[0], inShapes[1]));
38             for (size_t ind = 0; ind < outShape.size(); ++ind) {
39                 if (ind < inShapes[0].size() && ind < inShapes[1].size()) {
40                     outShape[ind] = (std::max)(inShapes[0][ind], inShapes[1][ind]);
41                 } else if (ind >= inShapes[0].size()) {
42                     outShape[ind] = inShapes[1][ind];
43                 } else {
44                     outShape[ind] = inShapes[0][ind];
45                 }
46             }
47             outShapes.push_back(outShape);
48         }
49     }
50 };
51
52 }  // namespace ShapeInfer
53 }  // namespace InferenceEngine