CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
position.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <cstdlib>
38#include <iostream>
39
40#include "../../config.h"
41#include "../../misc/macros.hpp"
42
44namespace codi {
45
48 public:
49
51 bool operator!=(EmptyPosition const& o) const {
52 CODI_UNUSED(o);
53 return false;
54 }
55
57 bool operator==(EmptyPosition const& o) const {
58 CODI_UNUSED(o);
59 return true;
60 }
61
63 bool operator<(EmptyPosition const& o) const {
64 CODI_UNUSED(o);
65 return false;
66 }
67
69 bool operator<=(EmptyPosition const& o) const {
70 CODI_UNUSED(o);
71 return true;
72 }
73
75 bool operator>(EmptyPosition const& o) const {
76 CODI_UNUSED(o);
77 return false;
78 }
79
81 bool operator>=(EmptyPosition const& o) const {
82 CODI_UNUSED(o);
83 return true;
84 }
85
87 friend std::ostream& operator<<(std::ostream& stream, EmptyPosition const& pos) {
88 CODI_UNUSED(pos);
89 stream << "[]";
90 return stream;
91 }
92 };
93
101 template<typename T_NestedPosition>
103 public:
104
105 using NestedPosition = CODI_DD(T_NestedPosition, EmptyPosition);
106
107 size_t data;
108
110
113
115 ArrayPosition(size_t const& data, NestedPosition const& inner) : data(data), inner(inner) {}
116
118 bool operator!=(ArrayPosition const& o) const {
119 return data != o.data || this->inner != o.inner;
120 }
121
123 bool operator==(ArrayPosition const& o) const {
124 return data == o.data && this->inner == o.inner;
125 }
126
128 bool operator<(ArrayPosition const& o) const {
129 return data < o.data || (data == o.data && inner < o.inner);
130 }
131
133 bool operator<=(ArrayPosition const& o) const {
134 return data < o.data || (data == o.data && inner <= o.inner);
135 }
136
138 bool operator>(ArrayPosition const& o) const {
139 return o < *this;
140 }
141
143 bool operator>=(ArrayPosition const& o) const {
144 return o <= *this;
145 }
146
148 friend std::ostream& operator<<(std::ostream& stream, ArrayPosition const& pos) {
149 stream << "[" << pos.data << ", " << pos.inner << "]";
150 return stream;
151 }
152 };
153
165 template<typename T_NestedPosition>
166 struct ChunkPosition : public ArrayPosition<T_NestedPosition> {
167 public:
168
169 using NestedPosition = CODI_DD(T_NestedPosition, EmptyPosition);
171
172 size_t chunk;
173
176
178 ChunkPosition(size_t const& chunk, size_t const& data, NestedPosition const& inner)
179 : Base(data, inner), chunk(chunk) {}
180
182 bool operator!=(ChunkPosition const& o) const {
183 return chunk != o.chunk || Base::operator!=(static_cast<Base const&>(o));
184 }
185
187 bool operator==(ChunkPosition const& o) const {
188 return chunk == o.chunk && Base::operator==(static_cast<Base const&>(o));
189 }
190
192 bool operator<(ChunkPosition const& o) const {
193 return chunk < o.chunk || (chunk == o.chunk && Base::operator<(static_cast<Base const&>(o)));
194 }
195
197 bool operator<=(ChunkPosition const& o) const {
198 return chunk < o.chunk || (chunk == o.chunk && Base::operator<=(static_cast<Base const&>(o)));
199 }
200
202 bool operator>(ChunkPosition const& o) const {
203 return o < *this;
204 }
205
207 bool operator>=(ChunkPosition const& o) const {
208 return o <= *this;
209 }
210
212 friend std::ostream& operator<<(std::ostream& stream, ChunkPosition const& pos) {
213 stream << "[" << pos.chunk << ", " << pos.data << ", " << pos.inner << "]";
214 return stream;
215 }
216 };
217}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Position with one index for e.g. array access.
Definition position.hpp:102
ArrayPosition(size_t const &data, NestedPosition const &inner)
Constructor.
Definition position.hpp:115
ArrayPosition()
Constructor.
Definition position.hpp:112
friend std::ostream & operator<<(std::ostream &stream, ArrayPosition const &pos)
Stream output.
Definition position.hpp:148
size_t data
Array position index.
Definition position.hpp:107
bool operator<=(ArrayPosition const &o) const
Operator <= also compares with nested data.
Definition position.hpp:133
bool operator<(ArrayPosition const &o) const
Operator < also compares with nested data.
Definition position.hpp:128
NestedPosition inner
Position of nested data.
Definition position.hpp:109
T_NestedPosition NestedPosition
See ArrayPosition.
Definition position.hpp:105
bool operator!=(ArrayPosition const &o) const
Operator != also compares with nested data.
Definition position.hpp:118
bool operator>=(ArrayPosition const &o) const
Operator >= also compares with nested data.
Definition position.hpp:143
bool operator>(ArrayPosition const &o) const
Operator > also compares with nested data.
Definition position.hpp:138
bool operator==(ArrayPosition const &o) const
Operator == also compares with nested data.
Definition position.hpp:123
Position with two indices for e.g. chunked data access.
Definition position.hpp:166
ChunkPosition(size_t const &chunk, size_t const &data, NestedPosition const &inner)
Constructor.
Definition position.hpp:178
bool operator<=(ChunkPosition const &o) const
Operator <= also compares with nested data.
Definition position.hpp:197
bool operator>=(ChunkPosition const &o) const
Operator >= also compares with nested data.
Definition position.hpp:207
bool operator==(ChunkPosition const &o) const
Operator == also compares with nested data.
Definition position.hpp:187
bool operator<(ChunkPosition const &o) const
Operator < also compares with nested data.
Definition position.hpp:192
size_t chunk
Chunk position index.
Definition position.hpp:172
bool operator!=(ChunkPosition const &o) const
Operator != also compares with nested data.
Definition position.hpp:182
ChunkPosition()
Constructor.
Definition position.hpp:175
T_NestedPosition NestedPosition
See ChunkPosition.
Definition position.hpp:169
friend std::ostream & operator<<(std::ostream &stream, ChunkPosition const &pos)
Stream output.
Definition position.hpp:212
bool operator>(ChunkPosition const &o) const
Operator > also compares with nested data.
Definition position.hpp:202
Empty Position with no nested data.
Definition position.hpp:47
bool operator!=(EmptyPosition const &o) const
Always false.
Definition position.hpp:51
bool operator>(EmptyPosition const &o) const
Always false.
Definition position.hpp:75
friend std::ostream & operator<<(std::ostream &stream, EmptyPosition const &pos)
Stream output.
Definition position.hpp:87
bool operator<=(EmptyPosition const &o) const
Always true.
Definition position.hpp:69
bool operator<(EmptyPosition const &o) const
Always false.
Definition position.hpp:63
bool operator==(EmptyPosition const &o) const
Always true.
Definition position.hpp:57
bool operator>=(EmptyPosition const &o) const
Always true.
Definition position.hpp:81