Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / const_infer / ie_power_const_infer.hpp
1 // Copyright (C) 2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <ie_blob.h>
8 #include <map>
9 #include <memory>
10 #include <cmath>
11 #include <string>
12 #include <vector>
13 #include <ie_layers.h>
14 #include "ie_const_infer_impl.hpp"
15
16 namespace InferenceEngine {
17 namespace ShapeInfer {
18
19 /**
20  *@brief Implementation of Const inference for TBD layer
21  */
22 class PowerConstInfer : public ConstInferImpl {
23 public:
24     explicit PowerConstInfer(const std::string& type) : ConstInferImpl(type) {}
25
26     void inferImpl(const std::vector<Blob::CPtr>& inData,
27                    const std::map<std::string, std::string>& params,
28                    const std::map<std::string, Blob::Ptr>& blobs,
29                    std::vector<Blob::Ptr>& outData) override {
30         LayerParams lp{};
31         PowerLayer layer(lp);
32         layer.params = params;
33         layer.type = _type;
34         _validator->parseParams(&layer);
35
36         float scale = layer.scale;
37         float power = layer.power;
38         float shift = layer.offset;
39
40         // TODO: check for access and sizes
41         auto* input = inData[0]->cbuffer().as<float*>();
42         auto* output = outData[0]->buffer().as<float*>();
43         size_t dataSize = inData[0]->size();
44
45         if (power == 1.0f) {
46             for (int i = 0; i < dataSize; i++) {
47                 output[i] = input[i] * scale + shift;
48             }
49         } else {
50             for (int i = 0; i < dataSize; i++) {
51                 output[i] = pow(input[i] * scale + shift, power);
52             }
53         }
54     }
55 };
56
57 }  // namespace ShapeInfer
58 }  // namespace InferenceEngine