21 #include "ngraph/attribute_adapter.hpp"
22 #include "ngraph/dimension.hpp"
23 #include "ngraph/op/util/attr_types.hpp"
24 #include "ngraph/rank.hpp"
25 #include "ngraph/shape.hpp"
31 struct AutoBroadcastSpec;
47 using Dimensions = std::vector<Dimension>;
50 using iterator = Dimensions::iterator;
51 using const_iterator = Dimensions::const_iterator;
52 using reverse_iterator = Dimensions::reverse_iterator;
53 using const_reverse_iterator = Dimensions::const_reverse_iterator;
73 PartialShape(
const std::vector<Dimension::value_type>& dimensions);
186 explicit operator std::vector<Dimension>()
const {
return m_dimensions; }
189 bool operator==(
const PartialShape& partial_shape)
const;
190 bool operator!=(
const PartialShape& partial_shape)
const;
236 iterator
begin() noexcept {
return m_dimensions.begin(); }
240 const_iterator
begin() const noexcept {
return cbegin(); }
244 iterator
end() noexcept {
return m_dimensions.end(); }
248 const_iterator
end() const noexcept {
return cend(); }
252 reverse_iterator
rbegin() noexcept {
return m_dimensions.rbegin(); }
256 const_reverse_iterator
rbegin() const noexcept {
return crbegin(); }
260 reverse_iterator
rend() noexcept {
return m_dimensions.rend(); }
264 const_reverse_iterator
rend() const noexcept {
return crend(); }
268 const_iterator
cbegin() const noexcept {
return m_dimensions.cbegin(); }
272 const_iterator
cend() const noexcept {
return m_dimensions.cend(); }
276 const_reverse_iterator
crbegin() const noexcept {
return m_dimensions.crbegin(); }
280 const_reverse_iterator
crend() const noexcept {
return m_dimensions.crend(); }
283 PartialShape(
bool rank_is_static,
const std::vector<Dimension>& dimensions);
286 bool m_rank_is_static;
295 mutable enum class ShapeType {
305 } m_shape_type{ShapeType::SHAPE_IS_UNKNOWN};
308 Dimensions m_dimensions;
357 std::ostream& operator<<(std::ostream& str,
const PartialShape& shape);
368 const std::vector<int64_t>&
get()
override;
369 void set(
const std::vector<int64_t>& value)
override;
370 static constexpr
DiscreteTypeInfo type_info{
"AttributeAdapter<PartialShape>", 0};
371 const DiscreteTypeInfo& get_type_info()
const override {
return type_info; }
372 operator PartialShape&() {
return m_ref; }
375 std::vector<int64_t> m_buffer;
376 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:171
Class representing a dimension, which may be dynamic (undetermined until runtime),...
Definition: dimension.hpp:35
static Dimension dynamic()
Create a dynamic dimension.
Definition: dimension.hpp:130
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
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:98
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:248
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:272
bool is_dynamic() const
Check if this shape is dynamic.
Definition: partial_shape.hpp:94
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:264
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:256
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:260
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:276
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:240
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:244
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:280
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:236
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:268
reverse_iterator rbegin() noexcept
Returns a read/write reverse iterator that points to the last element in the shape....
Definition: partial_shape.hpp:252
Shape for a tensor.
Definition: shape.hpp:31
Provides access to an attribute of type AT as a value accessor type VAT.
Definition: attribute_adapter.hpp:61
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Dimension Rank
Alias for Dimension, used when the value represents the number of axes in a shape,...
Definition: rank.hpp:27
PartialShape operator+(const PartialShape &s1, const PartialShape &s2)
Elementwise addition of two PartialShape objects.
Implicit broadcast specification.
Definition: attr_types.hpp:323