00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PPL_DB_Matrix_inlines_hh
00024 #define PPL_DB_Matrix_inlines_hh 1
00025
00026 #include "globals.defs.hh"
00027 #include "Checked_Number.defs.hh"
00028 #include "distances.defs.hh"
00029 #include <cassert>
00030 #include <iostream>
00031
00032 namespace Parma_Polyhedra_Library {
00033
00034 template <typename T>
00035 inline void
00036 DB_Matrix<T>::swap(DB_Matrix& y) {
00037 std::swap(rows, y.rows);
00038 std::swap(row_size, y.row_size);
00039 std::swap(row_capacity, y.row_capacity);
00040 }
00041
00042 template <typename T>
00043 inline dimension_type
00044 DB_Matrix<T>::max_num_rows() {
00045 return std::vector<DB_Row<T> >().max_size();
00046 }
00047
00048 template <typename T>
00049 inline dimension_type
00050 DB_Matrix<T>::max_num_columns() {
00051 return DB_Row<T>::max_size();
00052 }
00053
00054 template <typename T>
00055 inline memory_size_type
00056 DB_Matrix<T>::total_memory_in_bytes() const {
00057 return sizeof(*this) + external_memory_in_bytes();
00058 }
00059
00060 template <typename T>
00061 inline
00062 DB_Matrix<T>::const_iterator::const_iterator()
00063 : i(Iter()) {
00064 }
00065
00066 template <typename T>
00067 inline
00068 DB_Matrix<T>::const_iterator::const_iterator(const Iter& b)
00069 : i(b) {
00070 }
00071
00072 template <typename T>
00073 inline
00074 DB_Matrix<T>::const_iterator::const_iterator(const const_iterator& y)
00075 : i(y.i) {
00076 }
00077
00078 template <typename T>
00079 inline typename DB_Matrix<T>::const_iterator&
00080 DB_Matrix<T>::const_iterator::operator=(const const_iterator& y) {
00081 i = y.i;
00082 return *this;
00083 }
00084
00085 template <typename T>
00086 inline typename DB_Matrix<T>::const_iterator::reference
00087 DB_Matrix<T>::const_iterator::operator*() const {
00088 return *i;
00089 }
00090
00091 template <typename T>
00092 inline typename DB_Matrix<T>::const_iterator::pointer
00093 DB_Matrix<T>::const_iterator::operator->() const {
00094 return &*i;
00095 }
00096
00097 template <typename T>
00098 inline typename DB_Matrix<T>::const_iterator&
00099 DB_Matrix<T>::const_iterator::operator++() {
00100 ++i;
00101 return *this;
00102 }
00103
00104 template <typename T>
00105 inline typename DB_Matrix<T>::const_iterator
00106 DB_Matrix<T>::const_iterator::operator++(int) {
00107 return const_iterator(i++);
00108 }
00109
00110 template <typename T>
00111 inline bool
00112 DB_Matrix<T>::const_iterator::operator==(const const_iterator& y) const {
00113 return i == y.i;
00114 }
00115
00116 template <typename T>
00117 inline bool
00118 DB_Matrix<T>::const_iterator::operator!=(const const_iterator& y) const {
00119 return !operator==(y);
00120 }
00121
00122 template <typename T>
00123 inline typename DB_Matrix<T>::const_iterator
00124 DB_Matrix<T>::begin() const {
00125 return const_iterator(rows.begin());
00126 }
00127
00128 template <typename T>
00129 inline typename DB_Matrix<T>::const_iterator
00130 DB_Matrix<T>::end() const {
00131 return const_iterator(rows.end());
00132 }
00133
00134 template <typename T>
00135 inline
00136 DB_Matrix<T>::DB_Matrix()
00137 : rows(),
00138 row_size(0),
00139 row_capacity(0) {
00140 }
00141
00142 template <typename T>
00143 inline
00144 DB_Matrix<T>::~DB_Matrix() {
00145 }
00146
00147 template <typename T>
00148 inline DB_Row<T>&
00149 DB_Matrix<T>::operator[](const dimension_type k) {
00150 assert(k < rows.size());
00151 return rows[k];
00152 }
00153
00154 template <typename T>
00155 inline const DB_Row<T>&
00156 DB_Matrix<T>::operator[](const dimension_type k) const {
00157 assert(k < rows.size());
00158 return rows[k];
00159 }
00160
00161 template <typename T>
00162 inline dimension_type
00163 DB_Matrix<T>::num_rows() const {
00164 return rows.size();
00165 }
00166
00167 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00168
00169 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00170 template <typename T>
00171 inline bool
00172 operator!=(const DB_Matrix<T>& x, const DB_Matrix<T>& y) {
00173 return !(x == y);
00174 }
00175
00176 template <typename T>
00177 inline
00178 DB_Matrix<T>::DB_Matrix(const DB_Matrix& y)
00179 : rows(y.rows),
00180 row_size(y.row_size),
00181 row_capacity(compute_capacity(y.row_size, max_num_columns())) {
00182 }
00183
00184 template <typename T>
00185 inline DB_Matrix<T>&
00186 DB_Matrix<T>::operator=(const DB_Matrix& y) {
00187
00188
00189
00190
00191 if (this != &y) {
00192
00193 rows = y.rows;
00194 row_size = y.row_size;
00195
00196
00197 row_capacity = compute_capacity(y.row_size, max_num_columns());
00198 }
00199 return *this;
00200 }
00201
00202 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00203
00204 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00205 template <typename Specialization, typename Temp, typename To, typename T>
00206 inline bool
00207 l_m_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00208 const DB_Matrix<T>& x,
00209 const DB_Matrix<T>& y,
00210 const Rounding_Dir dir,
00211 Temp& tmp0,
00212 Temp& tmp1,
00213 Temp& tmp2) {
00214 const dimension_type x_num_rows = x.num_rows();
00215 if (x_num_rows != y.num_rows())
00216 return false;
00217 assign_r(tmp0, 0, ROUND_NOT_NEEDED);
00218 for (dimension_type i = x_num_rows; i-- > 0; ) {
00219 const DB_Row<T>& x_i = x[i];
00220 const DB_Row<T>& y_i = y[i];
00221 for (dimension_type j = x_num_rows; j-- > 0; ) {
00222 const T& x_i_j = x_i[j];
00223 const T& y_i_j = y_i[j];
00224 if (is_plus_infinity(x_i_j)) {
00225 if (is_plus_infinity(y_i_j))
00226 continue;
00227 else {
00228 pinf:
00229 assign_r(r, PLUS_INFINITY, ROUND_NOT_NEEDED);
00230 return true;
00231 }
00232 }
00233 else if (is_plus_infinity(y_i_j))
00234 goto pinf;
00235
00236 const Temp* tmp1p;
00237 const Temp* tmp2p;
00238 if (x_i_j > y_i_j) {
00239 maybe_assign(tmp1p, tmp1, x_i_j, dir);
00240 maybe_assign(tmp2p, tmp2, y_i_j, inverse(dir));
00241 }
00242 else {
00243 maybe_assign(tmp1p, tmp1, y_i_j, dir);
00244 maybe_assign(tmp2p, tmp2, x_i_j, inverse(dir));
00245 }
00246 sub_assign_r(tmp1, *tmp1p, *tmp2p, dir);
00247 assert(sgn(tmp1) >= 0);
00248 Specialization::combine(tmp0, tmp1, dir);
00249 }
00250 }
00251 Specialization::finalize(tmp0, dir);
00252 assign_r(r, tmp0, dir);
00253 return true;
00254 }
00255
00256 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00257
00258 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00259 template <typename Temp, typename To, typename T>
00260 inline bool
00261 rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00262 const DB_Matrix<T>& x,
00263 const DB_Matrix<T>& y,
00264 const Rounding_Dir dir,
00265 Temp& tmp0,
00266 Temp& tmp1,
00267 Temp& tmp2) {
00268 return
00269 l_m_distance_assign<Rectilinear_Distance_Specialization<Temp> >(r, x, y,
00270 dir,
00271 tmp0,
00272 tmp1,
00273 tmp2);
00274 }
00275
00276
00277 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00278
00279 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00280 template <typename Temp, typename To, typename T>
00281 inline bool
00282 euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00283 const DB_Matrix<T>& x,
00284 const DB_Matrix<T>& y,
00285 const Rounding_Dir dir,
00286 Temp& tmp0,
00287 Temp& tmp1,
00288 Temp& tmp2) {
00289 return
00290 l_m_distance_assign<Euclidean_Distance_Specialization<Temp> >(r, x, y,
00291 dir,
00292 tmp0,
00293 tmp1,
00294 tmp2);
00295 }
00296
00297 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00298
00299 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00300 template <typename Temp, typename To, typename T>
00301 inline bool
00302 l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00303 const DB_Matrix<T>& x,
00304 const DB_Matrix<T>& y,
00305 const Rounding_Dir dir,
00306 Temp& tmp0,
00307 Temp& tmp1,
00308 Temp& tmp2) {
00309 return
00310 l_m_distance_assign<L_Infinity_Distance_Specialization<Temp> >(r, x, y,
00311 dir,
00312 tmp0,
00313 tmp1,
00314 tmp2);
00315 }
00316
00317 }
00318
00319 namespace std {
00320
00321 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00322
00323 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00324 template <typename T>
00325 inline void
00326 swap(Parma_Polyhedra_Library::DB_Matrix<T>& x,
00327 Parma_Polyhedra_Library::DB_Matrix<T>& y) {
00328 x.swap(y);
00329 }
00330
00331 }
00332
00333 #endif // !defined(PPL_DB_Matrix_inlines_hh)