27 #ifndef CDPL_MATH_GRID_HPP
28 #define CDPL_MATH_GRID_HPP
34 #include <type_traits>
61 typedef typename std::conditional<std::is_const<G>::value,
62 typename G::ConstReference,
95 return data.getSize();
100 return data.getSize1();
105 return data.getSize2();
110 return data.getSize3();
115 return data.getMaxSize();
120 return data.getMaxSize1();
125 return data.getMaxSize2();
130 return data.getMaxSize3();
135 return data.isEmpty();
150 data.operator=(
r.data);
154 template <
typename E>
161 template <
typename E>
168 template <
typename E>
175 template <
typename T>
182 template <
typename T>
189 template <
typename E>
196 template <
typename E>
203 template <
typename E>
224 template <
typename T,
typename A = std::vector<T> >
245 data(), size1(0), size2(0), size3(0) {}
248 data(storageSize(
m, n, o)), size1(
m), size2(n), size3(o) {}
251 data(storageSize(
m, n, o), v), size1(
m), size2(n), size3(o) {}
254 data(g.data), size1(g.size1), size2(g.size2), size3(g.size3) {}
257 data(), size1(0), size2(0), size3(0)
262 template <
typename E>
266 gridAssignGrid<ScalarAssignment>(*
this, e);
300 return (size1 * size2 * size3);
320 return data.max_size();
348 template <
typename C>
354 template <
typename E>
362 template <
typename C>
368 template <
typename E>
376 template <
typename C>
382 template <
typename E>
390 template <
typename T1>
391 typename std::enable_if<IsScalar<T1>::value,
Grid>::type&
operator*=(
const T1& t)
393 gridAssignScalar<ScalarMultiplicationAssignment>(*
this, t);
397 template <
typename T1>
398 typename std::enable_if<IsScalar<T1>::value,
Grid>::type&
operator/=(
const T1& t)
400 gridAssignScalar<ScalarDivisionAssignment>(*
this, t);
404 template <
typename E>
408 gridAssignGrid<ScalarAssignment>(*
this, e);
412 template <
typename E>
415 gridAssignGrid<ScalarAdditionAssignment>(*
this, e);
419 template <
typename E>
422 gridAssignGrid<ScalarSubtractionAssignment>(*
this, e);
429 std::swap(data, g.data);
430 std::swap(size1, g.size1);
431 std::swap(size2, g.size2);
432 std::swap(size3, g.size3);
443 std::fill(data.begin(), data.end(), v);
448 if (size1 ==
m && size2 == n && size3 == o)
452 Grid tmp(
m, n, o, v);
454 for (
SizeType i = 0, min_size1 = std::min(size1,
m); i < min_size1; i++)
455 for (
SizeType j = 0, min_size2 = std::min(size2, n); j < min_size2; j++)
456 for (
SizeType k = 0, min_size3 = std::min(size3, o); k < min_size3; k++)
457 tmp(i, j, k) = (*this)(i, j, k);
462 data.resize(storageSize(
m, n, o), v);
473 (n <= (std::numeric_limits<SizeType>::max() / o) &&
m <= (std::numeric_limits<SizeType>::max() / (n * o))),
484 template <
typename T>
501 size1(0), size2(0), size3(0) {}
504 size1(
m), size2(n), size3(o) {}
507 size1(
m.size1), size2(
m.size2), size3(
m.size3) {}
523 return (size1 == 0 || size2 == 0 || size3 == 0);
528 return (size1 * size2 * size3);
548 return std::numeric_limits<SizeType>::max();
553 return std::numeric_limits<SizeType>::max();
558 return std::numeric_limits<SizeType>::max();
575 std::swap(size1, g.size1);
576 std::swap(size2, g.size2);
577 std::swap(size3, g.size3);
600 template <
typename T>
603 template <
typename T>
620 size1(0), size2(0), size3(0), value() {}
623 size1(
m), size2(n), size3(o), value(v) {}
626 size1(
m.size1), size2(
m.size2), size3(
m.size3), value(
m.value) {}
642 return (size1 == 0 || size2 == 0 || size3 == 0);
647 return (size1 * size2 * size3);
667 return std::numeric_limits<SizeType>::max();
672 return std::numeric_limits<SizeType>::max();
677 return std::numeric_limits<SizeType>::max();
695 std::swap(size1, g.size1);
696 std::swap(size2, g.size2);
697 std::swap(size3, g.size3);
698 std::swap(value, g.value);
721 template <
typename G>
725 template <
typename G>
Definition of exception classes.
Definition of various preprocessor macros for error checking.
#define CDPL_MATH_CHECK(expr, msg, e)
Definition: Check.hpp:36
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
Definition: Expression.hpp:208
Definition: Expression.hpp:120
Definition: Math/Grid.hpp:54
GridReference & assign(const GridExpression< E > &e)
Definition: Math/Grid.hpp:190
GridReference(GridType &g)
Definition: Math/Grid.hpp:70
std::conditional< std::is_const< G >::value, typename G::ConstReference, typename G::Reference >::type Reference
Definition: Math/Grid.hpp:63
friend void swap(GridReference &r1, GridReference &r2)
Definition: Math/Grid.hpp:215
GridReference & minusAssign(const GridExpression< E > &e)
Definition: Math/Grid.hpp:204
GridType & getData()
Definition: Math/Grid.hpp:143
Reference operator()(SizeType i, SizeType j, SizeType k)
Definition: Math/Grid.hpp:83
G::SizeType SizeType
Definition: Math/Grid.hpp:65
bool isEmpty() const
Definition: Math/Grid.hpp:133
SizeType getSize2() const
Definition: Math/Grid.hpp:103
GridReference & operator+=(const GridExpression< E > &e)
Definition: Math/Grid.hpp:162
std::enable_if< IsScalar< T >::value, GridReference >::type & operator/=(const T &t)
Definition: Math/Grid.hpp:183
ConstReference operator()(SizeType i) const
Definition: Math/Grid.hpp:78
SizeType getMaxSize() const
Definition: Math/Grid.hpp:113
GridReference & operator=(const GridExpression< E > &e)
Definition: Math/Grid.hpp:155
SizeType getMaxSize2() const
Definition: Math/Grid.hpp:123
std::enable_if< IsScalar< T >::value, GridReference >::type & operator*=(const T &t)
Definition: Math/Grid.hpp:176
SizeType getMaxSize3() const
Definition: Math/Grid.hpp:128
G::ValueType ValueType
Definition: Math/Grid.hpp:60
GridReference & plusAssign(const GridExpression< E > &e)
Definition: Math/Grid.hpp:197
const GridType & getData() const
Definition: Math/Grid.hpp:138
SizeType getSize3() const
Definition: Math/Grid.hpp:108
GridReference & operator-=(const GridExpression< E > &e)
Definition: Math/Grid.hpp:169
G::DifferenceType DifferenceType
Definition: Math/Grid.hpp:66
SizeType getMaxSize1() const
Definition: Math/Grid.hpp:118
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Definition: Math/Grid.hpp:88
SizeType getSize1() const
Definition: Math/Grid.hpp:98
G GridType
Definition: Math/Grid.hpp:59
SizeType getSize() const
Definition: Math/Grid.hpp:93
GridReference & operator=(const GridReference &r)
Definition: Math/Grid.hpp:148
Reference operator()(SizeType i)
Definition: Math/Grid.hpp:73
G::ConstReference ConstReference
Definition: Math/Grid.hpp:64
const SelfType ConstClosureType
Definition: Math/Grid.hpp:68
SelfType ClosureType
Definition: Math/Grid.hpp:67
void swap(GridReference &r)
Definition: Math/Grid.hpp:210
Definition: Math/Grid.hpp:226
T * Pointer
Definition: Math/Grid.hpp:237
A::size_type SizeType
Definition: Math/Grid.hpp:234
Grid & operator+=(const GridExpression< E > &e)
Definition: Math/Grid.hpp:369
Grid & operator=(const Grid &g)
Definition: Math/Grid.hpp:333
void resize(SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
Definition: Math/Grid.hpp:446
Grid & operator-=(const GridContainer< C > &c)
Definition: Math/Grid.hpp:377
Reference operator()(SizeType i, SizeType j, SizeType k)
Definition: Math/Grid.hpp:281
ConstReference operator()(SizeType i) const
Definition: Math/Grid.hpp:275
Grid(SizeType m, SizeType n, SizeType o, const ValueType &v)
Definition: Math/Grid.hpp:250
Grid(Grid &&g)
Definition: Math/Grid.hpp:256
std::shared_ptr< SelfType > SharedPointer
Definition: Math/Grid.hpp:242
Grid()
Definition: Math/Grid.hpp:244
Grid & operator=(const GridContainer< C > &c)
Definition: Math/Grid.hpp:349
const T * ConstPointer
Definition: Math/Grid.hpp:238
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator*=(const T1 &t)
Definition: Math/Grid.hpp:391
Grid & assign(const GridExpression< E > &e)
Definition: Math/Grid.hpp:405
A::difference_type DifferenceType
Definition: Math/Grid.hpp:235
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Definition: Math/Grid.hpp:287
T & Reference
Definition: Math/Grid.hpp:232
Grid & operator=(const GridExpression< E > &e)
Definition: Math/Grid.hpp:355
Grid & operator-=(const GridExpression< E > &e)
Definition: Math/Grid.hpp:383
SizeType getMaxSize() const
Definition: Math/Grid.hpp:318
const ArrayType & getData() const
Definition: Math/Grid.hpp:328
void clear(const ValueType &v=ValueType())
Definition: Math/Grid.hpp:441
SizeType getSize2() const
Definition: Math/Grid.hpp:308
friend void swap(Grid &g1, Grid &g2)
Definition: Math/Grid.hpp:436
const GridReference< const SelfType > ConstClosureType
Definition: Math/Grid.hpp:240
Grid & operator+=(const GridContainer< C > &c)
Definition: Math/Grid.hpp:363
void swap(Grid &g)
Definition: Math/Grid.hpp:426
Grid(const Grid &g)
Definition: Math/Grid.hpp:253
Grid & operator=(Grid &&g)
Definition: Math/Grid.hpp:342
SelfType GridTemporaryType
Definition: Math/Grid.hpp:241
Reference operator()(SizeType i)
Definition: Math/Grid.hpp:269
const T & ConstReference
Definition: Math/Grid.hpp:233
ArrayType & getData()
Definition: Math/Grid.hpp:323
bool isEmpty() const
Definition: Math/Grid.hpp:293
SizeType getSize1() const
Definition: Math/Grid.hpp:303
Grid(const GridExpression< E > &e)
Definition: Math/Grid.hpp:263
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator/=(const T1 &t)
Definition: Math/Grid.hpp:398
A ArrayType
Definition: Math/Grid.hpp:236
Grid & plusAssign(const GridExpression< E > &e)
Definition: Math/Grid.hpp:413
SizeType getSize() const
Definition: Math/Grid.hpp:298
Grid & minusAssign(const GridExpression< E > &e)
Definition: Math/Grid.hpp:420
GridReference< SelfType > ClosureType
Definition: Math/Grid.hpp:239
T ValueType
Definition: Math/Grid.hpp:231
SizeType getSize3() const
Definition: Math/Grid.hpp:313
Grid(SizeType m, SizeType n, SizeType o)
Definition: Math/Grid.hpp:247
Definition: Math/Grid.hpp:605
ScalarGrid()
Definition: Math/Grid.hpp:619
SizeType getMaxSize3() const
Definition: Math/Grid.hpp:675
SizeType getMaxSize1() const
Definition: Math/Grid.hpp:665
ConstReference operator()(SizeType i) const
Definition: Math/Grid.hpp:628
GridReference< SelfType > ClosureType
Definition: Math/Grid.hpp:615
SizeType getSize1() const
Definition: Math/Grid.hpp:650
friend void swap(ScalarGrid &g1, ScalarGrid &g2)
Definition: Math/Grid.hpp:702
ScalarGrid(const ScalarGrid &m)
Definition: Math/Grid.hpp:625
ScalarGrid(SizeType m, SizeType n, SizeType o, const ValueType &v=ValueType())
Definition: Math/Grid.hpp:622
bool isEmpty() const
Definition: Math/Grid.hpp:640
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Definition: Math/Grid.hpp:634
const T & Reference
Definition: Math/Grid.hpp:611
std::size_t SizeType
Definition: Math/Grid.hpp:613
SizeType getSize3() const
Definition: Math/Grid.hpp:660
const GridReference< const SelfType > ConstClosureType
Definition: Math/Grid.hpp:616
ScalarGrid & operator=(const ScalarGrid &g)
Definition: Math/Grid.hpp:680
const T & ConstReference
Definition: Math/Grid.hpp:612
Grid< T > GridTemporaryType
Definition: Math/Grid.hpp:617
SizeType getMaxSize2() const
Definition: Math/Grid.hpp:670
void swap(ScalarGrid &g)
Definition: Math/Grid.hpp:692
SizeType getSize2() const
Definition: Math/Grid.hpp:655
SizeType getSize() const
Definition: Math/Grid.hpp:645
void resize(SizeType m, SizeType n, SizeType o)
Definition: Math/Grid.hpp:707
T ValueType
Definition: Math/Grid.hpp:610
std::ptrdiff_t DifferenceType
Definition: Math/Grid.hpp:614
Definition: Math/Grid.hpp:486
SizeType getMaxSize3() const
Definition: Math/Grid.hpp:556
ZeroGrid & operator=(const ZeroGrid &g)
Definition: Math/Grid.hpp:561
Grid< T > GridTemporaryType
Definition: Math/Grid.hpp:498
SizeType getSize2() const
Definition: Math/Grid.hpp:536
SizeType getSize3() const
Definition: Math/Grid.hpp:541
SizeType getSize() const
Definition: Math/Grid.hpp:526
void swap(ZeroGrid &g)
Definition: Math/Grid.hpp:572
SizeType getMaxSize2() const
Definition: Math/Grid.hpp:551
friend void swap(ZeroGrid &g1, ZeroGrid &g2)
Definition: Math/Grid.hpp:581
ZeroGrid(SizeType m, SizeType n, SizeType o)
Definition: Math/Grid.hpp:503
T ValueType
Definition: Math/Grid.hpp:491
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Definition: Math/Grid.hpp:515
ConstReference operator()(SizeType i) const
Definition: Math/Grid.hpp:509
const T & Reference
Definition: Math/Grid.hpp:492
SizeType getMaxSize1() const
Definition: Math/Grid.hpp:546
ZeroGrid(const ZeroGrid &m)
Definition: Math/Grid.hpp:506
const GridReference< const SelfType > ConstClosureType
Definition: Math/Grid.hpp:497
std::ptrdiff_t DifferenceType
Definition: Math/Grid.hpp:495
ZeroGrid()
Definition: Math/Grid.hpp:500
GridReference< SelfType > ClosureType
Definition: Math/Grid.hpp:496
SizeType getSize1() const
Definition: Math/Grid.hpp:531
const T & ConstReference
Definition: Math/Grid.hpp:493
std::size_t SizeType
Definition: Math/Grid.hpp:494
void resize(SizeType m, SizeType n, SizeType o)
Definition: Math/Grid.hpp:586
bool isEmpty() const
Definition: Math/Grid.hpp:521
constexpr unsigned int A
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
An unbounded dense grid holding floating point values of type double.
Definition: Math/Grid.hpp:743
ScalarGrid< float > FScalarGrid
Definition: Math/Grid.hpp:732
ZeroGrid< double > DZeroGrid
Definition: Math/Grid.hpp:730
Grid< float > FGrid
An unbounded dense grid holding floating point values of type float.
Definition: Math/Grid.hpp:738
ZeroGrid< float > FZeroGrid
Definition: Math/Grid.hpp:729
ScalarGrid< double > DScalarGrid
Definition: Math/Grid.hpp:733
The namespace of the Chemical Data Processing Library.
Definition: TypeTraits.hpp:200