5#ifndef GKO_PUBLIC_CORE_BASE_INDEX_SET_HPP_
6#define GKO_PUBLIC_CORE_BASE_INDEX_SET_HPP_
10#include <initializer_list>
14#include <ginkgo/core/base/array.hpp>
15#include <ginkgo/core/base/exception_helpers.hpp>
16#include <ginkgo/core/base/executor.hpp>
17#include <ginkgo/core/base/types.hpp>
18#include <ginkgo/core/base/utils.hpp>
55template <
typename IndexType =
int32>
68 explicit index_set(std::shared_ptr<const Executor> exec) noexcept
69 : exec_(std::move(exec)),
71 num_stored_indices_{0},
72 subsets_begin_{array<index_type>(exec_)},
73 subsets_end_{array<index_type>(exec_)},
74 superset_cumulative_indices_{array<index_type>(exec_)}
86 explicit index_set(std::shared_ptr<const gko::Executor> exec,
87 std::initializer_list<IndexType> init_list,
88 const bool is_sorted =
false)
89 : exec_(
std::move(exec)),
90 index_space_size_(init_list.size() > 0
91 ? *(
std::max_element(
std::begin(init_list),
92 std::end(init_list))) +
95 num_stored_indices_{static_cast<IndexType>(init_list.size())}
97 GKO_ASSERT(index_space_size_ > 0);
98 this->populate_subsets(
112 explicit index_set(std::shared_ptr<const gko::Executor> exec,
115 const bool is_sorted =
false)
116 : exec_(
std::move(exec)), index_space_size_(size)
118 GKO_ASSERT(index_space_size_ >= indices.
get_size());
119 this->populate_subsets(indices, is_sorted);
151 *
this = std::move(other);
175 if (&other ==
this) {
178 this->index_space_size_ = other.index_space_size_;
179 this->num_stored_indices_ = other.num_stored_indices_;
180 this->subsets_begin_ = other.subsets_begin_;
181 this->subsets_end_ = other.subsets_end_;
182 this->superset_cumulative_indices_ = other.superset_cumulative_indices_;
199 if (&other ==
this) {
202 this->index_space_size_ = std::exchange(other.index_space_size_, 0);
203 this->num_stored_indices_ = std::exchange(other.num_stored_indices_, 0);
204 this->subsets_begin_ = std::move(other.subsets_begin_);
205 this->subsets_end_ = std::move(other.subsets_end_);
206 this->superset_cumulative_indices_ =
207 std::move(other.superset_cumulative_indices_);
221 this->index_space_size_ = 0;
222 this->num_stored_indices_ = 0;
223 this->subsets_begin_.
clear();
224 this->subsets_end_.
clear();
225 this->superset_cumulative_indices_.
clear();
233 std::shared_ptr<const Executor>
get_executor()
const {
return this->exec_; }
315 const bool is_sorted =
false)
const;
331 const bool is_sorted =
false)
const;
352 const bool is_sorted =
false)
const;
373 return this->subsets_begin_.
get_size();
410 const bool is_sorted);
412 std::shared_ptr<const Executor> exec_;
413 index_type index_space_size_;
414 index_type num_stored_indices_;
void clear() noexcept
Definition array.hpp:604
const value_type * get_const_data() const noexcept
Definition array.hpp:682
size_type get_size() const noexcept
Definition array.hpp:656
Definition index_set.hpp:56
index_set(const index_set &other)
Definition index_set.hpp:139
index_set & operator=(index_set &&other)
Definition index_set.hpp:197
array< index_type > to_global_indices() const
const index_type * get_subsets_begin() const
Definition index_set.hpp:381
index_type get_num_elems() const
Definition index_set.hpp:254
index_type get_global_index(index_type local_index) const
array< bool > contains(const array< index_type > &global_indices, const bool is_sorted=false) const
IndexType index_type
Definition index_set.hpp:61
const index_type * get_subsets_end() const
Definition index_set.hpp:391
std::shared_ptr< const Executor > get_executor() const
Definition index_set.hpp:233
void clear() noexcept
Definition index_set.hpp:219
index_set(std::shared_ptr< const Executor > exec) noexcept
Definition index_set.hpp:68
index_type get_local_index(index_type global_index) const
index_set(index_set &&other)
Definition index_set.hpp:159
array< index_type > map_global_to_local(const array< index_type > &global_indices, const bool is_sorted=false) const
index_set(std::shared_ptr< const gko::Executor > exec, std::initializer_list< IndexType > init_list, const bool is_sorted=false)
Definition index_set.hpp:86
index_type get_num_subsets() const
Definition index_set.hpp:371
index_set(std::shared_ptr< const Executor > exec, index_set &&other)
Definition index_set.hpp:148
bool contains(const index_type global_index) const
index_set & operator=(const index_set &other)
Definition index_set.hpp:173
bool is_contiguous() const
Definition index_set.hpp:247
index_set(std::shared_ptr< const gko::Executor > exec, const index_type size, const gko::array< index_type > &indices, const bool is_sorted=false)
Definition index_set.hpp:112
array< index_type > map_local_to_global(const array< index_type > &local_indices, const bool is_sorted=false) const
const index_type * get_superset_indices() const
Definition index_set.hpp:403
index_set(std::shared_ptr< const Executor > exec, const index_set &other)
Definition index_set.hpp:128
index_type get_size() const
Definition index_set.hpp:240
The Ginkgo namespace.
Definition abstract_factory.hpp:20