Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_range_shape_infer.hpp
1 // Copyright (C) 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 <cmath>
13
14 namespace InferenceEngine {
15 namespace ShapeInfer {
16
17 /**
18  *@brief Implementation of Shape inference for Range layer
19  */
20 class RangeShapeProp : public BuiltInShapeInferImpl {
21 public:
22     explicit RangeShapeProp(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         RangeLayer rangeLayer(lp);
30         rangeLayer.params = params;
31         rangeLayer.type = _type;
32         validate(&rangeLayer, inBlobs, params, blobs);
33
34         const size_t RANGE_START = 0;
35         const size_t RANGE_LIMIT = 1;
36         const size_t RANGE_DELTA = 2;
37
38         float start = (inBlobs[RANGE_START]->cbuffer().as<float*>() +
39                        inBlobs[RANGE_START]->getTensorDesc().getBlockingDesc().getOffsetPadding())[0];
40         float limit = (inBlobs[RANGE_LIMIT]->cbuffer().as<float*>() +
41                        inBlobs[RANGE_LIMIT]->getTensorDesc().getBlockingDesc().getOffsetPadding())[0];
42         float delta = (inBlobs[RANGE_DELTA]->cbuffer().as<float*>() +
43                        inBlobs[RANGE_DELTA]->getTensorDesc().getBlockingDesc().getOffsetPadding())[0];
44         size_t work_amount_dst = std::floor(std::abs((limit - start) / delta));
45         outShapes = {{work_amount_dst}};
46     }
47 };
48
49 }  // namespace ShapeInfer
50 }  // namespace InferenceEngine
51