Chemical Data Processing Library C++ API - Version 1.4.0
Math/Grid.hpp
Go to the documentation of this file.
1 /*
2  * Grid.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_GRID_HPP
28 #define CDPL_MATH_GRID_HPP
29 
30 #include <cstddef>
31 #include <algorithm>
32 #include <vector>
33 #include <limits>
34 #include <type_traits>
35 #include <utility>
36 #include <memory>
37 
38 #include "CDPL/Math/Check.hpp"
41 #include "CDPL/Math/Functional.hpp"
42 #include "CDPL/Math/TypeTraits.hpp"
43 #include "CDPL/Base/Exceptions.hpp"
44 
45 
46 namespace CDPL
47 {
48 
49  namespace Math
50  {
51 
56  template <typename G>
57  class GridReference : public GridExpression<GridReference<G> >
58  {
59 
60  typedef GridReference<G> SelfType;
61 
62  public:
64  typedef G GridType;
66  typedef typename G::ValueType ValueType;
68  typedef typename std::conditional<std::is_const<G>::value,
69  typename G::ConstReference,
70  typename G::Reference>::type Reference;
72  typedef typename G::ConstReference ConstReference;
74  typedef typename G::SizeType SizeType;
76  typedef typename G::DifferenceType DifferenceType;
80  typedef const SelfType ConstClosureType;
81 
86  explicit GridReference(GridType& g):
87  data(g) {}
88 
95  {
96  return data(i);
97  }
98 
105  {
106  return data(i);
107  }
108 
117  {
118  return data(i, j, k);
119  }
120 
129  {
130  return data(i, j, k);
131  }
132 
138  {
139  return data.getSize();
140  }
141 
147  {
148  return data.getSize1();
149  }
150 
156  {
157  return data.getSize2();
158  }
159 
165  {
166  return data.getSize3();
167  }
168 
174  {
175  return data.getMaxSize();
176  }
177 
183  {
184  return data.getMaxSize1();
185  }
186 
192  {
193  return data.getMaxSize2();
194  }
195 
201  {
202  return data.getMaxSize3();
203  }
204 
209  bool isEmpty() const
210  {
211  return data.isEmpty();
212  }
213 
218  const GridType& getData() const
219  {
220  return data;
221  }
222 
228  {
229  return data;
230  }
231 
238  {
239  data.operator=(r.data);
240  return *this;
241  }
242 
249  template <typename E>
251  {
252  data.operator=(e);
253  return *this;
254  }
255 
262  template <typename E>
264  {
265  data.operator+=(e);
266  return *this;
267  }
268 
275  template <typename E>
277  {
278  data.operator-=(e);
279  return *this;
280  }
281 
288  template <typename T>
289  typename std::enable_if<IsScalar<T>::value, GridReference>::type& operator*=(const T& t)
290  {
291  data.operator*=(t);
292  return *this;
293  }
294 
301  template <typename T>
302  typename std::enable_if<IsScalar<T>::value, GridReference>::type& operator/=(const T& t)
303  {
304  data.operator/=(t);
305  return *this;
306  }
307 
315  template <typename E>
317  {
318  data.assign(e);
319  return *this;
320  }
321 
328  template <typename E>
330  {
331  data.plusAssign(e);
332  return *this;
333  }
334 
341  template <typename E>
343  {
344  data.minusAssign(e);
345  return *this;
346  }
347 
353  {
354  data.swap(r.data);
355  }
356 
362  friend void swap(GridReference& r1, GridReference& r2)
363  {
364  r1.swap(r2);
365  }
366 
367  private:
368  GridType& data;
369  };
370 
376  template <typename T, typename A = std::vector<T> >
377  class Grid : public GridContainer<Grid<T, A> >
378  {
379 
380  typedef Grid<T, A> SelfType;
381 
382  public:
384  typedef T ValueType;
386  typedef T& Reference;
388  typedef const T& ConstReference;
390  typedef typename A::size_type SizeType;
392  typedef typename A::difference_type DifferenceType;
394  typedef A ArrayType;
396  typedef T* Pointer;
398  typedef const T* ConstPointer;
406  typedef std::shared_ptr<SelfType> SharedPointer;
407 
411  Grid():
412  data(), size1(0), size2(0), size3(0) {}
413 
421  data(storageSize(m, n, o)), size1(m), size2(n), size3(o) {}
422 
431  data(storageSize(m, n, o), v), size1(m), size2(n), size3(o) {}
432 
437  Grid(const Grid& g):
438  data(g.data), size1(g.size1), size2(g.size2), size3(g.size3) {}
439 
444  Grid(Grid&& g):
445  data(), size1(0), size2(0), size3(0)
446  {
447  swap(g);
448  }
449 
455  template <typename E>
457  data(storageSize(e().getSize1(), e().getSize2(), e().getSize3())), size1(e().getSize1()), size2(e().getSize2()), size3(e().getSize3())
458  {
459  gridAssignGrid<ScalarAssignment>(*this, e);
460  }
461 
469  {
470  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
471  return data[i];
472  }
473 
481  {
482  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
483  return data[i];
484  }
485 
495  {
496  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
497  return data[(k * getSize2() + j) * getSize1() + i];
498  }
499 
509  {
510  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
511  return data[(k * getSize2() + j) * getSize1() + i];
512  }
513 
518  bool isEmpty() const
519  {
520  return data.empty();
521  }
522 
528  {
529  return (size1 * size2 * size3);
530  }
531 
537  {
538  return size1;
539  }
540 
546  {
547  return size2;
548  }
549 
555  {
556  return size3;
557  }
558 
564  {
565  return data.max_size();
566  }
567 
573  {
574  return data;
575  }
576 
581  const ArrayType& getData() const
582  {
583  return data;
584  }
585 
591  Grid& operator=(const Grid& g)
592  {
593  data = g.data;
594  size1 = g.size1;
595  size2 = g.size2;
596  size3 = g.size3;
597  return *this;
598  }
599 
606  {
607  swap(g);
608  return *this;
609  }
610 
617  template <typename C>
619  {
620  return assign(c);
621  }
622 
629  template <typename E>
631  {
632  Grid tmp(e);
633  swap(tmp);
634  return *this;
635  }
636 
643  template <typename C>
645  {
646  return plusAssign(c);
647  }
648 
655  template <typename E>
657  {
658  Grid tmp(*this + e);
659  swap(tmp);
660  return *this;
661  }
662 
669  template <typename C>
671  {
672  return minusAssign(c);
673  }
674 
681  template <typename E>
683  {
684  Grid tmp(*this - e);
685  swap(tmp);
686  return *this;
687  }
688 
695  template <typename T1>
696  typename std::enable_if<IsScalar<T1>::value, Grid>::type& operator*=(const T1& t)
697  {
698  gridAssignScalar<ScalarMultiplicationAssignment>(*this, t);
699  return *this;
700  }
701 
708  template <typename T1>
709  typename std::enable_if<IsScalar<T1>::value, Grid>::type& operator/=(const T1& t)
710  {
711  gridAssignScalar<ScalarDivisionAssignment>(*this, t);
712  return *this;
713  }
714 
721  template <typename E>
723  {
724  resize(e().getSize1(), e().getSize2(), false);
725  gridAssignGrid<ScalarAssignment>(*this, e);
726  return *this;
727  }
728 
735  template <typename E>
737  {
738  gridAssignGrid<ScalarAdditionAssignment>(*this, e);
739  return *this;
740  }
741 
748  template <typename E>
750  {
751  gridAssignGrid<ScalarSubtractionAssignment>(*this, e);
752  return *this;
753  }
754 
759  void swap(Grid& g)
760  {
761  if (this != &g) {
762  std::swap(data, g.data);
763  std::swap(size1, g.size1);
764  std::swap(size2, g.size2);
765  std::swap(size3, g.size3);
766  }
767  }
768 
774  friend void swap(Grid& g1, Grid& g2)
775  {
776  g1.swap(g2);
777  }
778 
783  void clear(const ValueType& v = ValueType())
784  {
785  std::fill(data.begin(), data.end(), v);
786  }
787 
796  void resize(SizeType m, SizeType n, SizeType o, bool preserve = true, const ValueType& v = ValueType())
797  {
798  if (size1 == m && size2 == n && size3 == o)
799  return;
800 
801  if (preserve) {
802  Grid tmp(m, n, o, v);
803 
804  for (SizeType i = 0, min_size1 = std::min(size1, m); i < min_size1; i++)
805  for (SizeType j = 0, min_size2 = std::min(size2, n); j < min_size2; j++)
806  for (SizeType k = 0, min_size3 = std::min(size3, o); k < min_size3; k++)
807  tmp(i, j, k) = (*this)(i, j, k);
808 
809  swap(tmp);
810 
811  } else {
812  data.resize(storageSize(m, n, o), v);
813  size1 = m;
814  size2 = n;
815  size3 = o;
816  }
817  }
818 
819  private:
820  static SizeType storageSize(SizeType m, SizeType n, SizeType o)
821  {
822  CDPL_MATH_CHECK(n == 0 || o == 0 ||
823  (n <= (std::numeric_limits<SizeType>::max() / o) && m <= (std::numeric_limits<SizeType>::max() / (n * o))),
824  "Maximum size exceeded", Base::SizeError);
825  return (m * n * o);
826  }
827 
828  ArrayType data;
829  SizeType size1;
830  SizeType size2;
831  SizeType size3;
832  };
833 
838  template <typename T>
839  class ZeroGrid : public GridContainer<ZeroGrid<T> >
840  {
841 
842  typedef ZeroGrid<T> SelfType;
843 
844  public:
846  typedef T ValueType;
848  typedef const T& Reference;
850  typedef const T& ConstReference;
852  typedef std::size_t SizeType;
854  typedef std::ptrdiff_t DifferenceType;
861 
866  size1(0), size2(0), size3(0) {}
867 
875  size1(m), size2(n), size3(o) {}
876 
881  ZeroGrid(const ZeroGrid& m):
882  size1(m.size1), size2(m.size2), size3(m.size3) {}
883 
891  {
892  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
893  return zero;
894  }
895 
905  {
906  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
907  return zero;
908  }
909 
914  bool isEmpty() const
915  {
916  return (size1 == 0 || size2 == 0 || size3 == 0);
917  }
918 
924  {
925  return (size1 * size2 * size3);
926  }
927 
933  {
934  return size1;
935  }
936 
942  {
943  return size2;
944  }
945 
951  {
952  return size3;
953  }
954 
960  {
961  return std::numeric_limits<SizeType>::max();
962  }
963 
969  {
970  return std::numeric_limits<SizeType>::max();
971  }
972 
978  {
979  return std::numeric_limits<SizeType>::max();
980  }
981 
988  {
989  if (this != &g) {
990  size1 = g.size1;
991  size2 = g.size2;
992  size3 = g.size3;
993  }
994 
995  return *this;
996  }
997 
1002  void swap(ZeroGrid& g)
1003  {
1004  if (this != &g) {
1005  std::swap(size1, g.size1);
1006  std::swap(size2, g.size2);
1007  std::swap(size3, g.size3);
1008  }
1009  }
1010 
1016  friend void swap(ZeroGrid& g1, ZeroGrid& g2)
1017  {
1018  g1.swap(g2);
1019  }
1020 
1028  {
1029  size1 = m;
1030  size2 = n;
1031  size3 = o;
1032  }
1033 
1034  private:
1035  SizeType size1;
1036  SizeType size2;
1037  SizeType size3;
1038  static const ValueType zero;
1039  };
1040 
1041  template <typename T>
1042  const typename ZeroGrid<T>::ValueType ZeroGrid<T>::zero = ZeroGrid<T>::ValueType();
1043 
1048  template <typename T>
1049  class ScalarGrid : public GridContainer<ScalarGrid<T> >
1050  {
1051 
1052  typedef ScalarGrid<T> SelfType;
1053 
1054  public:
1056  typedef T ValueType;
1058  typedef const T& Reference;
1060  typedef const T& ConstReference;
1062  typedef std::size_t SizeType;
1064  typedef std::ptrdiff_t DifferenceType;
1071 
1076  size1(0), size2(0), size3(0), value() {}
1077 
1086  size1(m), size2(n), size3(o), value(v) {}
1087 
1093  size1(m.size1), size2(m.size2), size3(m.size3), value(m.value) {}
1094 
1102  {
1103  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
1104  return value;
1105  }
1106 
1116  {
1117  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
1118  return value;
1119  }
1120 
1125  bool isEmpty() const
1126  {
1127  return (size1 == 0 || size2 == 0 || size3 == 0);
1128  }
1129 
1135  {
1136  return (size1 * size2 * size3);
1137  }
1138 
1144  {
1145  return size1;
1146  }
1147 
1153  {
1154  return size2;
1155  }
1156 
1162  {
1163  return size3;
1164  }
1165 
1171  {
1172  return std::numeric_limits<SizeType>::max();
1173  }
1174 
1180  {
1181  return std::numeric_limits<SizeType>::max();
1182  }
1183 
1189  {
1190  return std::numeric_limits<SizeType>::max();
1191  }
1192 
1199  {
1200  if (this != &g) {
1201  size1 = g.size1;
1202  size2 = g.size2;
1203  size3 = g.size3;
1204  value = g.value;
1205  }
1206 
1207  return *this;
1208  }
1209 
1214  void swap(ScalarGrid& g)
1215  {
1216  if (this != &g) {
1217  std::swap(size1, g.size1);
1218  std::swap(size2, g.size2);
1219  std::swap(size3, g.size3);
1220  std::swap(value, g.value);
1221  }
1222  }
1223 
1229  friend void swap(ScalarGrid& g1, ScalarGrid& g2)
1230  {
1231  g1.swap(g2);
1232  }
1233 
1241  {
1242  size1 = m;
1243  size2 = n;
1244  size3 = o;
1245  }
1246 
1247  private:
1248  SizeType size1;
1249  SizeType size2;
1250  SizeType size3;
1251  ValueType value;
1252  };
1253 
1258  template <typename G>
1260  {};
1261 
1266  template <typename G>
1268  {};
1269 
1274 
1279 
1284 
1289 
1294 
1299  } // namespace Math
1300 } // namespace CDPL
1301 
1302 #endif // CDPL_MATH_GRID_HPP
Definition of exception classes.
Definition of various preprocessor macros for error checking.
#define CDPL_MATH_CHECK(expr, msg, e)
Throws the exception e with message msg when the boolean expression expr evaluates to false.
Definition: Check.hpp:47
Definition of various functors.
Implementation of grid assignment routines.
Definition of various grid expression types and operations.
Definition of type traits.
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
Refinement of Math::GridExpression marking the derived type as a concrete (writable) grid container.
Definition: Expression.hpp:320
CRTP base class for all grid expression types.
Definition: Expression.hpp:180
Lightweight grid expression that proxies a reference to an underlying grid container.
Definition: Math/Grid.hpp:58
GridReference & assign(const GridExpression< E > &e)
Assigns the grid expression e to the wrapped grid without intermediate temporary (use only when e doe...
Definition: Math/Grid.hpp:316
GridReference(GridType &g)
Constructs the reference wrapping the grid g.
Definition: Math/Grid.hpp:86
std::conditional< std::is_const< G >::value, typename G::ConstReference, typename G::Reference >::type Reference
Mutable reference type (degrades to ConstReference when the wrapped grid is const).
Definition: Math/Grid.hpp:70
friend void swap(GridReference &r1, GridReference &r2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:362
GridReference & minusAssign(const GridExpression< E > &e)
Subtracts the grid expression e from the wrapped grid without intermediate temporary.
Definition: Math/Grid.hpp:342
GridType & getData()
Returns a mutable reference to the wrapped grid.
Definition: Math/Grid.hpp:227
Reference operator()(SizeType i, SizeType j, SizeType k)
Returns a mutable reference to the element at the (i, j, k) cell of the wrapped grid.
Definition: Math/Grid.hpp:116
G::SizeType SizeType
The unsigned size type used by the wrapped grid.
Definition: Math/Grid.hpp:74
bool isEmpty() const
Tells whether the wrapped grid is empty (zero cells along any dimension).
Definition: Math/Grid.hpp:209
SizeType getSize2() const
Returns the size of the wrapped grid along the second dimension.
Definition: Math/Grid.hpp:155
GridReference & operator+=(const GridExpression< E > &e)
Adds the grid expression e cell-wise to the wrapped grid.
Definition: Math/Grid.hpp:263
std::enable_if< IsScalar< T >::value, GridReference >::type & operator/=(const T &t)
Divides every cell of the wrapped grid by the scalar t.
Definition: Math/Grid.hpp:302
ConstReference operator()(SizeType i) const
Returns a const reference to the element at the linear index i of the wrapped grid.
Definition: Math/Grid.hpp:104
SizeType getMaxSize() const
Returns the maximum total number of cells the wrapped grid can hold.
Definition: Math/Grid.hpp:173
GridReference & operator=(const GridExpression< E > &e)
Assigns the grid expression e to the wrapped grid.
Definition: Math/Grid.hpp:250
SizeType getMaxSize2() const
Returns the maximum size of the wrapped grid along the second dimension.
Definition: Math/Grid.hpp:191
std::enable_if< IsScalar< T >::value, GridReference >::type & operator*=(const T &t)
Multiplies every cell of the wrapped grid by the scalar t.
Definition: Math/Grid.hpp:289
SizeType getMaxSize3() const
Returns the maximum size of the wrapped grid along the third dimension.
Definition: Math/Grid.hpp:200
G::ValueType ValueType
The element value type of the wrapped grid.
Definition: Math/Grid.hpp:66
GridReference & plusAssign(const GridExpression< E > &e)
Adds the grid expression e to the wrapped grid without intermediate temporary.
Definition: Math/Grid.hpp:329
const GridType & getData() const
Returns a const reference to the wrapped grid.
Definition: Math/Grid.hpp:218
SizeType getSize3() const
Returns the size of the wrapped grid along the third dimension.
Definition: Math/Grid.hpp:164
GridReference & operator-=(const GridExpression< E > &e)
Subtracts the grid expression e cell-wise from the wrapped grid.
Definition: Math/Grid.hpp:276
G::DifferenceType DifferenceType
The signed difference type used by the wrapped grid.
Definition: Math/Grid.hpp:76
SizeType getMaxSize1() const
Returns the maximum size of the wrapped grid along the first dimension.
Definition: Math/Grid.hpp:182
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the element at the (i, j, k) cell of the wrapped grid.
Definition: Math/Grid.hpp:128
SizeType getSize1() const
Returns the size of the wrapped grid along the first dimension.
Definition: Math/Grid.hpp:146
G GridType
The wrapped grid type.
Definition: Math/Grid.hpp:64
SizeType getSize() const
Returns the total number of cells of the wrapped grid.
Definition: Math/Grid.hpp:137
GridReference & operator=(const GridReference &r)
Copies the cells of r into the wrapped grid.
Definition: Math/Grid.hpp:237
Reference operator()(SizeType i)
Returns a mutable reference to the element at the linear index i of the wrapped grid.
Definition: Math/Grid.hpp:94
G::ConstReference ConstReference
Constant reference type to an element.
Definition: Math/Grid.hpp:72
const SelfType ConstClosureType
Constant closure type used when this reference appears inside another expression.
Definition: Math/Grid.hpp:80
SelfType ClosureType
Closure type used when this reference appears inside another expression.
Definition: Math/Grid.hpp:78
void swap(GridReference &r)
Swaps the contents of the wrapped grid with those of the grid wrapped by r.
Definition: Math/Grid.hpp:352
Dynamically-sized dense 3D grid ( ) with configurable underlying storage.
Definition: Math/Grid.hpp:378
T * Pointer
Pointer type for raw element access.
Definition: Math/Grid.hpp:396
A::size_type SizeType
The unsigned size type used by the underlying storage container.
Definition: Math/Grid.hpp:390
Grid & operator+=(const GridExpression< E > &e)
Adds the grid expression e cell-wise to this grid (via a temporary to handle aliasing).
Definition: Math/Grid.hpp:656
Grid & operator=(const Grid &g)
Copy-assigns the contents of g to this grid.
Definition: Math/Grid.hpp:591
void resize(SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
Resizes the grid to cells.
Definition: Math/Grid.hpp:796
Grid & operator-=(const GridContainer< C > &c)
Subtracts the contents of the grid container c cell-wise from this grid (no alias check needed).
Definition: Math/Grid.hpp:670
Reference operator()(SizeType i, SizeType j, SizeType k)
Returns a mutable reference to the element at (i, j, k).
Definition: Math/Grid.hpp:494
ConstReference operator()(SizeType i) const
Returns a const reference to the element at linear index i.
Definition: Math/Grid.hpp:480
Grid(SizeType m, SizeType n, SizeType o, const ValueType &v)
Constructs an m × n × o grid with every element initialized to v.
Definition: Math/Grid.hpp:430
Grid(Grid &&g)
Move-constructs a grid from g (g is left in a valid empty state).
Definition: Math/Grid.hpp:444
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Grid instances.
Definition: Math/Grid.hpp:406
Grid()
Constructs an empty grid (zero size on every axis).
Definition: Math/Grid.hpp:411
Grid & operator=(const GridContainer< C > &c)
Assigns the contents of the grid container c to this grid (no alias check needed).
Definition: Math/Grid.hpp:618
const T * ConstPointer
Constant pointer type for raw element access.
Definition: Math/Grid.hpp:398
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator*=(const T1 &t)
Multiplies every cell by the scalar t.
Definition: Math/Grid.hpp:696
Grid & assign(const GridExpression< E > &e)
Resizes this grid to match e and assigns its cells without intermediate temporary.
Definition: Math/Grid.hpp:722
A::difference_type DifferenceType
The signed difference type used by the underlying storage container.
Definition: Math/Grid.hpp:392
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the element at (i, j, k).
Definition: Math/Grid.hpp:508
T & Reference
Mutable reference type to an element.
Definition: Math/Grid.hpp:386
Grid & operator=(const GridExpression< E > &e)
Assigns the grid expression e to this grid (via a temporary to handle aliasing).
Definition: Math/Grid.hpp:630
Grid & operator-=(const GridExpression< E > &e)
Subtracts the grid expression e cell-wise from this grid (via a temporary to handle aliasing).
Definition: Math/Grid.hpp:682
SizeType getMaxSize() const
Returns the maximum total cell count the underlying storage container can hold.
Definition: Math/Grid.hpp:563
const ArrayType & getData() const
Returns a const reference to the underlying storage container.
Definition: Math/Grid.hpp:581
void clear(const ValueType &v=ValueType())
Sets every cell of the grid to the value v.
Definition: Math/Grid.hpp:783
SizeType getSize2() const
Returns the second-axis size.
Definition: Math/Grid.hpp:545
friend void swap(Grid &g1, Grid &g2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:774
const GridReference< const SelfType > ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:402
Grid & operator+=(const GridContainer< C > &c)
Adds the contents of the grid container c cell-wise to this grid (no alias check needed).
Definition: Math/Grid.hpp:644
void swap(Grid &g)
Swaps the contents of this grid with those of g.
Definition: Math/Grid.hpp:759
Grid(const Grid &g)
Constructs a copy of the grid g.
Definition: Math/Grid.hpp:437
Grid & operator=(Grid &&g)
Move-assigns the contents of g to this grid.
Definition: Math/Grid.hpp:605
SelfType GridTemporaryType
Concrete temporary grid type used by expression-template machinery.
Definition: Math/Grid.hpp:404
Reference operator()(SizeType i)
Returns a mutable reference to the element at linear index i.
Definition: Math/Grid.hpp:468
const T & ConstReference
Constant reference type to an element.
Definition: Math/Grid.hpp:388
ArrayType & getData()
Returns a mutable reference to the underlying storage container.
Definition: Math/Grid.hpp:572
bool isEmpty() const
Tells whether the grid is empty.
Definition: Math/Grid.hpp:518
SizeType getSize1() const
Returns the first-axis size.
Definition: Math/Grid.hpp:536
Grid(const GridExpression< E > &e)
Constructs the grid from the grid expression e (materializing the expression result).
Definition: Math/Grid.hpp:456
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator/=(const T1 &t)
Divides every cell by the scalar t.
Definition: Math/Grid.hpp:709
A ArrayType
The underlying storage container type.
Definition: Math/Grid.hpp:394
Grid & plusAssign(const GridExpression< E > &e)
Adds the cells of the grid expression e to this grid without intermediate temporary.
Definition: Math/Grid.hpp:736
SizeType getSize() const
Returns the total cell count .
Definition: Math/Grid.hpp:527
Grid & minusAssign(const GridExpression< E > &e)
Subtracts the cells of the grid expression e from this grid without intermediate temporary.
Definition: Math/Grid.hpp:749
GridReference< SelfType > ClosureType
Closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:400
T ValueType
The scalar value type stored in the grid.
Definition: Math/Grid.hpp:384
SizeType getSize3() const
Returns the third-axis size.
Definition: Math/Grid.hpp:554
Grid(SizeType m, SizeType n, SizeType o)
Constructs an m × n × o grid with default-initialized elements.
Definition: Math/Grid.hpp:420
Constant grid expression in which every cell equals the same scalar value.
Definition: Math/Grid.hpp:1050
ScalarGrid()
Constructs an empty scalar grid.
Definition: Math/Grid.hpp:1075
SizeType getMaxSize3() const
Returns the maximum representable third-axis size.
Definition: Math/Grid.hpp:1188
SizeType getMaxSize1() const
Returns the maximum representable first-axis size.
Definition: Math/Grid.hpp:1170
ConstReference operator()(SizeType i) const
Returns a const reference to the common cell value (linear-index form).
Definition: Math/Grid.hpp:1101
GridReference< SelfType > ClosureType
Closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:1066
SizeType getSize1() const
Returns the first-axis size.
Definition: Math/Grid.hpp:1143
friend void swap(ScalarGrid &g1, ScalarGrid &g2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:1229
ScalarGrid(const ScalarGrid &m)
Constructs a copy of the scalar grid m.
Definition: Math/Grid.hpp:1092
ScalarGrid(SizeType m, SizeType n, SizeType o, const ValueType &v=ValueType())
Constructs a scalar grid of size in which every cell equals v.
Definition: Math/Grid.hpp:1085
bool isEmpty() const
Tells whether the grid is empty (any axis has zero size).
Definition: Math/Grid.hpp:1125
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the common cell value (3D-index form).
Definition: Math/Grid.hpp:1115
const T & Reference
Reference type (always a const reference — cells are immutable).
Definition: Math/Grid.hpp:1058
std::size_t SizeType
The unsigned size type.
Definition: Math/Grid.hpp:1062
SizeType getSize3() const
Returns the third-axis size.
Definition: Math/Grid.hpp:1161
const GridReference< const SelfType > ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:1068
ScalarGrid & operator=(const ScalarGrid &g)
Copy-assigns the axis sizes and common value from g.
Definition: Math/Grid.hpp:1198
const T & ConstReference
Constant reference type to a cell.
Definition: Math/Grid.hpp:1060
Grid< T > GridTemporaryType
Concrete temporary grid type used by expression-template machinery.
Definition: Math/Grid.hpp:1070
SizeType getMaxSize2() const
Returns the maximum representable second-axis size.
Definition: Math/Grid.hpp:1179
void swap(ScalarGrid &g)
Swaps the axis sizes and common value with g.
Definition: Math/Grid.hpp:1214
SizeType getSize2() const
Returns the second-axis size.
Definition: Math/Grid.hpp:1152
SizeType getSize() const
Returns the total cell count .
Definition: Math/Grid.hpp:1134
void resize(SizeType m, SizeType n, SizeType o)
Resizes the grid axes to (m, n, o).
Definition: Math/Grid.hpp:1240
T ValueType
The scalar value type.
Definition: Math/Grid.hpp:1056
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Math/Grid.hpp:1064
Constant grid expression whose cells are all zero.
Definition: Math/Grid.hpp:840
SizeType getMaxSize3() const
Returns the maximum representable third-axis size.
Definition: Math/Grid.hpp:977
ZeroGrid & operator=(const ZeroGrid &g)
Copy-assigns the axis sizes from g.
Definition: Math/Grid.hpp:987
Grid< T > GridTemporaryType
Concrete temporary grid type used by expression-template machinery.
Definition: Math/Grid.hpp:860
SizeType getSize2() const
Returns the second-axis size.
Definition: Math/Grid.hpp:941
SizeType getSize3() const
Returns the third-axis size.
Definition: Math/Grid.hpp:950
SizeType getSize() const
Returns the total cell count .
Definition: Math/Grid.hpp:923
void swap(ZeroGrid &g)
Swaps the axis sizes with g.
Definition: Math/Grid.hpp:1002
SizeType getMaxSize2() const
Returns the maximum representable second-axis size.
Definition: Math/Grid.hpp:968
friend void swap(ZeroGrid &g1, ZeroGrid &g2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:1016
ZeroGrid(SizeType m, SizeType n, SizeType o)
Constructs a zero grid of size .
Definition: Math/Grid.hpp:874
T ValueType
The scalar value type.
Definition: Math/Grid.hpp:846
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the zero element (3D-index form).
Definition: Math/Grid.hpp:904
ConstReference operator()(SizeType i) const
Returns a const reference to the zero element (linear-index form).
Definition: Math/Grid.hpp:890
const T & Reference
Reference type (always a const reference — all cells are zero).
Definition: Math/Grid.hpp:848
SizeType getMaxSize1() const
Returns the maximum representable first-axis size.
Definition: Math/Grid.hpp:959
ZeroGrid(const ZeroGrid &m)
Constructs a copy of the zero grid m.
Definition: Math/Grid.hpp:881
const GridReference< const SelfType > ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:858
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Math/Grid.hpp:854
ZeroGrid()
Constructs an empty zero grid (zero size on every axis).
Definition: Math/Grid.hpp:865
GridReference< SelfType > ClosureType
Closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:856
SizeType getSize1() const
Returns the first-axis size.
Definition: Math/Grid.hpp:932
const T & ConstReference
Constant reference type to the zero element.
Definition: Math/Grid.hpp:850
std::size_t SizeType
The unsigned size type.
Definition: Math/Grid.hpp:852
void resize(SizeType m, SizeType n, SizeType o)
Resizes the grid axes to (m, n, o).
Definition: Math/Grid.hpp:1027
bool isEmpty() const
Tells whether the grid is empty (any axis has zero size).
Definition: Math/Grid.hpp:914
constexpr unsigned int A
Generic type that covers any element except hydrogen.
Definition: AtomType.hpp:637
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int r
Specifies that the stereocenter has r configuration.
Definition: CIPDescriptor.hpp:76
constexpr unsigned int m
Specifies that the stereocenter has m configuration.
Definition: CIPDescriptor.hpp:116
Grid< double > DGrid
Unbounded dense grid storing floating point values of type double.
Definition: Math/Grid.hpp:1298
ScalarGrid< float > FScalarGrid
Immutable grid where all elements have the same value of type float.
Definition: Math/Grid.hpp:1283
ZeroGrid< double > DZeroGrid
Immutable grid where all elements have the value zero of type double.
Definition: Math/Grid.hpp:1278
Grid< float > FGrid
Unbounded dense grid storing floating point values of type float.
Definition: Math/Grid.hpp:1293
ZeroGrid< float > FZeroGrid
Immutable grid where all elements have the value zero of type float.
Definition: Math/Grid.hpp:1273
ScalarGrid< double > DScalarGrid
Immutable grid where all elements have the same value of type double.
Definition: Math/Grid.hpp:1288
The namespace of the Chemical Data Processing Library.
Selects a concrete temporary grid type compatible with the grid expression G.
Definition: TypeTraits.hpp:337