1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
12 #include <ie_layers.h>
14 namespace InferenceEngine {
15 namespace ShapeInfer {
18 *@brief Implementation of Const inference for TBD layer
20 class DivConstInfer : public ConstInferImpl {
22 explicit DivConstInfer(const std::string& type) : ConstInferImpl(type) {}
24 void inferImpl(const std::vector<Blob::CPtr>& inData,
25 const std::map<std::string, std::string>& params,
26 const std::map<std::string, Blob::Ptr>& blobs,
27 std::vector<Blob::Ptr>& outData) override {
28 size_t numInputs = inData.size();
29 if (inData.size() != 2)
30 THROW_IE_EXCEPTION << "Unsupported number of inputs: " << numInputs << ". 2 inputs is supported";
31 auto* firstBlobBuffer = inData[0]->cbuffer().as<float*>();
32 auto* secondBlobBuffer = inData[1]->cbuffer().as<float*>();
34 if (!firstBlobBuffer || !secondBlobBuffer) {
35 THROW_IE_EXCEPTION << "empty input data";
37 auto outBlob = *outData.begin();
38 auto* outBuffer = outBlob->buffer().as<float*>();
39 if (!outBuffer) THROW_IE_EXCEPTION << "empty output data";
40 if (inData[0]->size() != inData[1]->size()) {
41 THROW_IE_EXCEPTION << "inputs with different shapes are not supported";
43 for (int i = 0; i < outBlob->size(); i++) {
44 if (secondBlobBuffer[i] == 0) THROW_IE_EXCEPTION << "division by zero";
45 outBuffer[i] = firstBlobBuffer[i] / secondBlobBuffer[i];
50 } // namespace ShapeInfer
51 } // namespace InferenceEngine