LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
PackedIndex.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * Developed for the LSST Data Management System.
4  * This product includes software developed by the LSST Project
5  * (https://www.lsst.org).
6  * See the COPYRIGHT file at the top-level directory of this distribution
7  * for details of code ownership.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 #ifndef LSST_AFW_MATH_POLYNOMIALS_PackedIndex_h_INCLUDED
23 #define LSST_AFW_MATH_POLYNOMIALS_PackedIndex_h_INCLUDED
24 
25 namespace lsst { namespace geom { namespace polynomials {
26 
28 enum class PackingOrder {
29 
43  YX,
44 
58  XY
59 };
60 
69 struct Index2d {
70 
72  constexpr Index2d() noexcept : flat(0), nx(0), ny(0) {}
73 
75  constexpr Index2d(std::size_t flat_, std::size_t nx_, std::size_t ny_) noexcept :
76  flat(flat_), nx(nx_), ny(ny_)
77  {}
78 
80  constexpr bool operator==(Index2d const & other) const noexcept {
81  return flat == other.flat && nx == other.nx && ny == other.ny;
82  }
83 
85  constexpr bool operator!=(Index2d const & other) const noexcept {
86  return !(*this == other);
87  }
88 
92 };
93 
94 namespace detail {
95 
96 // Specialization of all PackedIndexIterator/PackedIndexRange logic
97 // that isn't common across PackingOrders.
98 template <PackingOrder packing> struct PackingOrderTraits;
99 
100 template <>
102 
103  // Return the offset of the given coefficient after the (nx + ny) offset is subtracted off.
104  static std::size_t computeInnerIndex(std::size_t nx, std::size_t ny) { return nx; }
105 
106  static void increment(Index2d & index) {
107  if (index.ny == 0) {
108  index.ny = index.nx + 1;
109  index.nx = 0;
110  } else {
111  --index.ny;
112  ++index.nx;
113  }
114  }
115 
116  // Return the nx and ny values appropriate for the end iterator of a range of the given order.
117  static std::size_t getEndX(std::size_t order) { return 0; }
118  static std::size_t getEndY(std::size_t order) { return order + 1; }
119 
120 };
121 
122 template <>
124 
125  // Return the offset of the given coefficient after the (nx + ny) offset is subtracted off.
126  static std::size_t computeInnerIndex(std::size_t nx, std::size_t ny) { return ny; }
127 
128  static void increment(Index2d & index) {
129  if (index.nx == 0) {
130  index.nx = index.ny + 1;
131  index.ny = 0;
132  } else {
133  --index.nx;
134  ++index.ny;
135  }
136  }
137 
138  // Return the nx and ny values appropriate for the end iterator of a range of the given order.
139  static std::size_t getEndX(std::size_t order) { return order + 1; }
140  static std::size_t getEndY(std::size_t order) { return 0; }
141 
142 };
143 
144 } // namespace detail
145 
163 template <PackingOrder packing>
166 public:
167 
170  using pointer = Index2d const *;
171  using reference = Index2d const &;
173 
175  static constexpr std::size_t computeOffset(std::size_t order) noexcept {
176  return order*(order + 1)/2;
177  }
178 
180  static constexpr std::size_t computeSize(std::size_t order) noexcept {
181  return computeOffset(order + 1);
182  }
183 
185  static constexpr std::size_t computeIndex(std::size_t nx, std::size_t ny) noexcept {
186  return computeOffset(nx + ny) + Traits::computeInnerIndex(nx, ny);
187  }
188 
190  static constexpr PackedIndexIterator makeEnd(std::size_t order) noexcept {
191  return PackedIndexIterator(order);
192  }
193 
195  constexpr PackedIndexIterator() noexcept : _index() {}
196 
198  constexpr PackedIndexIterator(std::size_t nx, std::size_t ny) noexcept :
199  _index(computeIndex(nx, ny), nx, ny)
200  {}
201 
203  constexpr reference operator*() const noexcept { return _index; }
204 
206  constexpr pointer operator->() const noexcept { return &_index; }
207 
210  ++_index.flat;
211  Traits::increment(_index);
212  return *this;
213  }
214 
217  PackedIndexIterator r(*this);
218  ++(*this);
219  return r;
220  }
221 
223  constexpr bool operator==(PackedIndexIterator const & other) const noexcept {
224  return _index == other._index;
225  }
226 
228  constexpr bool operator!=(PackedIndexIterator const & other) const noexcept {
229  return !(*this == other);
230  }
231 
232 private:
233 
234  constexpr PackedIndexIterator(std::size_t order) noexcept :
235  _index(computeOffset(order + 1), Traits::getEndX(order), Traits::getEndY(order))
236  {}
237 
238  Index2d _index;
239 };
240 
247 template <PackingOrder packing>
249 public:
250 
254  using reference = typename iterator::reference;
255  using pointer = typename iterator::pointer;
258 
260  static constexpr std::size_t computeOffset(std::size_t order) noexcept {
261  return iterator::computeOffset(order);
262  }
263 
265  static constexpr std::size_t computeSize(std::size_t order) noexcept {
266  return iterator::computeSize(order);
267  }
268 
270  static constexpr std::size_t computeIndex(std::size_t nx, std::size_t ny) noexcept {
271  return iterator::computeIndex(nx, ny);
272  }
273 
275  constexpr PackedIndexRange(iterator first, iterator last) noexcept :
276  _begin(first),
277  _end(last)
278  {}
279 
281  constexpr iterator begin() const noexcept { return _begin; }
282 
284  constexpr iterator cbegin() const noexcept { return _begin; }
285 
287  constexpr iterator end() const noexcept { return _end; }
288 
290  constexpr iterator cend() const noexcept { return _end; }
291 
293  constexpr std::size_t size() const noexcept { return _end->flat - _begin->flat; }
294 
296  constexpr bool empty() const noexcept { return size() == 0u; }
297 
299  constexpr bool operator==(PackedIndexRange const & other) const noexcept {
300  return _begin == other._begin && _end == other._end;
301  }
302 
304  constexpr bool operator!=(PackedIndexRange const & other) const noexcept {
305  return !(*this == other);
306  }
307 
308 private:
309  iterator _begin;
310  iterator _end;
311 };
312 
313 }}} // namespace lsst::geom::polynomials
314 
315 #endif // !LSST_AFW_MATH_POLYNOMIALS_PackedIndex_h_INCLUDED
lsst::geom::polynomials::PackingOrder::XY
@ XY
A pair of indices is mapped to the flattened position , which yields the (nx, ny) ordering.
lsst::geom::polynomials::PackedIndexIterator::pointer
Index2d const * pointer
Definition: PackedIndex.h:170
lsst::geom::polynomials::PackedIndexIterator::computeSize
static constexpr std::size_t computeSize(std::size_t order) noexcept
Return the flattened size of an expansion with the given maximum order (inclusive).
Definition: PackedIndex.h:180
lsst::geom::polynomials::PackedIndexIterator::difference_type
std::ptrdiff_t difference_type
Definition: PackedIndex.h:168
lsst::geom::polynomials::PackedIndexRange::cbegin
constexpr iterator cbegin() const noexcept
Return an iterator to the start of the range.
Definition: PackedIndex.h:284
lsst::geom::polynomials::Index2d::Index2d
constexpr Index2d() noexcept
Construct an index with zero entries.
Definition: PackedIndex.h:72
lsst::geom::polynomials::PackedIndexRange::size
constexpr std::size_t size() const noexcept
Return the number of elements in the flattened expansion.
Definition: PackedIndex.h:293
lsst::geom::polynomials::PackedIndexRange::operator==
constexpr bool operator==(PackedIndexRange const &other) const noexcept
Equality comparison.
Definition: PackedIndex.h:299
lsst::geom::polynomials::Index2d::Index2d
constexpr Index2d(std::size_t flat_, std::size_t nx_, std::size_t ny_) noexcept
Construct with the provided values.
Definition: PackedIndex.h:75
lsst::afw::table._match.first
first
Definition: _match.py:74
std::input_iterator_tag
lsst::geom::polynomials::PackedIndexIterator::makeEnd
static constexpr PackedIndexIterator makeEnd(std::size_t order) noexcept
Construct an iterator one past the end of an expansion with the given order.
Definition: PackedIndex.h:190
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::YX >::increment
static void increment(Index2d &index)
Definition: PackedIndex.h:106
lsst::geom::polynomials::PackedIndexRange::begin
constexpr iterator begin() const noexcept
Return an iterator to the start of the range.
Definition: PackedIndex.h:281
lsst::geom::polynomials::PackingOrder
PackingOrder
Enum defining the packing orders used to order 2-d polynomial coefficients.
Definition: PackedIndex.h:28
lsst::geom::polynomials::PackedIndexRange::operator!=
constexpr bool operator!=(PackedIndexRange const &other) const noexcept
Inequality comparison.
Definition: PackedIndex.h:304
lsst::geom::polynomials::PackedIndexRange::reference
typename iterator::reference reference
Definition: PackedIndex.h:254
lsst::geom::polynomials::Index2d::ny
std::size_t ny
Index into the 1-d functoin for ny.
Definition: PackedIndex.h:91
lsst::geom::polynomials::PackedIndexIterator::value_type
Index2d value_type
Definition: PackedIndex.h:169
lsst::geom::polynomials::PackedIndexRange::empty
constexpr bool empty() const noexcept
Return true if the number of elements in the flattened expansion is zero.
Definition: PackedIndex.h:296
lsst::geom::polynomials::PackedIndexRange::value_type
typename iterator::value_type value_type
Definition: PackedIndex.h:253
lsst::geom::polynomials::PackedIndexIterator::operator++
PackedIndexIterator & operator++() noexcept
Move to the next element in the packed array and return the iterator.
Definition: PackedIndex.h:209
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::XY >::computeInnerIndex
static std::size_t computeInnerIndex(std::size_t nx, std::size_t ny)
Definition: PackedIndex.h:126
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::XY >::getEndX
static std::size_t getEndX(std::size_t order)
Definition: PackedIndex.h:139
lsst::geom::polynomials::PackedIndexIterator
An iterator for traversing "packed" triangular 2-d series expansions, in which two 1-d expansions are...
Definition: PackedIndex.h:164
lsst::geom::polynomials::Index2d::nx
std::size_t nx
Index into the 1-d function for nx.
Definition: PackedIndex.h:90
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::YX >::getEndX
static std::size_t getEndX(std::size_t order)
Definition: PackedIndex.h:117
lsst::geom::polynomials::Index2d
A custom tuple that relates the indices of two 1-d functions for x and y to the flattened index for t...
Definition: PackedIndex.h:69
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::geom::polynomials::PackedIndexRange::computeIndex
static constexpr std::size_t computeIndex(std::size_t nx, std::size_t ny) noexcept
Return the flattened index for the element with the given x and y orders.
Definition: PackedIndex.h:270
lsst::geom::polynomials::PackedIndexIterator::operator++
PackedIndexIterator operator++(int) noexcept
Move to the next element in the packed array and return a copy of the iterator before the move.
Definition: PackedIndex.h:216
lsst::geom::polynomials::PackedIndexIterator::reference
Index2d const & reference
Definition: PackedIndex.h:171
lsst::geom::polynomials::PackedIndexIterator::computeIndex
static constexpr std::size_t computeIndex(std::size_t nx, std::size_t ny) noexcept
Return the flattened index for the element with the given x and y orders.
Definition: PackedIndex.h:185
lsst::geom::polynomials::Index2d::operator!=
constexpr bool operator!=(Index2d const &other) const noexcept
Inequality comparison.
Definition: PackedIndex.h:85
lsst::geom::polynomials::detail::PackingOrderTraits
Definition: PackedIndex.h:98
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::geom::polynomials::PackedIndexRange::computeSize
static constexpr std::size_t computeSize(std::size_t order) noexcept
Return the flattened size of an expansion with the given maximum order (inclusive).
Definition: PackedIndex.h:265
lsst::geom::polynomials::PackedIndexRange
A specialized iterator range class for PackedIndexIterator, providing size calculation,...
Definition: PackedIndex.h:248
lsst::geom::polynomials::PackedIndexIterator::operator*
constexpr reference operator*() const noexcept
Dereference the iterator, yielding a Index2d const reference.
Definition: PackedIndex.h:203
lsst::geom::polynomials::PackedIndexIterator::operator!=
constexpr bool operator!=(PackedIndexIterator const &other) const noexcept
Inequality comparison.
Definition: PackedIndex.h:228
lsst::geom
Definition: AffineTransform.h:36
lsst::geom::polynomials::PackedIndexIterator::PackedIndexIterator
constexpr PackedIndexIterator(std::size_t nx, std::size_t ny) noexcept
Construct an iterator pointing to the element with the given x and y orders.
Definition: PackedIndex.h:198
lsst::geom::polynomials::Index2d::operator==
constexpr bool operator==(Index2d const &other) const noexcept
Equality comparison.
Definition: PackedIndex.h:80
lsst::geom::polynomials::PackedIndexRange::PackedIndexRange
constexpr PackedIndexRange(iterator first, iterator last) noexcept
Construct from begin and end iterators.
Definition: PackedIndex.h:275
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::XY >::getEndY
static std::size_t getEndY(std::size_t order)
Definition: PackedIndex.h:140
lsst::geom::polynomials::Index2d::flat
std::size_t flat
Index into the flattened 2-d function.
Definition: PackedIndex.h:89
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::XY >::increment
static void increment(Index2d &index)
Definition: PackedIndex.h:128
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::YX >::getEndY
static std::size_t getEndY(std::size_t order)
Definition: PackedIndex.h:118
lsst::geom::polynomials::PackedIndexIterator::operator->
constexpr pointer operator->() const noexcept
Dereference the iterator, yielding a Index2d const pointer.
Definition: PackedIndex.h:206
lsst::geom::polynomials::PackingOrder::YX
@ YX
A pair of indices is mapped to the flattened position , which yields the (nx, ny) ordering.
std::ptrdiff_t
lsst::geom::polynomials::PackedIndexIterator::operator==
constexpr bool operator==(PackedIndexIterator const &other) const noexcept
Equality comparison.
Definition: PackedIndex.h:223
lsst::geom::polynomials::PackedIndexRange::pointer
typename iterator::pointer pointer
Definition: PackedIndex.h:255
std::size_t
lsst::geom::polynomials::detail::PackingOrderTraits< PackingOrder::YX >::computeInnerIndex
static std::size_t computeInnerIndex(std::size_t nx, std::size_t ny)
Definition: PackedIndex.h:104
lsst::geom::polynomials::PackedIndexRange::cend
constexpr iterator cend() const noexcept
Return an iterator to one past the end of the range.
Definition: PackedIndex.h:290
lsst::geom::polynomials::PackedIndexIterator::computeOffset
static constexpr std::size_t computeOffset(std::size_t order) noexcept
Return the flattened offset to the start of the given order.
Definition: PackedIndex.h:175
lsst::geom::polynomials::PackedIndexRange::computeOffset
static constexpr std::size_t computeOffset(std::size_t order) noexcept
Return the flattened offset to the start of the given order.
Definition: PackedIndex.h:260
lsst::geom::polynomials::PackedIndexRange::iterator
PackedIndexIterator< packing > iterator
Definition: PackedIndex.h:251
lsst::geom::polynomials::PackedIndexRange::difference_type
typename iterator::difference_type difference_type
Definition: PackedIndex.h:256
lsst::geom::polynomials::PackedIndexIterator::PackedIndexIterator
constexpr PackedIndexIterator() noexcept
Construct an iterator at the beginning of an expansion of any order.
Definition: PackedIndex.h:195
lsst::geom::polynomials::PackedIndexRange::end
constexpr iterator end() const noexcept
Return an iterator to one past the end of the range.
Definition: PackedIndex.h:287