tensor.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include <memory>
20 #include <string>
21 
22 #include "ngraph/partial_shape.hpp"
23 #include "ngraph/shape.hpp"
24 #include "ngraph/type/element_type.hpp"
25 
26 namespace ngraph
27 {
28  class Node;
29 
30  namespace descriptor
31  {
32  /// \brief Compile-time descriptor of a first-class value that is a tensor.
33  class NGRAPH_API Tensor
34  {
35  Tensor(const Tensor&) = delete;
36  Tensor& operator=(const Tensor&) = delete;
37 
38  public:
39  Tensor(const element::Type& element_type,
40  const PartialShape& pshape,
41  const std::string& name);
42  Tensor(const element::Type& element_type,
43  const PartialShape& pshape,
44  Node* node,
45  size_t node_output_number);
46 
47  const std::string& get_name() const;
48  void set_name(const std::string& name);
49  void set_tensor_type(const element::Type& element_type, const PartialShape& pshape);
50  void set_element_type(const element::Type& elemenet_type);
51  void set_partial_shape(const PartialShape& partial_shape);
52 
53  const element::Type& get_element_type() const { return m_element_type; }
54  const Shape& get_shape() const;
55  const PartialShape& get_partial_shape() const { return m_partial_shape; }
56  void set_pool_offset(size_t);
57  size_t get_pool_offset() const;
58 
59  size_t size() const;
60 
61  protected:
62  element::Type m_element_type;
63 
64  // TODO(amprocte): For now we are maintaining both m_shape and m_partial_shape fields,
65  // with m_shape possibly being invalid (get_shape will throw an exception if it
66  // is). This is because get_shape() returns a const reference. I think ideally we
67  // should refactor so that get_shape returns by value.
68  Shape m_shape;
69  PartialShape m_partial_shape;
70  Node* m_node{nullptr};
71  size_t m_node_output_number{0};
72 
73  std::string m_name;
74  size_t m_pool_offset{0};
75  };
76 
77  NGRAPH_API
78  std::ostream& operator<<(std::ostream&, const ngraph::descriptor::Tensor&);
79  }
80 }
ngraph::descriptor::Tensor
Compile-time descriptor of a first-class value that is a tensor.
Definition: tensor.hpp:34
ngraph::set_element_type
void set_element_type(const element::Type &element_type)
Set the element type. Must be compatible with the current element type.
ngraph::element::Type
Definition: element_type.hpp:61
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28