1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include "blob_factory.hpp"
12 using namespace InferenceEngine;
14 Blob::Ptr Blob::CreateFromData(const DataPtr &data) {
15 return CreateBlobFromData(data);
18 Data::Data(const std::string &name, Precision _precision, Layout layout): precision(_precision), layout(layout),
19 name(name), userObject({0}),
20 tensorDesc(_precision, layout) {}
22 Data::Data(const std::string &name, const SizeVector &a_dims, Precision _precision, Layout layout)
23 : precision(_precision), layout(layout), dims(a_dims), name(name), userObject({0}),
24 tensorDesc(_precision, a_dims, layout) {
25 SizeVector tensorDims = a_dims;
26 std::reverse(tensorDims.begin(), tensorDims.end());
27 tensorDesc = TensorDesc(_precision, tensorDims, layout);
30 Data::Data(const std::string &name, const TensorDesc &desc): tensorDesc(desc), precision(desc.getPrecision()),
31 layout(desc.getLayout()), dims(desc.getDims()),
32 name(name), userObject({0}) {
33 std::reverse(dims.begin(), dims.end());
36 const SizeVector& Data::getDims() const {
37 return tensorDesc.getDims();
40 const Precision& Data::getPrecision() const {
44 return tensorDesc.getPrecision();
47 const TensorDesc& Data::getTensorDesc() const {
48 if ((tensorDesc.getDims().size() == 0 && tensorDesc.getDims() != dims) ||
49 (tensorDesc.getLayout() == Layout::ANY && layout != Layout::ANY) ||
50 (!tensorDesc.getPrecision() && precision)) {
51 THROW_IE_EXCEPTION << "Tensor descriptor is empty!";
53 if (precision && tensorDesc.getPrecision() != precision) {
54 tensorDesc.setPrecision(precision);
59 bool Data::isInitialized() const {
60 return !dims.empty() || !tensorDesc.getDims().empty() || layout == SCALAR;
63 void Data::setDims(const SizeVector &a_dims) {
65 std::reverse(dims.begin(), dims.end());
66 tensorDesc.setDims(a_dims);
69 void Data::setBatchSize(size_t batch_size) {
71 dims = tensorDesc.getDims();
72 std::reverse(dims.begin(), dims.end());
76 dims.at(dims.size() - 1) = batch_size;
77 SizeVector normalDims = dims;
78 std::reverse(normalDims.begin(), normalDims.end());
79 tensorDesc.setDims(normalDims);
82 void Data::setLayout(Layout layout) {
83 tensorDesc.setLayout(layout);
84 this->layout = layout;
87 void Data::reshape(const SizeVector &a_dims, Layout a_layout) {
90 std::reverse(dims.begin(), dims.end());
92 tensorDesc.reshape(a_dims, layout);
95 CNNLayerWeakPtr &Data::getCreatorLayer() {
99 const std::string &Data::getName() const {
103 std::map<std::string, CNNLayerPtr> &Data::getInputTo() {
107 const UserValue& Data::getUserObject() const {
111 Layout Data::getLayout() const {
112 if (tensorDesc.getLayout() == Layout::ANY && layout != Layout::ANY)
114 return tensorDesc.getLayout();
117 void Data::setPrecision(const Precision & precision) {
118 this->precision = precision;
119 tensorDesc.setPrecision(precision);