33#ifndef GKO_PUBLIC_CORE_BASE_INDEX_SET_HPP_
34#define GKO_PUBLIC_CORE_BASE_INDEX_SET_HPP_
38#include <initializer_list>
43#include <ginkgo/core/base/array.hpp>
44#include <ginkgo/core/base/exception_helpers.hpp>
45#include <ginkgo/core/base/executor.hpp>
46#include <ginkgo/core/base/types.hpp>
47#include <ginkgo/core/base/utils.hpp>
84template <
typename IndexType =
int32>
98 : exec_(std::move(exec)),
100 num_stored_indices_{0},
101 subsets_begin_{array<index_type>(exec_)},
102 subsets_end_{array<index_type>(exec_)},
103 superset_cumulative_indices_{array<index_type>(exec_)}
115 explicit index_set(std::shared_ptr<const gko::Executor> exec,
116 std::initializer_list<IndexType>
init_list,
118 : exec_(std::
move(exec)),
126 GKO_ASSERT(index_space_size_ > 0);
127 this->populate_subsets(
141 explicit index_set(std::shared_ptr<const gko::Executor> exec,
145 : exec_(std::
move(exec)), index_space_size_(size)
147 GKO_ASSERT(index_space_size_ >=
indices.get_num_elems());
180 *
this = std::move(
other);
204 if (&
other ==
this) {
207 this->index_space_size_ =
other.index_space_size_;
208 this->num_stored_indices_ =
other.num_stored_indices_;
209 this->subsets_begin_ =
other.subsets_begin_;
210 this->subsets_end_ =
other.subsets_end_;
211 this->superset_cumulative_indices_ =
other.superset_cumulative_indices_;
228 if (&
other ==
this) {
231 this->index_space_size_ = std::exchange(
other.index_space_size_, 0);
232 this->num_stored_indices_ = std::exchange(
other.num_stored_indices_, 0);
233 this->subsets_begin_ = std::move(
other.subsets_begin_);
234 this->subsets_end_ = std::move(
other.subsets_end_);
235 this->superset_cumulative_indices_ =
236 std::move(
other.superset_cumulative_indices_);
250 this->index_space_size_ = 0;
251 this->num_stored_indices_ = 0;
252 this->subsets_begin_.
clear();
253 this->subsets_end_.
clear();
254 this->superset_cumulative_indices_.
clear();
262 std::shared_ptr<const Executor>
get_executor()
const {
return this->exec_; }
441 std::shared_ptr<const Executor> exec_;
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:187
void clear() noexcept
Deallocates all data used by the array.
Definition array.hpp:585
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition array.hpp:655
size_type get_num_elems() const noexcept
Returns the number of elements in the array.
Definition array.hpp:637
An index set class represents an ordered set of intervals.
Definition index_set.hpp:85
index_set(const index_set &other)
Creates a copy of the input index_set.
Definition index_set.hpp:168
index_set & operator=(index_set &&other)
Moves data from another index_set.
Definition index_set.hpp:226
array< index_type > to_global_indices() const
This function allows the user obtain a decompressed global_indices array from the indices stored in t...
const index_type * get_subsets_begin() const
Returns a pointer to the beginning indices of the subsets.
Definition index_set.hpp:410
index_type get_num_elems() const
Return the actual number of indices stored in the index set.
Definition index_set.hpp:283
index_type get_global_index(index_type local_index) const
Return the global index given a local index.
array< bool > contains(const array< index_type > &global_indices, const bool is_sorted=false) const
Checks if the individual global indeices exist in the index set.
IndexType index_type
The type of elements stored in the index set.
Definition index_set.hpp:90
const index_type * get_subsets_end() const
Returns a pointer to the end indices of the subsets.
Definition index_set.hpp:420
std::shared_ptr< const Executor > get_executor() const
Returns the executor of the index_set.
Definition index_set.hpp:262
void clear() noexcept
Deallocates all data used by the index_set.
Definition index_set.hpp:248
index_set(std::shared_ptr< const Executor > exec) noexcept
Creates an empty index_set tied to the specified Executor.
Definition index_set.hpp:97
index_type get_local_index(index_type global_index) const
Return the local index given a global index.
index_set(index_set &&other)
Moves the input index_set.
Definition index_set.hpp:188
array< index_type > map_global_to_local(const array< index_type > &global_indices, const bool is_sorted=false) const
This is an array version of the scalar function above.
index_set(std::shared_ptr< const gko::Executor > exec, std::initializer_list< IndexType > init_list, const bool is_sorted=false)
Creates an index set on the specified executor from the initializer list.
Definition index_set.hpp:115
index_type get_num_subsets() const
Returns the number of subsets stored in the index set.
Definition index_set.hpp:400
index_set(std::shared_ptr< const Executor > exec, index_set &&other)
Moves the input index_set to a different executor.
Definition index_set.hpp:177
bool contains(const index_type global_index) const
Checks if the global index exists in the index set.
index_set & operator=(const index_set &other)
Copies data from another index_set.
Definition index_set.hpp:202
bool is_contiguous() const
Returns if the index set is contiguous.
Definition index_set.hpp:276
index_set(std::shared_ptr< const gko::Executor > exec, const index_type size, const gko::array< index_type > &indices, const bool is_sorted=false)
Creates an index set on the specified executor and the given size.
Definition index_set.hpp:141
array< index_type > map_local_to_global(const array< index_type > &local_indices, const bool is_sorted=false) const
This is an array version of the scalar function above.
const index_type * get_superset_indices() const
Returns a pointer to the cumulative indices of the superset of the subsets.
Definition index_set.hpp:432
index_set(std::shared_ptr< const Executor > exec, const index_set &other)
Creates a copy of the input index_set on a different executor.
Definition index_set.hpp:157
index_type get_size() const
Returns the size of the index set space.
Definition index_set.hpp:269
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803