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:
66  typedef G GridType;
67 
71  typedef typename G::ValueType ValueType;
72 
76  typedef typename std::conditional<std::is_const<G>::value,
77  typename G::ConstReference,
78  typename G::Reference>::type Reference;
79 
83  typedef typename G::ConstReference ConstReference;
84 
88  typedef typename G::SizeType SizeType;
89 
93  typedef typename G::DifferenceType DifferenceType;
94 
99 
103  typedef const SelfType ConstClosureType;
104 
109  explicit GridReference(GridType& g):
110  data(g) {}
111 
118  {
119  return data(i);
120  }
121 
128  {
129  return data(i);
130  }
131 
140  {
141  return data(i, j, k);
142  }
143 
152  {
153  return data(i, j, k);
154  }
155 
161  {
162  return data.getSize();
163  }
164 
170  {
171  return data.getSize1();
172  }
173 
179  {
180  return data.getSize2();
181  }
182 
188  {
189  return data.getSize3();
190  }
191 
197  {
198  return data.getMaxSize();
199  }
200 
206  {
207  return data.getMaxSize1();
208  }
209 
215  {
216  return data.getMaxSize2();
217  }
218 
224  {
225  return data.getMaxSize3();
226  }
227 
232  bool isEmpty() const
233  {
234  return data.isEmpty();
235  }
236 
241  const GridType& getData() const
242  {
243  return data;
244  }
245 
251  {
252  return data;
253  }
254 
261  {
262  data.operator=(r.data);
263  return *this;
264  }
265 
272  template <typename E>
274  {
275  data.operator=(e);
276  return *this;
277  }
278 
285  template <typename E>
287  {
288  data.operator+=(e);
289  return *this;
290  }
291 
298  template <typename E>
300  {
301  data.operator-=(e);
302  return *this;
303  }
304 
311  template <typename T>
312  typename std::enable_if<IsScalar<T>::value, GridReference>::type& operator*=(const T& t)
313  {
314  data.operator*=(t);
315  return *this;
316  }
317 
324  template <typename T>
325  typename std::enable_if<IsScalar<T>::value, GridReference>::type& operator/=(const T& t)
326  {
327  data.operator/=(t);
328  return *this;
329  }
330 
338  template <typename E>
340  {
341  data.assign(e);
342  return *this;
343  }
344 
351  template <typename E>
353  {
354  data.plusAssign(e);
355  return *this;
356  }
357 
364  template <typename E>
366  {
367  data.minusAssign(e);
368  return *this;
369  }
370 
376  {
377  data.swap(r.data);
378  }
379 
385  friend void swap(GridReference& r1, GridReference& r2)
386  {
387  r1.swap(r2);
388  }
389 
390  private:
391  GridType& data;
392  };
393 
399  template <typename T, typename A = std::vector<T> >
400  class Grid : public GridContainer<Grid<T, A> >
401  {
402 
403  typedef Grid<T, A> SelfType;
404 
405  public:
409  typedef T ValueType;
410 
414  typedef T& Reference;
415 
419  typedef const T& ConstReference;
420 
424  typedef typename A::size_type SizeType;
425 
429  typedef typename A::difference_type DifferenceType;
430 
434  typedef A ArrayType;
435 
439  typedef T* Pointer;
440 
444  typedef const T* ConstPointer;
445 
450 
455 
460 
464  typedef std::shared_ptr<SelfType> SharedPointer;
465 
469  Grid():
470  data(), size1(0), size2(0), size3(0) {}
471 
479  data(storageSize(m, n, o)), size1(m), size2(n), size3(o) {}
480 
489  data(storageSize(m, n, o), v), size1(m), size2(n), size3(o) {}
490 
495  Grid(const Grid& g):
496  data(g.data), size1(g.size1), size2(g.size2), size3(g.size3) {}
497 
502  Grid(Grid&& g):
503  data(), size1(0), size2(0), size3(0)
504  {
505  swap(g);
506  }
507 
513  template <typename E>
515  data(storageSize(e().getSize1(), e().getSize2(), e().getSize3())), size1(e().getSize1()), size2(e().getSize2()), size3(e().getSize3())
516  {
517  gridAssignGrid<ScalarAssignment>(*this, e);
518  }
519 
527  {
528  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
529  return data[i];
530  }
531 
539  {
540  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
541  return data[i];
542  }
543 
553  {
554  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
555  return data[(k * getSize2() + j) * getSize1() + i];
556  }
557 
567  {
568  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
569  return data[(k * getSize2() + j) * getSize1() + i];
570  }
571 
576  bool isEmpty() const
577  {
578  return data.empty();
579  }
580 
586  {
587  return (size1 * size2 * size3);
588  }
589 
595  {
596  return size1;
597  }
598 
604  {
605  return size2;
606  }
607 
613  {
614  return size3;
615  }
616 
622  {
623  return data.max_size();
624  }
625 
631  {
632  return data;
633  }
634 
639  const ArrayType& getData() const
640  {
641  return data;
642  }
643 
649  Grid& operator=(const Grid& g)
650  {
651  data = g.data;
652  size1 = g.size1;
653  size2 = g.size2;
654  size3 = g.size3;
655  return *this;
656  }
657 
664  {
665  swap(g);
666  return *this;
667  }
668 
675  template <typename C>
677  {
678  return assign(c);
679  }
680 
687  template <typename E>
689  {
690  Grid tmp(e);
691  swap(tmp);
692  return *this;
693  }
694 
701  template <typename C>
703  {
704  return plusAssign(c);
705  }
706 
713  template <typename E>
715  {
716  Grid tmp(*this + e);
717  swap(tmp);
718  return *this;
719  }
720 
727  template <typename C>
729  {
730  return minusAssign(c);
731  }
732 
739  template <typename E>
741  {
742  Grid tmp(*this - e);
743  swap(tmp);
744  return *this;
745  }
746 
753  template <typename T1>
754  typename std::enable_if<IsScalar<T1>::value, Grid>::type& operator*=(const T1& t)
755  {
756  gridAssignScalar<ScalarMultiplicationAssignment>(*this, t);
757  return *this;
758  }
759 
766  template <typename T1>
767  typename std::enable_if<IsScalar<T1>::value, Grid>::type& operator/=(const T1& t)
768  {
769  gridAssignScalar<ScalarDivisionAssignment>(*this, t);
770  return *this;
771  }
772 
779  template <typename E>
781  {
782  resize(e().getSize1(), e().getSize2(), false);
783  gridAssignGrid<ScalarAssignment>(*this, e);
784  return *this;
785  }
786 
793  template <typename E>
795  {
796  gridAssignGrid<ScalarAdditionAssignment>(*this, e);
797  return *this;
798  }
799 
806  template <typename E>
808  {
809  gridAssignGrid<ScalarSubtractionAssignment>(*this, e);
810  return *this;
811  }
812 
817  void swap(Grid& g)
818  {
819  if (this != &g) {
820  std::swap(data, g.data);
821  std::swap(size1, g.size1);
822  std::swap(size2, g.size2);
823  std::swap(size3, g.size3);
824  }
825  }
826 
832  friend void swap(Grid& g1, Grid& g2)
833  {
834  g1.swap(g2);
835  }
836 
841  void clear(const ValueType& v = ValueType())
842  {
843  std::fill(data.begin(), data.end(), v);
844  }
845 
854  void resize(SizeType m, SizeType n, SizeType o, bool preserve = true, const ValueType& v = ValueType())
855  {
856  if (size1 == m && size2 == n && size3 == o)
857  return;
858 
859  if (preserve) {
860  Grid tmp(m, n, o, v);
861 
862  for (SizeType i = 0, min_size1 = std::min(size1, m); i < min_size1; i++)
863  for (SizeType j = 0, min_size2 = std::min(size2, n); j < min_size2; j++)
864  for (SizeType k = 0, min_size3 = std::min(size3, o); k < min_size3; k++)
865  tmp(i, j, k) = (*this)(i, j, k);
866 
867  swap(tmp);
868 
869  } else {
870  data.resize(storageSize(m, n, o), v);
871  size1 = m;
872  size2 = n;
873  size3 = o;
874  }
875  }
876 
877  private:
878  static SizeType storageSize(SizeType m, SizeType n, SizeType o)
879  {
880  CDPL_MATH_CHECK(n == 0 || o == 0 ||
881  (n <= (std::numeric_limits<SizeType>::max() / o) && m <= (std::numeric_limits<SizeType>::max() / (n * o))),
882  "Maximum size exceeded", Base::SizeError);
883  return (m * n * o);
884  }
885 
886  ArrayType data;
887  SizeType size1;
888  SizeType size2;
889  SizeType size3;
890  };
891 
896  template <typename T>
897  class ZeroGrid : public GridContainer<ZeroGrid<T> >
898  {
899 
900  typedef ZeroGrid<T> SelfType;
901 
902  public:
906  typedef T ValueType;
907 
911  typedef const T& Reference;
912 
916  typedef const T& ConstReference;
917 
921  typedef std::size_t SizeType;
922 
926  typedef std::ptrdiff_t DifferenceType;
927 
932 
937 
942 
947  size1(0), size2(0), size3(0) {}
948 
956  size1(m), size2(n), size3(o) {}
957 
962  ZeroGrid(const ZeroGrid& m):
963  size1(m.size1), size2(m.size2), size3(m.size3) {}
964 
972  {
973  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
974  return zero;
975  }
976 
986  {
987  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
988  return zero;
989  }
990 
995  bool isEmpty() const
996  {
997  return (size1 == 0 || size2 == 0 || size3 == 0);
998  }
999 
1005  {
1006  return (size1 * size2 * size3);
1007  }
1008 
1014  {
1015  return size1;
1016  }
1017 
1023  {
1024  return size2;
1025  }
1026 
1032  {
1033  return size3;
1034  }
1035 
1041  {
1042  return std::numeric_limits<SizeType>::max();
1043  }
1044 
1050  {
1051  return std::numeric_limits<SizeType>::max();
1052  }
1053 
1059  {
1060  return std::numeric_limits<SizeType>::max();
1061  }
1062 
1069  {
1070  if (this != &g) {
1071  size1 = g.size1;
1072  size2 = g.size2;
1073  size3 = g.size3;
1074  }
1075 
1076  return *this;
1077  }
1078 
1083  void swap(ZeroGrid& g)
1084  {
1085  if (this != &g) {
1086  std::swap(size1, g.size1);
1087  std::swap(size2, g.size2);
1088  std::swap(size3, g.size3);
1089  }
1090  }
1091 
1097  friend void swap(ZeroGrid& g1, ZeroGrid& g2)
1098  {
1099  g1.swap(g2);
1100  }
1101 
1109  {
1110  size1 = m;
1111  size2 = n;
1112  size3 = o;
1113  }
1114 
1115  private:
1116  SizeType size1;
1117  SizeType size2;
1118  SizeType size3;
1119  static const ValueType zero;
1120  };
1121 
1122  template <typename T>
1123  const typename ZeroGrid<T>::ValueType ZeroGrid<T>::zero = ZeroGrid<T>::ValueType();
1124 
1129  template <typename T>
1130  class ScalarGrid : public GridContainer<ScalarGrid<T> >
1131  {
1132 
1133  typedef ScalarGrid<T> SelfType;
1134 
1135  public:
1139  typedef T ValueType;
1140 
1144  typedef const T& Reference;
1145 
1149  typedef const T& ConstReference;
1150 
1154  typedef std::size_t SizeType;
1155 
1159  typedef std::ptrdiff_t DifferenceType;
1160 
1165 
1170 
1175 
1180  size1(0), size2(0), size3(0), value() {}
1181 
1190  size1(m), size2(n), size3(o), value(v) {}
1191 
1197  size1(m.size1), size2(m.size2), size3(m.size3), value(m.value) {}
1198 
1206  {
1207  CDPL_MATH_CHECK(i < (getSize1() * getSize2() * getSize3()), "Index out of range", Base::IndexError);
1208  return value;
1209  }
1210 
1220  {
1221  CDPL_MATH_CHECK(i < getSize1() && j < getSize2() && k < getSize3(), "Index out of range", Base::IndexError);
1222  return value;
1223  }
1224 
1229  bool isEmpty() const
1230  {
1231  return (size1 == 0 || size2 == 0 || size3 == 0);
1232  }
1233 
1239  {
1240  return (size1 * size2 * size3);
1241  }
1242 
1248  {
1249  return size1;
1250  }
1251 
1257  {
1258  return size2;
1259  }
1260 
1266  {
1267  return size3;
1268  }
1269 
1275  {
1276  return std::numeric_limits<SizeType>::max();
1277  }
1278 
1284  {
1285  return std::numeric_limits<SizeType>::max();
1286  }
1287 
1293  {
1294  return std::numeric_limits<SizeType>::max();
1295  }
1296 
1303  {
1304  if (this != &g) {
1305  size1 = g.size1;
1306  size2 = g.size2;
1307  size3 = g.size3;
1308  value = g.value;
1309  }
1310 
1311  return *this;
1312  }
1313 
1318  void swap(ScalarGrid& g)
1319  {
1320  if (this != &g) {
1321  std::swap(size1, g.size1);
1322  std::swap(size2, g.size2);
1323  std::swap(size3, g.size3);
1324  std::swap(value, g.value);
1325  }
1326  }
1327 
1333  friend void swap(ScalarGrid& g1, ScalarGrid& g2)
1334  {
1335  g1.swap(g2);
1336  }
1337 
1345  {
1346  size1 = m;
1347  size2 = n;
1348  size3 = o;
1349  }
1350 
1351  private:
1352  SizeType size1;
1353  SizeType size2;
1354  SizeType size3;
1355  ValueType value;
1356  };
1357 
1362  template <typename G>
1364  {};
1365 
1370  template <typename G>
1372  {};
1373 
1378 
1383 
1388 
1393 
1398 
1403  } // namespace Math
1404 } // namespace CDPL
1405 
1406 #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:336
CRTP base class of all grid expression types.
Definition: Expression.hpp:188
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:339
GridReference(GridType &g)
Constructs the reference wrapping the grid g.
Definition: Math/Grid.hpp:109
std::conditional< std::is_const< G >::value, typename G::ConstReference, typename G::Reference >::type Reference
Mutable element reference type (degrades to ConstReference when the wrapped grid is const).
Definition: Math/Grid.hpp:78
friend void swap(GridReference &r1, GridReference &r2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:385
GridReference & minusAssign(const GridExpression< E > &e)
Subtracts the grid expression e from the wrapped grid without intermediate temporary.
Definition: Math/Grid.hpp:365
GridType & getData()
Returns a mutable reference to the wrapped grid.
Definition: Math/Grid.hpp:250
Reference operator()(SizeType i, SizeType j, SizeType k)
Returns a mutable reference to the element (i, j, k) of the wrapped grid.
Definition: Math/Grid.hpp:139
G::SizeType SizeType
The unsigned size type used by the wrapped grid.
Definition: Math/Grid.hpp:88
bool isEmpty() const
Tells whether the wrapped grid is empty (zero elements along any dimension).
Definition: Math/Grid.hpp:232
SizeType getSize2() const
Returns the size of the wrapped grid along the second dimension.
Definition: Math/Grid.hpp:178
GridReference & operator+=(const GridExpression< E > &e)
Adds the grid expression e element-wise to the wrapped grid.
Definition: Math/Grid.hpp:286
std::enable_if< IsScalar< T >::value, GridReference >::type & operator/=(const T &t)
Divides every element of the wrapped grid by the scalar t.
Definition: Math/Grid.hpp:325
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:127
SizeType getMaxSize() const
Returns the maximum total number of elements the wrapped grid can hold.
Definition: Math/Grid.hpp:196
GridReference & operator=(const GridExpression< E > &e)
Assigns the grid expression e to the wrapped grid.
Definition: Math/Grid.hpp:273
SizeType getMaxSize2() const
Returns the maximum size of the wrapped grid along the second dimension.
Definition: Math/Grid.hpp:214
std::enable_if< IsScalar< T >::value, GridReference >::type & operator*=(const T &t)
Multiplies every element of the wrapped grid by the scalar t.
Definition: Math/Grid.hpp:312
SizeType getMaxSize3() const
Returns the maximum size of the wrapped grid along the third dimension.
Definition: Math/Grid.hpp:223
G::ValueType ValueType
The element value type of the wrapped grid.
Definition: Math/Grid.hpp:71
GridReference & plusAssign(const GridExpression< E > &e)
Adds the grid expression e to the wrapped grid without intermediate temporary.
Definition: Math/Grid.hpp:352
const GridType & getData() const
Returns a const reference to the wrapped grid.
Definition: Math/Grid.hpp:241
SizeType getSize3() const
Returns the size of the wrapped grid along the third dimension.
Definition: Math/Grid.hpp:187
GridReference & operator-=(const GridExpression< E > &e)
Subtracts the grid expression e element-wise from the wrapped grid.
Definition: Math/Grid.hpp:299
G::DifferenceType DifferenceType
The signed difference type used by the wrapped grid.
Definition: Math/Grid.hpp:93
SizeType getMaxSize1() const
Returns the maximum size of the wrapped grid along the first dimension.
Definition: Math/Grid.hpp:205
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the element (i, j, k) of the wrapped grid.
Definition: Math/Grid.hpp:151
SizeType getSize1() const
Returns the size of the wrapped grid along the first dimension.
Definition: Math/Grid.hpp:169
G GridType
The wrapped grid type.
Definition: Math/Grid.hpp:66
SizeType getSize() const
Returns the total number of elements of the wrapped grid.
Definition: Math/Grid.hpp:160
GridReference & operator=(const GridReference &r)
Copies the elements of r into the wrapped grid.
Definition: Math/Grid.hpp:260
Reference operator()(SizeType i)
Returns a mutable reference to the element at the linear index i of the wrapped grid.
Definition: Math/Grid.hpp:117
G::ConstReference ConstReference
Constant element reference type.
Definition: Math/Grid.hpp:83
const SelfType ConstClosureType
Constant closure type used when this reference appears inside another expression.
Definition: Math/Grid.hpp:103
SelfType ClosureType
Closure type used when this reference appears inside another expression.
Definition: Math/Grid.hpp:98
void swap(GridReference &r)
Swaps the contents of the wrapped grid with those of the grid wrapped by r.
Definition: Math/Grid.hpp:375
Dynamically-sized dense 3D grid with configurable underlying storage.
Definition: Math/Grid.hpp:401
T * Pointer
Pointer type for raw element access.
Definition: Math/Grid.hpp:439
A::size_type SizeType
The unsigned size type used by the underlying storage container.
Definition: Math/Grid.hpp:424
Grid & operator+=(const GridExpression< E > &e)
Adds the grid expression e element-wise to this grid (via a temporary to handle aliasing).
Definition: Math/Grid.hpp:714
Grid & operator=(const Grid &g)
Copy-assigns the contents of g to this grid.
Definition: Math/Grid.hpp:649
void resize(SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
Resizes the grid to m×n×o elements.
Definition: Math/Grid.hpp:854
Grid & operator-=(const GridContainer< C > &c)
Subtracts the contents of the grid container c element-wise from this grid (no alias check needed).
Definition: Math/Grid.hpp:728
Reference operator()(SizeType i, SizeType j, SizeType k)
Returns a mutable reference to the element at (i, j, k).
Definition: Math/Grid.hpp:552
ConstReference operator()(SizeType i) const
Returns a const reference to the element at linear index i.
Definition: Math/Grid.hpp:538
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:488
Grid(Grid &&g)
Move-constructs a grid from g (g is left in a valid empty state).
Definition: Math/Grid.hpp:502
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Grid instances.
Definition: Math/Grid.hpp:464
Grid()
Constructs an empty grid (zero size on every axis).
Definition: Math/Grid.hpp:469
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:676
const T * ConstPointer
Constant pointer type for raw element access.
Definition: Math/Grid.hpp:444
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator*=(const T1 &t)
Multiplies every element by the scalar t.
Definition: Math/Grid.hpp:754
Grid & assign(const GridExpression< E > &e)
Resizes this grid to match e and assigns its elements without intermediate temporary.
Definition: Math/Grid.hpp:780
A::difference_type DifferenceType
The signed difference type used by the underlying storage container.
Definition: Math/Grid.hpp:429
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the element at (i, j, k).
Definition: Math/Grid.hpp:566
T & Reference
Mutable element reference type.
Definition: Math/Grid.hpp:414
Grid & operator=(const GridExpression< E > &e)
Assigns the grid expression e to this grid (via a temporary to handle aliasing).
Definition: Math/Grid.hpp:688
Grid & operator-=(const GridExpression< E > &e)
Subtracts the grid expression e element-wise from this grid (via a temporary to handle aliasing).
Definition: Math/Grid.hpp:740
SizeType getMaxSize() const
Returns the maximum total element count the underlying storage container can hold.
Definition: Math/Grid.hpp:621
const ArrayType & getData() const
Returns a const reference to the underlying storage container.
Definition: Math/Grid.hpp:639
void clear(const ValueType &v=ValueType())
Sets every element of the grid to the value v.
Definition: Math/Grid.hpp:841
SizeType getSize2() const
Returns the second-axis size.
Definition: Math/Grid.hpp:603
friend void swap(Grid &g1, Grid &g2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:832
const GridReference< const SelfType > ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:454
Grid & operator+=(const GridContainer< C > &c)
Adds the contents of the grid container c element-wise to this grid (no alias check needed).
Definition: Math/Grid.hpp:702
void swap(Grid &g)
Swaps the contents of this grid with those of g.
Definition: Math/Grid.hpp:817
Grid(const Grid &g)
Constructs a copy of the grid g.
Definition: Math/Grid.hpp:495
Grid & operator=(Grid &&g)
Move-assigns the contents of g to this grid.
Definition: Math/Grid.hpp:663
SelfType GridTemporaryType
Concrete temporary grid type used by expression template machinery.
Definition: Math/Grid.hpp:459
Reference operator()(SizeType i)
Returns a mutable reference to the element at linear index i.
Definition: Math/Grid.hpp:526
const T & ConstReference
Constant element reference type.
Definition: Math/Grid.hpp:419
ArrayType & getData()
Returns a mutable reference to the underlying storage container.
Definition: Math/Grid.hpp:630
bool isEmpty() const
Tells whether the grid is empty.
Definition: Math/Grid.hpp:576
SizeType getSize1() const
Returns the first-axis size.
Definition: Math/Grid.hpp:594
Grid(const GridExpression< E > &e)
Constructs the grid from the grid expression e (materializing the expression result).
Definition: Math/Grid.hpp:514
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator/=(const T1 &t)
Divides every element by the scalar t.
Definition: Math/Grid.hpp:767
A ArrayType
The underlying storage container type.
Definition: Math/Grid.hpp:434
Grid & plusAssign(const GridExpression< E > &e)
Adds the elements of the grid expression e to this grid without intermediate temporary.
Definition: Math/Grid.hpp:794
SizeType getSize() const
Returns the total element count .
Definition: Math/Grid.hpp:585
Grid & minusAssign(const GridExpression< E > &e)
Subtracts the elements of the grid expression e from this grid without intermediate temporary.
Definition: Math/Grid.hpp:807
GridReference< SelfType > ClosureType
Closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:449
T ValueType
The scalar value type stored in the grid.
Definition: Math/Grid.hpp:409
SizeType getSize3() const
Returns the third-axis size.
Definition: Math/Grid.hpp:612
Grid(SizeType m, SizeType n, SizeType o)
Constructs an m×n×o grid with default-initialized elements.
Definition: Math/Grid.hpp:478
Constant grid expression in which every element equals the same scalar value.
Definition: Math/Grid.hpp:1131
ScalarGrid()
Constructs an empty scalar grid.
Definition: Math/Grid.hpp:1179
SizeType getMaxSize3() const
Returns the maximum representable third-axis size.
Definition: Math/Grid.hpp:1292
SizeType getMaxSize1() const
Returns the maximum representable first-axis size.
Definition: Math/Grid.hpp:1274
ConstReference operator()(SizeType i) const
Returns a const reference to the common element value (linear-index form).
Definition: Math/Grid.hpp:1205
GridReference< SelfType > ClosureType
Closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:1164
SizeType getSize1() const
Returns the first-axis size.
Definition: Math/Grid.hpp:1247
friend void swap(ScalarGrid &g1, ScalarGrid &g2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:1333
ScalarGrid(const ScalarGrid &m)
Constructs a copy of the scalar grid m.
Definition: Math/Grid.hpp:1196
ScalarGrid(SizeType m, SizeType n, SizeType o, const ValueType &v=ValueType())
Constructs a scalar grid of size m×n×o in which every element equals v.
Definition: Math/Grid.hpp:1189
bool isEmpty() const
Tells whether the grid is empty (any axis has zero size).
Definition: Math/Grid.hpp:1229
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the common element value (3D-index form).
Definition: Math/Grid.hpp:1219
const T & Reference
Mutable element reference type (always a const reference — elements are immutable).
Definition: Math/Grid.hpp:1144
std::size_t SizeType
The unsigned size type.
Definition: Math/Grid.hpp:1154
SizeType getSize3() const
Returns the third-axis size.
Definition: Math/Grid.hpp:1265
const GridReference< const SelfType > ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:1169
ScalarGrid & operator=(const ScalarGrid &g)
Copy-assigns the axis sizes and common value from g.
Definition: Math/Grid.hpp:1302
const T & ConstReference
Constant element reference type.
Definition: Math/Grid.hpp:1149
Grid< T > GridTemporaryType
Concrete temporary grid type used by expression template machinery.
Definition: Math/Grid.hpp:1174
SizeType getMaxSize2() const
Returns the maximum representable second-axis size.
Definition: Math/Grid.hpp:1283
void swap(ScalarGrid &g)
Swaps the axis sizes and common value with g.
Definition: Math/Grid.hpp:1318
SizeType getSize2() const
Returns the second-axis size.
Definition: Math/Grid.hpp:1256
SizeType getSize() const
Returns the total element count .
Definition: Math/Grid.hpp:1238
void resize(SizeType m, SizeType n, SizeType o)
Resizes the grid axes to (m, n, o).
Definition: Math/Grid.hpp:1344
T ValueType
The scalar value type.
Definition: Math/Grid.hpp:1139
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Math/Grid.hpp:1159
Constant grid expression whose elements are all zero.
Definition: Math/Grid.hpp:898
SizeType getMaxSize3() const
Returns the maximum representable third-axis size.
Definition: Math/Grid.hpp:1058
ZeroGrid & operator=(const ZeroGrid &g)
Copy-assigns the axis sizes from g.
Definition: Math/Grid.hpp:1068
Grid< T > GridTemporaryType
Concrete temporary grid type used by expression template machinery.
Definition: Math/Grid.hpp:941
SizeType getSize2() const
Returns the second-axis size.
Definition: Math/Grid.hpp:1022
SizeType getSize3() const
Returns the third-axis size.
Definition: Math/Grid.hpp:1031
SizeType getSize() const
Returns the total element count .
Definition: Math/Grid.hpp:1004
void swap(ZeroGrid &g)
Swaps the axis sizes with g.
Definition: Math/Grid.hpp:1083
SizeType getMaxSize2() const
Returns the maximum representable second-axis size.
Definition: Math/Grid.hpp:1049
friend void swap(ZeroGrid &g1, ZeroGrid &g2)
ADL-enabled free-function form of swap().
Definition: Math/Grid.hpp:1097
ZeroGrid(SizeType m, SizeType n, SizeType o)
Constructs a zero grid of size m×n×o.
Definition: Math/Grid.hpp:955
T ValueType
The scalar value type.
Definition: Math/Grid.hpp:906
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the zero element (3D-index form).
Definition: Math/Grid.hpp:985
ConstReference operator()(SizeType i) const
Returns a const reference to the zero element (linear-index form).
Definition: Math/Grid.hpp:971
const T & Reference
Reference type (always a const reference — all elements are zero).
Definition: Math/Grid.hpp:911
SizeType getMaxSize1() const
Returns the maximum representable first-axis size.
Definition: Math/Grid.hpp:1040
ZeroGrid(const ZeroGrid &m)
Constructs a copy of the zero grid m.
Definition: Math/Grid.hpp:962
const GridReference< const SelfType > ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:936
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Math/Grid.hpp:926
ZeroGrid()
Constructs an empty zero grid (zero size on every axis).
Definition: Math/Grid.hpp:946
GridReference< SelfType > ClosureType
Closure type used when this grid appears inside another expression.
Definition: Math/Grid.hpp:931
SizeType getSize1() const
Returns the first-axis size.
Definition: Math/Grid.hpp:1013
const T & ConstReference
Constant reference type to the zero element.
Definition: Math/Grid.hpp:916
std::size_t SizeType
The unsigned size type.
Definition: Math/Grid.hpp:921
void resize(SizeType m, SizeType n, SizeType o)
Resizes the grid axes to (m, n, o).
Definition: Math/Grid.hpp:1108
bool isEmpty() const
Tells whether the grid is empty (any axis has zero size).
Definition: Math/Grid.hpp:995
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:1402
ScalarGrid< float > FScalarGrid
Immutable grid where all elements have the same value of type float.
Definition: Math/Grid.hpp:1387
ZeroGrid< double > DZeroGrid
Immutable grid where all elements have the value zero of type double.
Definition: Math/Grid.hpp:1382
Grid< float > FGrid
Unbounded dense grid storing floating-point values of type float.
Definition: Math/Grid.hpp:1397
ZeroGrid< float > FZeroGrid
Immutable grid where all elements have the value zero of type float.
Definition: Math/Grid.hpp:1377
ScalarGrid< double > DScalarGrid
Immutable grid where all elements have the same value of type double.
Definition: Math/Grid.hpp:1392
The namespace of the Chemical Data Processing Library.
Selects a concrete temporary grid type compatible with the grid expression G.
Definition: TypeTraits.hpp:365