6 #include "../../types.hpp" 10 namespace wavepackets {
17 template<dim_t D,
class MultiIndex>
47 : offset_(that.offset_)
48 , table_(
std::move(that.table_))
56 table_ = std::move(that.
table_);
67 , table_(
std::move(table))
75 std::vector< MultiIndex >
const&
_table()
const 103 return table_.begin();
109 const_iterator
end()
const 119 return table_.cbegin();
127 return table_.cend();
145 assert(ordinal <
size());
147 return table_[ordinal];
163 bool try_find(
const MultiIndex& index, std::size_t& ordinal)
const 165 std::less< MultiIndex > comp;
167 auto it = std::lower_bound(table_.begin(), table_.end(), index, comp);
169 if (it != table_.end() && *it == index) {
170 ordinal = it - table_.begin();
193 std::size_t
find(
const MultiIndex& index)
const 198 throw std::invalid_argument(
"slice does not contain multi-index");
218 auto ordinals = std::array<std::size_t,D>();
220 MultiIndex index(_index);
222 std::less< MultiIndex > comp;
226 while (dlast >= 0 && index[dlast] == 0) {
231 auto lower = table_.begin();
233 auto upper = std::lower_bound(lower, table_.end(),
backward_(index, dlast), comp);
234 ordinals[dlast] = upper - table_.begin();
236 for (
dim_t i = 0; i < dlast; i++) {
238 lower = std::lower_bound(lower, upper,
backward_(index, i), comp);
239 ordinals[i] = lower - table_.begin();
252 return table_ == that.
table_;
257 return table_ != that.
table_;
352 template<dim_t D,
class MultiIndex>
359 std::vector< ShapeSlice<D, MultiIndex> >
slices_;
367 std::size_t n_entries,
371 , slices_(
std::move(slices))
372 , n_entries_(n_entries)
379 : lower_(
std::move(that.lower_))
380 , upper_(
std::move(that.upper_))
381 , slices_(
std::move(that.slices_))
382 , n_entries_(that.n_entries_)
383 , limits_(that.limits_)
392 lower_ = std::move(that.
lower_);
393 upper_ = std::move(that.
upper_);
394 slices_ = std::move(that.
slices_);
413 else if (islice >= (
int)slices_.size())
416 return slices_[islice];
423 else if (islice >= (
int)slices_.size())
426 return slices_[islice];
432 const std::vector< ShapeSlice<D, MultiIndex> >&
slices()
const 437 MultiIndex
at(std::size_t ordinal)
const 439 for (
auto & slice : slices_) {
440 if (slice.offset() + slice.size() > ordinal)
441 return slice[ordinal - slice.offset()];
443 throw std::runtime_error(
"ordinal >= shape.n_entries()");
459 return (
int)slices_.size();
491 return limits_[axis];
503 for (
int islice = n_entries_-1; islice >= 0; islice--) {
504 if (slice(islice) != that.
slice(islice))
std::vector< MultiIndex > table_
Definition: shape_enum.hpp:23
const MultiIndex & limits() const
Retrieves the minimum bounding box which contains all nodes.
Definition: shape_enum.hpp:472
bool operator!=(const ShapeSlice &that) const
Definition: shape_enum.hpp:255
int limit(dim_t axis) const
Retrieves the -th entry of the minimum bounding box .
Definition: shape_enum.hpp:489
Definition: coefficients_file_parser.cpp:10
ShapeSlice< D, MultiIndex > & slice(int islice)
Definition: shape_enum.hpp:419
std::vector< MultiIndex > const & _table() const
Definition: shape_enum.hpp:75
ShapeSlice(std::size_t offset)
Definition: shape_enum.hpp:60
std::size_t size() const
Definition: shape_enum.hpp:93
int n_slices() const
Retrieves the number of slices.
Definition: shape_enum.hpp:457
Definition: stdarray2stream.hpp:7
A shape enumeration is a complete, ordered list of all lattice nodes that are part of the basis shape...
Definition: shape_enum.hpp:353
MultiIndex at(std::size_t ordinal) const
Definition: shape_enum.hpp:437
const_iterator cend() const
Returns a const-iterator referring to the past-the-end node.
Definition: shape_enum.hpp:125
std::size_t n_entries() const
Retrieves the number of nodes.
Definition: shape_enum.hpp:449
ShapeSlice & operator=(const ShapeSlice &that)=default
bool operator==(const ShapeSlice &that) const
Checks whether both sides are equals by comparison of every node.
Definition: shape_enum.hpp:250
const std::vector< ShapeSlice< D, MultiIndex > > & slices() const
Returns a reference to the array containing all slices.
Definition: shape_enum.hpp:432
std::size_t offset_
Definition: shape_enum.hpp:21
ShapeSlice< D, MultiIndex > lower_
Definition: shape_enum.hpp:356
MultiIndex limits_
Definition: shape_enum.hpp:361
ShapeSlice(std::vector< MultiIndex > &&table, std::size_t offset)
Definition: shape_enum.hpp:65
bool operator==(const ShapeEnum &that) const
Checks whether both enumerations are equals by comparison of every node.
Definition: shape_enum.hpp:498
std::array< std::size_t, D > find_backward_neighbours(const MultiIndex &_index) const
Retrieves the ordinals of all backward neighbours of a lattice node .
Definition: shape_enum.hpp:216
const_iterator cbegin() const
Returns a const-iterator pointing to the first node.
Definition: shape_enum.hpp:117
MultiIndex backward_(MultiIndex index, dim_t axis) const
Definition: shape_enum.hpp:33
const_iterator begin() const
Returns a const-iterator pointing to the first node.
Definition: shape_enum.hpp:101
std::vector< MultiIndex >::const_iterator const_iterator
Definition: shape_enum.hpp:40
ShapeEnum(ShapeEnum &&that)
Definition: shape_enum.hpp:378
const_iterator end() const
Returns a const-iterator referring to the past-the-end node.
Definition: shape_enum.hpp:109
MultiIndex forward_(MultiIndex index, dim_t axis) const
Definition: shape_enum.hpp:27
std::vector< ShapeSlice< D, MultiIndex > > slices_
Definition: shape_enum.hpp:359
bool operator!=(const ShapeEnum &that) const
Definition: shape_enum.hpp:511
std::vector< MultiIndex > & _table()
Definition: shape_enum.hpp:70
bool try_find(const MultiIndex &index, std::size_t &ordinal) const
Retrieves the position of the node , if is part of this slice.
Definition: shape_enum.hpp:163
ShapeSlice< D, MultiIndex > upper_
Definition: shape_enum.hpp:357
std::size_t find(const MultiIndex &index) const
Returns the position of a node.
Definition: shape_enum.hpp:193
The -th slice of a shape enumeration contains all multi-indices that satisfy .
Definition: shape_enum.hpp:18
std::size_t offset() const
Retrieves the number of nodes in all previous slices.
Definition: shape_enum.hpp:85
MultiIndex operator[](std::size_t ordinal) const
Returns the multi-index of the node at position ordinal.
Definition: shape_enum.hpp:143
ShapeSlice(ShapeSlice &&that)
Definition: shape_enum.hpp:46
ShapeEnum(std::vector< ShapeSlice< D, MultiIndex > > &&slices, std::size_t n_entries, MultiIndex limits)
Definition: shape_enum.hpp:366
int dim_t
Definition: types.hpp:16
ShapeEnum & operator=(ShapeEnum &&that)
Definition: shape_enum.hpp:388
const ShapeSlice< D, MultiIndex > & slice(int islice) const
Returns a reference to a slice.
Definition: shape_enum.hpp:409
std::size_t n_entries_
Definition: shape_enum.hpp:360
ShapeSlice & operator=(ShapeSlice &&that)
Definition: shape_enum.hpp:53