1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/* DB_Matrix class implementation: inline functions.
Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com)
This file is part of the Parma Polyhedra Library (PPL).
The PPL is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
The PPL is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
For the most up-to-date information see the Parma Polyhedra Library
site: http://www.cs.unipr.it/ppl/ . */
#ifndef PPL_DB_Matrix_inlines_hh
#define PPL_DB_Matrix_inlines_hh 1
#include "globals.defs.hh"
#include "Checked_Number.defs.hh"
#include "distances.defs.hh"
#include "assert.hh"
#include <iostream>
namespace Parma_Polyhedra_Library {
template <typename T>
inline void
DB_Matrix<T>::swap(DB_Matrix& y) {
std::swap(rows, y.rows);
std::swap(row_size, y.row_size);
std::swap(row_capacity, y.row_capacity);
}
template <typename T>
inline dimension_type
DB_Matrix<T>::max_num_rows() {
return std::vector<DB_Row<T> >().max_size();
}
template <typename T>
inline dimension_type
DB_Matrix<T>::max_num_columns() {
return DB_Row<T>::max_size();
}
template <typename T>
inline memory_size_type
DB_Matrix<T>::total_memory_in_bytes() const {
return sizeof(*this) + external_memory_in_bytes();
}
template <typename T>
inline
DB_Matrix<T>::const_iterator::const_iterator()
: i(Iter()) {
}
template <typename T>
inline
DB_Matrix<T>::const_iterator::const_iterator(const Iter& b)
: i(b) {
}
template <typename T>
inline
DB_Matrix<T>::const_iterator::const_iterator(const const_iterator& y)
: i(y.i) {
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator&
DB_Matrix<T>::const_iterator::operator=(const const_iterator& y) {
i = y.i;
return *this;
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator::reference
DB_Matrix<T>::const_iterator::operator*() const {
return *i;
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator::pointer
DB_Matrix<T>::const_iterator::operator->() const {
return &*i;
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator&
DB_Matrix<T>::const_iterator::operator++() {
++i;
return *this;
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator
DB_Matrix<T>::const_iterator::operator++(int) {
return const_iterator(i++);
}
template <typename T>
inline bool
DB_Matrix<T>::const_iterator::operator==(const const_iterator& y) const {
return i == y.i;
}
template <typename T>
inline bool
DB_Matrix<T>::const_iterator::operator!=(const const_iterator& y) const {
return !operator==(y);
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator
DB_Matrix<T>::begin() const {
return const_iterator(rows.begin());
}
template <typename T>
inline typename DB_Matrix<T>::const_iterator
DB_Matrix<T>::end() const {
return const_iterator(rows.end());
}
template <typename T>
inline
DB_Matrix<T>::DB_Matrix()
: rows(),
row_size(0),
row_capacity(0) {
}
template <typename T>
inline
DB_Matrix<T>::~DB_Matrix() {
}
template <typename T>
inline DB_Row<T>&
DB_Matrix<T>::operator[](const dimension_type k) {
PPL_ASSERT(k < rows.size());
return rows[k];
}
template <typename T>
inline const DB_Row<T>&
DB_Matrix<T>::operator[](const dimension_type k) const {
PPL_ASSERT(k < rows.size());
return rows[k];
}
template <typename T>
inline dimension_type
DB_Matrix<T>::num_rows() const {
return rows.size();
}
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \relates DB_Matrix */
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename T>
inline bool
operator!=(const DB_Matrix<T>& x, const DB_Matrix<T>& y) {
return !(x == y);
}
template <typename T>
inline
DB_Matrix<T>::DB_Matrix(const DB_Matrix& y)
: rows(y.rows),
row_size(y.row_size),
row_capacity(compute_capacity(y.row_size, max_num_columns())) {
}
template <typename T>
inline DB_Matrix<T>&
DB_Matrix<T>::operator=(const DB_Matrix& y) {
// Without the following guard against auto-assignments we would
// recompute the row capacity based on row size, possibly without
// actually increasing the capacity of the rows. This would lead to
// an inconsistent state.
if (this != &y) {
// The following assignment may do nothing on auto-assignments...
rows = y.rows;
row_size = y.row_size;
// ... hence the following assignment must not be done on
// auto-assignments.
row_capacity = compute_capacity(y.row_size, max_num_columns());
}
return *this;
}
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \relates DB_Matrix */
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename Specialization, typename Temp, typename To, typename T>
inline bool
l_m_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
const DB_Matrix<T>& x,
const DB_Matrix<T>& y,
const Rounding_Dir dir,
Temp& tmp0,
Temp& tmp1,
Temp& tmp2) {
const dimension_type x_num_rows = x.num_rows();
if (x_num_rows != y.num_rows())
return false;
assign_r(tmp0, 0, ROUND_NOT_NEEDED);
for (dimension_type i = x_num_rows; i-- > 0; ) {
const DB_Row<T>& x_i = x[i];
const DB_Row<T>& y_i = y[i];
for (dimension_type j = x_num_rows; j-- > 0; ) {
const T& x_i_j = x_i[j];
const T& y_i_j = y_i[j];
if (is_plus_infinity(x_i_j)) {
if (is_plus_infinity(y_i_j))
continue;
else {
pinf:
assign_r(r, PLUS_INFINITY, ROUND_NOT_NEEDED);
return true;
}
}
else if (is_plus_infinity(y_i_j))
goto pinf;
const Temp* tmp1p;
const Temp* tmp2p;
if (x_i_j > y_i_j) {
maybe_assign(tmp1p, tmp1, x_i_j, dir);
maybe_assign(tmp2p, tmp2, y_i_j, inverse(dir));
}
else {
maybe_assign(tmp1p, tmp1, y_i_j, dir);
maybe_assign(tmp2p, tmp2, x_i_j, inverse(dir));
}
sub_assign_r(tmp1, *tmp1p, *tmp2p, dir);
PPL_ASSERT(sgn(tmp1) >= 0);
Specialization::combine(tmp0, tmp1, dir);
}
}
Specialization::finalize(tmp0, dir);
assign_r(r, tmp0, dir);
return true;
}
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \relates DB_Matrix */
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename Temp, typename To, typename T>
inline bool
rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
const DB_Matrix<T>& x,
const DB_Matrix<T>& y,
const Rounding_Dir dir,
Temp& tmp0,
Temp& tmp1,
Temp& tmp2) {
return
l_m_distance_assign<Rectilinear_Distance_Specialization<Temp> >(r, x, y,
dir,
tmp0,
tmp1,
tmp2);
}
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \relates DB_Matrix */
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename Temp, typename To, typename T>
inline bool
euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
const DB_Matrix<T>& x,
const DB_Matrix<T>& y,
const Rounding_Dir dir,
Temp& tmp0,
Temp& tmp1,
Temp& tmp2) {
return
l_m_distance_assign<Euclidean_Distance_Specialization<Temp> >(r, x, y,
dir,
tmp0,
tmp1,
tmp2);
}
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \relates DB_Matrix */
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename Temp, typename To, typename T>
inline bool
l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
const DB_Matrix<T>& x,
const DB_Matrix<T>& y,
const Rounding_Dir dir,
Temp& tmp0,
Temp& tmp1,
Temp& tmp2) {
return
l_m_distance_assign<L_Infinity_Distance_Specialization<Temp> >(r, x, y,
dir,
tmp0,
tmp1,
tmp2);
}
} // namespace Parma_Polyhedra_Library
namespace std {
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \relates Parma_Polyhedra_Library::DB_Matrix */
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
template <typename T>
inline void
swap(Parma_Polyhedra_Library::DB_Matrix<T>& x,
Parma_Polyhedra_Library::DB_Matrix<T>& y) {
x.swap(y);
}
} // namespace std
#endif // !defined(PPL_DB_Matrix_inlines_hh)
|