Added iterator to any name (#14766)
* Added iterator to any name
* Fixed code style
* Remove constructor
* Revert "Remove constructor"
This reverts commit 134625a651.
* Add new constructor
* Init iterator
This commit is contained in:
1 parent
808a6b7b83
commit
8a223adf05
2 files changed
+36
-11
No files matched your search
@@ -45,13 +45,17 @@ void set_ov_tensor_legacy_name(Tensor& tensor, const std::string& tensor_name);
|
||||
/// \brief Compile-time descriptor of a first-class value that is a tensor.
|
||||
class OPENVINO_API Tensor {
|
||||
public:
|
||||
Tensor(const element::Type& element_type, const PartialShape& pshape, const std::string& name = "");
|
||||
Tensor(const element::Type& element_type,
|
||||
const PartialShape& pshape,
|
||||
const std::unordered_set<std::string>& names = {});
|
||||
OPENVINO_DEPRECATED("This constructor is deprecated. Please use constructor with set of names")
|
||||
Tensor(const element::Type& element_type, const PartialShape& pshape, const std::string& name);
|
||||
Tensor(const element::Type& element_type, const PartialShape& pshape, Node* node, size_t node_output_number);
|
||||
|
||||
Tensor(const Tensor&) = delete;
|
||||
Tensor& operator=(const Tensor&) = delete;
|
||||
|
||||
std::string get_any_name() const;
|
||||
const std::string& get_any_name() const;
|
||||
const std::unordered_set<std::string>& get_names() const;
|
||||
void set_names(const std::unordered_set<std::string>& names);
|
||||
void add_names(const std::unordered_set<std::string>& names);
|
||||
@@ -130,6 +134,7 @@ protected:
|
||||
std::string m_legacy_name;
|
||||
|
||||
std::unordered_set<std::string> m_names;
|
||||
std::unordered_set<std::string>::const_iterator m_name_it;
|
||||
RTMap m_rt_info;
|
||||
mutable std::atomic_bool m_shape_changed;
|
||||
|
||||
|
||||
@@ -8,10 +8,22 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
ov::descriptor::Tensor::Tensor(const element::Type& element_type,
|
||||
const PartialShape& pshape,
|
||||
const std::unordered_set<std::string>& names)
|
||||
: m_element_type(element_type),
|
||||
m_partial_shape(pshape),
|
||||
m_shape_changed(true) {
|
||||
m_name_it = m_names.cend();
|
||||
set_names(names);
|
||||
}
|
||||
|
||||
ov::descriptor::Tensor::Tensor(const element::Type& element_type, const PartialShape& pshape, const std::string& name)
|
||||
: m_element_type(element_type),
|
||||
m_partial_shape(pshape),
|
||||
m_shape_changed(true) {}
|
||||
m_shape_changed(true) {
|
||||
m_name_it = m_names.cend();
|
||||
}
|
||||
|
||||
ov::descriptor::Tensor::Tensor(const element::Type& element_type,
|
||||
const PartialShape& pshape,
|
||||
@@ -19,7 +31,9 @@ ov::descriptor::Tensor::Tensor(const element::Type& element_type,
|
||||
size_t node_output_number)
|
||||
: m_element_type(element_type),
|
||||
m_partial_shape(pshape),
|
||||
m_shape_changed(true) {}
|
||||
m_shape_changed(true) {
|
||||
m_name_it = m_names.cend();
|
||||
}
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
void ov::descriptor::Tensor::set_tensor_type(const element::Type& element_type, const PartialShape& pshape) {
|
||||
@@ -96,23 +110,29 @@ const std::unordered_set<std::string>& ov::descriptor::Tensor::get_names() const
|
||||
return m_names;
|
||||
}
|
||||
|
||||
std::string ov::descriptor::Tensor::get_any_name() const {
|
||||
if (m_names.empty()) {
|
||||
const std::string& ov::descriptor::Tensor::get_any_name() const {
|
||||
if (m_name_it == m_names.cend()) {
|
||||
throw ngraph::ngraph_error("Attempt to get a name for a Tensor without names");
|
||||
}
|
||||
// As unordered_set for std::string doesn't guaranty the same elements order between runs
|
||||
// we have to manually determine the order by sorting tensor name in lexicographical and returning the first one
|
||||
std::set<std::string> sorted_names(m_names.begin(), m_names.end());
|
||||
return *sorted_names.begin();
|
||||
return *m_name_it;
|
||||
}
|
||||
|
||||
void ov::descriptor::Tensor::set_names(const std::unordered_set<std::string>& names) {
|
||||
m_names = names;
|
||||
m_name_it = m_names.cbegin();
|
||||
for (auto it = m_names.cbegin(); it != m_names.cend(); it++) {
|
||||
if (*it < *m_name_it)
|
||||
// Update any name
|
||||
m_name_it = it;
|
||||
}
|
||||
}
|
||||
|
||||
void ov::descriptor::Tensor::add_names(const std::unordered_set<std::string>& names) {
|
||||
for (const auto& name : names) {
|
||||
m_names.insert(name);
|
||||
auto res = m_names.insert(name);
|
||||
if (m_name_it == m_names.end() || *res.first < *m_name_it)
|
||||
// Update any name
|
||||
m_name_it = res.first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user