9 #include "ngraph/attribute_adapter.hpp"
10 #include "ngraph/dimension.hpp"
11 #include "ngraph/op/util/attr_types.hpp"
12 #include "ngraph/rank.hpp"
13 #include "ngraph/shape.hpp"
19 struct AutoBroadcastSpec;
35 using Dimensions = std::vector<Dimension>;
38 using iterator = Dimensions::iterator;
39 using const_iterator = Dimensions::const_iterator;
40 using reverse_iterator = Dimensions::reverse_iterator;
41 using const_reverse_iterator = Dimensions::const_reverse_iterator;
61 PartialShape(
const std::vector<Dimension::value_type>& dimensions);
174 explicit operator std::vector<Dimension>()
const {
return m_dimensions; }
177 bool operator==(
const PartialShape& partial_shape)
const;
178 bool operator!=(
const PartialShape& partial_shape)
const;
224 iterator
begin() noexcept {
return m_dimensions.begin(); }
228 const_iterator
begin() const noexcept {
return cbegin(); }
232 iterator
end() noexcept {
return m_dimensions.end(); }
236 const_iterator
end() const noexcept {
return cend(); }
240 reverse_iterator
rbegin() noexcept {
return m_dimensions.rbegin(); }
244 const_reverse_iterator
rbegin() const noexcept {
return crbegin(); }
248 reverse_iterator
rend() noexcept {
return m_dimensions.rend(); }
252 const_reverse_iterator
rend() const noexcept {
return crend(); }
256 const_iterator
cbegin() const noexcept {
return m_dimensions.cbegin(); }
260 const_iterator
cend() const noexcept {
return m_dimensions.cend(); }
264 const_reverse_iterator
crbegin() const noexcept {
return m_dimensions.crbegin(); }
268 const_reverse_iterator
crend() const noexcept {
return m_dimensions.crend(); }
272 PartialShape(
bool rank_is_static,
const std::vector<Dimension>& dimensions);
275 bool m_rank_is_static;
284 mutable enum class ShapeType {
294 } m_shape_type{ShapeType::SHAPE_IS_UNKNOWN};
297 Dimensions m_dimensions;
346 std::ostream& operator<<(std::ostream& str,
const PartialShape& shape);
357 const std::vector<int64_t>&
get()
override;
358 void set(
const std::vector<int64_t>& value)
override;
359 static constexpr
DiscreteTypeInfo type_info{
"AttributeAdapter<PartialShape>", 0};
360 const DiscreteTypeInfo& get_type_info()
const override {
return type_info; }
361 operator PartialShape&() {
return m_ref; }
365 std::vector<int64_t> m_buffer;
366 bool m_buffer_valid{
false};
void set(const std::vector< int64_t > &value) override
Sets the value.
const std::vector< int64_t > & get() override
Returns the value.
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:161
Class representing a dimension, which may be dynamic (undetermined until runtime),...
Definition: dimension.hpp:23
static Dimension dynamic()
Create a dynamic dimension.
Definition: dimension.hpp:118
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:34
bool all_non_negative() const
Returns true if all static dimensions of the tensor are non-negative, else false.
Rank rank() const
Get the rank of the shape.
Definition: partial_shape.hpp:86
bool same_scheme(const PartialShape &s) const
Check whether this shape represents the same scheme as the argument.
bool is_static() const
Check if this shape is static.
const_iterator end() const noexcept
Returns a read-only (constant) iterator that points one past the last element in the shape....
Definition: partial_shape.hpp:236
const_iterator cend() const noexcept
Returns a read-only (constant) iterator that points one past the last element in the shape....
Definition: partial_shape.hpp:260
bool is_dynamic() const
Check if this shape is dynamic.
Definition: partial_shape.hpp:82
Shape get_shape() const
Get the unique shape.
const_reverse_iterator rend() const noexcept
Returns a read-only (constant) reverse iterator that points to one before the first element in the sh...
Definition: partial_shape.hpp:252
const Dimension & operator[](size_t i) const
Index operator for PartialShape.
bool merge_rank(Rank r)
Checks that this shape's rank is compatible with r, and, if this shape's rank is dynamic and r is sta...
static bool broadcast_merge_into(PartialShape &dst, const PartialShape &src, const op::AutoBroadcastSpec &autob)
Try to merge one shape into another along with implicit broadcasting.
bool relaxes(const PartialShape &s) const
Check whether this shape is a relaxation of the argument.
const_reverse_iterator rbegin() const noexcept
Returns a read-only (constant) reverse iterator that points to the last element in the shape....
Definition: partial_shape.hpp:244
reverse_iterator rend() noexcept
Returns a read/write reverse iterator that points to one before the first element in the shape....
Definition: partial_shape.hpp:248
PartialShape()
Constructs a static PartialShape with zero rank (the shape of a scalar).
friend NGRAPH_API std::ostream & operator<<(std::ostream &str, const PartialShape &shape)
Inserts a human-readable representation of a PartialShape into an output stream.
friend PartialShape operator+(const PartialShape &s1, const PartialShape &s2)
Elementwise addition of two PartialShape objects.
const_reverse_iterator crbegin() const noexcept
Returns a read-only (constant) reverse iterator that points to the last element in the shape....
Definition: partial_shape.hpp:264
bool compatible(const PartialShape &s) const
Check whether this shape is compatible with the argument, i.e., whether it is possible to merge them.
PartialShape(std::initializer_list< Dimension > init)
Constructs a shape with static rank from an initializer list of Dimension.
const_iterator begin() const noexcept
Returns a read-only (constant) iterator that points to the first element in the shape....
Definition: partial_shape.hpp:228
Dimension & operator[](size_t i)
Index operator for PartialShape.
Shape get_max_shape() const
Get the max bounding shape.
iterator end() noexcept
Returns a read/write iterator that points one past the last element in the shape. Iteration is done i...
Definition: partial_shape.hpp:232
PartialShape(const std::vector< Dimension::value_type > &dimensions)
Constructs a PartialShape with static rank from a vector of dimensions values.
const_reverse_iterator crend() const noexcept
Returns a read-only (constant) reverse iterator that points to one before the first element in the sh...
Definition: partial_shape.hpp:268
Shape get_min_shape() const
Get the min bounding shape.
PartialShape(const std::vector< Dimension > &dimensions)
Constructs a PartialShape with static rank from a vector of Dimension.
bool refines(const PartialShape &s) const
Check whether this shape is a refinement of the argument.
Shape to_shape() const
Convert a static PartialShape to a Shape.
iterator begin() noexcept
Returns a read/write iterator that points to the first element in the shape. Iteration is done in ord...
Definition: partial_shape.hpp:224
static PartialShape dynamic(Rank r=Rank::dynamic())
Construct a PartialShape with the given rank and all dimensions (if any) dynamic.
static bool merge_into(PartialShape &dst, const PartialShape &src)
Try to merge one shape into another.
PartialShape(const Shape &shape)
Constructs a static PartialShape from a Shape.
const_iterator cbegin() const noexcept
Returns a read-only (constant) iterator that points to the first element in the shape....
Definition: partial_shape.hpp:256
reverse_iterator rbegin() noexcept
Returns a read/write reverse iterator that points to the last element in the shape....
Definition: partial_shape.hpp:240
Shape for a tensor.
Definition: shape.hpp:19
Provides access to an attribute of type AT as a value accessor type VAT.
Definition: attribute_adapter.hpp:49
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Dimension Rank
Alias for Dimension, used when the value represents the number of axes in a shape,...
Definition: rank.hpp:15
PartialShape operator+(const PartialShape &s1, const PartialShape &s2)
Elementwise addition of two PartialShape objects.
Implicit broadcast specification.
Definition: attr_types.hpp:311