Parma_Polyhedra_Library::DB_Matrix< T > Class Template Reference
[C++ Language Interface]

The base class for the square matrices. More...

#include <DB_Matrix.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::DB_Matrix< T >:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 DB_Matrix ()
 Builds an empty matrix.
 DB_Matrix (dimension_type n_rows)
 Builds a square matrix having the specified dimension.
 DB_Matrix (const DB_Matrix &y)
 Copy-constructor.
template<typename U>
 DB_Matrix (const DB_Matrix< U > &y)
 Constructs a conservative approximation of y.
 ~DB_Matrix ()
 Destructor.
DB_Matrixoperator= (const DB_Matrix &y)
 Assignment operator.
const_iterator begin () const
 Returns the const_iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator.
const_iterator end () const
 Returns the past-the-end const_iterator.
void swap (DB_Matrix &y)
 Swaps *this with y.
void grow (dimension_type new_n_rows)
 Makes the matrix grow by adding more rows and more columns.
void resize_no_copy (dimension_type new_n_rows)
 Resizes the matrix without worrying about the old contents.
dimension_type num_rows () const
 Returns the number of rows in the matrix.
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this.
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this.
void print () const
 Prints *this to std::cerr using operator<<.
bool ascii_load (std::istream &s)
 Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.
memory_size_type total_memory_in_bytes () const
 Returns the total size in bytes of the memory occupied by *this.
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this.
bool OK () const
 Checks if all the invariants are satisfied.
Subscript operators.
DB_Row< T > & operator[] (dimension_type k)
 Returns a reference to the k-th row of the matrix.
const DB_Row< T > & operator[] (dimension_type k) const
 Returns a constant reference to the k-th row of the matrix.

Static Public Member Functions

static dimension_type max_num_rows ()
 Returns the maximum number of rows a DB_Matrix can handle.
static dimension_type max_num_columns ()
 Returns the maximum number of columns a DB_Matrix can handle.

Private Attributes

std::vector< DB_Row< T > > rows
 The rows of the matrix.
dimension_type row_size
 Size of the initialized part of each row.
dimension_type row_capacity
 Capacity allocated for each row, i.e., number of long objects that each row can contain.

Friends

class DB_Matrix

Related Functions

(Note that these are not member functions.)

template<typename T>
std::ostream & operator<< (std::ostream &s, const DB_Matrix< T > &c)
 Output operator.
template<typename T>
void swap (Parma_Polyhedra_Library::DB_Matrix< T > &x, Parma_Polyhedra_Library::DB_Matrix< T > &y)
 Specializes std::swap.
template<typename T>
bool operator== (const DB_Matrix< T > &x, const DB_Matrix< T > &y)
 Returns true if and only if x and y are identical.
template<typename T>
bool operator!= (const DB_Matrix< T > &x, const DB_Matrix< T > &y)
 Returns true if and only if x and y are different.
template<typename Temp, typename To, typename T>
bool rectilinear_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const DB_Matrix< T > &x, const DB_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 Computes the rectilinear (or Manhattan) distance between x and y.
template<typename Temp, typename To, typename T>
bool euclidean_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const DB_Matrix< T > &x, const DB_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 Computes the euclidean distance between x and y.
template<typename Temp, typename To, typename T>
bool l_infinity_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const DB_Matrix< T > &x, const DB_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 Computes the $L_\infty$ distance between x and y.
template<typename Specialization, typename Temp, typename To, typename T>
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)

Classes

class  const_iterator
 A read-only iterator over the rows of the matrix. More...


Detailed Description

template<typename T>
class Parma_Polyhedra_Library::DB_Matrix< T >

The base class for the square matrices.

The template class DB_Matrix<T> allows for the representation of a square matrix of T objects. Each DB_Matrix<T> object can be viewed as a multiset of DB_Row<T>.

Definition at line 61 of file DB_Matrix.defs.hh.


Constructor & Destructor Documentation

template<typename T>
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix (  ) 

Builds an empty matrix.

DB_Rows' size and capacity are initialized to $0$.

template<typename T>
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix ( dimension_type  n_rows  )  [inline, explicit]

Builds a square matrix having the specified dimension.

Definition at line 29 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::construct(), Parma_Polyhedra_Library::DB_Matrix< T >::OK(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, and Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00030   : rows(n_rows),
00031     row_size(n_rows),
00032     row_capacity(compute_capacity(n_rows, max_num_columns())) {
00033   // Construct in direct order: will destroy in reverse order.
00034   for (dimension_type i = 0; i < n_rows; ++i)
00035     rows[i].construct(n_rows, row_capacity);
00036   assert(OK());
00037 }

template<typename T>
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix ( const DB_Matrix< T > &  y  )  [inline]

Copy-constructor.

Definition at line 178 of file DB_Matrix.inlines.hh.

00179   : rows(y.rows),
00180     row_size(y.row_size),
00181     row_capacity(compute_capacity(y.row_size, max_num_columns())) {
00182 }

template<typename T>
template<typename U>
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix ( const DB_Matrix< U > &  y  )  [inline, explicit]

Constructs a conservative approximation of y.

Definition at line 41 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::OK(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, and Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00042   : rows(y.rows.size()),
00043     row_size(y.row_size),
00044     row_capacity(compute_capacity(y.row_size, max_num_columns())) {
00045   // Construct in direct order: will destroy in reverse order.
00046   for (dimension_type i = 0, n_rows = rows.size(); i < n_rows; ++i)
00047     rows[i].construct_upward_approximation(y[i], row_capacity);
00048   assert(OK());
00049 }

template<typename T>
Parma_Polyhedra_Library::DB_Matrix< T >::~DB_Matrix (  )  [inline]

Destructor.

Definition at line 144 of file DB_Matrix.inlines.hh.

00144                          {
00145 }


Member Function Documentation

template<typename T>
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::max_num_rows (  )  [inline, static]

Returns the maximum number of rows a DB_Matrix can handle.

Definition at line 44 of file DB_Matrix.inlines.hh.

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::grow(), and Parma_Polyhedra_Library::DB_Matrix< T >::resize_no_copy().

00044                            {
00045   return std::vector<DB_Row<T> >().max_size();
00046 }

template<typename T>
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::max_num_columns (  )  [inline, static]

Returns the maximum number of columns a DB_Matrix can handle.

Definition at line 50 of file DB_Matrix.inlines.hh.

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::grow(), Parma_Polyhedra_Library::DB_Matrix< T >::operator=(), and Parma_Polyhedra_Library::DB_Matrix< T >::resize_no_copy().

00050                               {
00051   return DB_Row<T>::max_size();
00052 }

template<typename T>
DB_Matrix< T > & Parma_Polyhedra_Library::DB_Matrix< T >::operator= ( const DB_Matrix< T > &  y  )  [inline]

Assignment operator.

Definition at line 186 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::DB_Matrix< T >::max_num_columns(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, Parma_Polyhedra_Library::DB_Matrix< T >::row_size, and Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00186                                           {
00187   // Without the following guard against auto-assignments we would
00188   // recompute the row capacity based on row size, possibly without
00189   // actually increasing the capacity of the rows.  This would lead to
00190   // an inconsistent state.
00191   if (this != &y) {
00192     // The following assignment may do nothing on auto-assignments...
00193     rows = y.rows;
00194     row_size = y.row_size;
00195     // ... hence the following assignment must not be done on
00196     // auto-assignments.
00197     row_capacity = compute_capacity(y.row_size, max_num_columns());
00198   }
00199   return *this;
00200 }

template<typename T>
DB_Matrix< T >::const_iterator Parma_Polyhedra_Library::DB_Matrix< T >::begin (  )  const [inline]

Returns the const_iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator.

Definition at line 124 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00124                           {
00125   return const_iterator(rows.begin());
00126 }

template<typename T>
DB_Matrix< T >::const_iterator Parma_Polyhedra_Library::DB_Matrix< T >::end (  )  const [inline]

Returns the past-the-end const_iterator.

Definition at line 130 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00130                         {
00131   return const_iterator(rows.end());
00132 }

template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::swap ( DB_Matrix< T > &  y  )  [inline]

template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::grow ( dimension_type  new_n_rows  )  [inline]

Makes the matrix grow by adding more rows and more columns.

Parameters:
new_n_rows The number of rows and columns of the resized matrix.
A new matrix, with the specified dimension, is created. The contents of the old matrix are copied in the upper, left-hand corner of the new matrix, which is then assigned to *this.

Definition at line 53 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::construct(), Parma_Polyhedra_Library::DB_Matrix< T >::max_num_columns(), Parma_Polyhedra_Library::DB_Matrix< T >::max_num_rows(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, Parma_Polyhedra_Library::DB_Matrix< T >::row_size, Parma_Polyhedra_Library::DB_Matrix< T >::rows, Parma_Polyhedra_Library::DB_Matrix< T >::swap(), and Parma_Polyhedra_Library::swap().

00053                                                   {
00054   const dimension_type old_n_rows = rows.size();
00055   assert(new_n_rows >= old_n_rows);
00056 
00057   if (new_n_rows > old_n_rows) {
00058     if (new_n_rows <= row_capacity) {
00059       // We can recycle the old rows.
00060       if (rows.capacity() < new_n_rows) {
00061         // Reallocation will take place.
00062         std::vector<DB_Row<T> > new_rows;
00063         new_rows.reserve(compute_capacity(new_n_rows, max_num_rows()));
00064         new_rows.insert(new_rows.end(), new_n_rows, DB_Row<T>());
00065         // Construct the new rows.
00066         dimension_type i = new_n_rows;
00067         while (i-- > old_n_rows)
00068           new_rows[i].construct(new_n_rows, row_capacity);
00069         // Steal the old rows.
00070         ++i;
00071         while (i-- > 0)
00072           new_rows[i].swap(rows[i]);
00073         // Put the new vector into place.
00074         std::swap(rows, new_rows);
00075       }
00076       else {
00077         // Reallocation will NOT take place.
00078         rows.insert(rows.end(), new_n_rows - old_n_rows, DB_Row<T>());
00079         for (dimension_type i = new_n_rows; i-- > old_n_rows; )
00080           rows[i].construct(new_n_rows, row_capacity);
00081       }
00082     }
00083     else {
00084       // We cannot even recycle the old rows.
00085       DB_Matrix new_matrix;
00086       new_matrix.rows.reserve(compute_capacity(new_n_rows, max_num_rows()));
00087       new_matrix.rows.insert(new_matrix.rows.end(), new_n_rows, DB_Row<T>());
00088       // Construct the new rows.
00089       new_matrix.row_size = new_n_rows;
00090       new_matrix.row_capacity = compute_capacity(new_n_rows,
00091                                                  max_num_columns());
00092       dimension_type i = new_n_rows;
00093       while (i-- > old_n_rows)
00094         new_matrix.rows[i].construct(new_matrix.row_size,
00095                                      new_matrix.row_capacity);
00096       // Copy the old rows.
00097       ++i;
00098       while (i-- > 0) {
00099         // FIXME: copying may be unnecessarily costly.
00100         DB_Row<T> new_row(rows[i],
00101                           new_matrix.row_size,
00102                           new_matrix.row_capacity);
00103         std::swap(new_matrix.rows[i], new_row);
00104       }
00105       // Put the new vector into place.
00106       swap(new_matrix);
00107       return;
00108     }
00109   }
00110   // Here we have the right number of rows.
00111   if (new_n_rows > row_size) {
00112     // We need more columns.
00113     if (new_n_rows <= row_capacity)
00114       // But we have enough capacity: we resize existing rows.
00115       for (dimension_type i = old_n_rows; i-- > 0; )
00116         rows[i].expand_within_capacity(new_n_rows);
00117     else {
00118       // Capacity exhausted: we must reallocate the rows and
00119       // make sure all the rows have the same capacity.
00120       const dimension_type new_row_capacity
00121         = compute_capacity(new_n_rows, max_num_columns());
00122       for (dimension_type i = old_n_rows; i-- > 0; ) {
00123         // FIXME: copying may be unnecessarily costly.
00124         DB_Row<T> new_row(rows[i], new_n_rows, new_row_capacity);
00125         std::swap(rows[i], new_row);
00126       }
00127       row_capacity = new_row_capacity;
00128     }
00129     // Rows have grown or shrunk.
00130     row_size = new_n_rows;
00131   }
00132 }

template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::resize_no_copy ( dimension_type  new_n_rows  )  [inline]

Resizes the matrix without worrying about the old contents.

Parameters:
new_n_rows The number of rows and columns of the resized matrix.
A new matrix, with the specified dimension, is created without copying the content of the old matrix and assigned to *this.

Definition at line 136 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::construct(), Parma_Polyhedra_Library::DB_Matrix< T >::max_num_columns(), Parma_Polyhedra_Library::DB_Matrix< T >::max_num_rows(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, Parma_Polyhedra_Library::DB_Matrix< T >::row_size, Parma_Polyhedra_Library::DB_Matrix< T >::rows, Parma_Polyhedra_Library::DB_Matrix< T >::swap(), and Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::ascii_load().

00136                                                             {
00137   dimension_type old_n_rows = rows.size();
00138 
00139   if (new_n_rows > old_n_rows) {
00140     // Rows will be inserted.
00141     if (new_n_rows <= row_capacity) {
00142       // We can recycle the old rows.
00143       if (rows.capacity() < new_n_rows) {
00144         // Reallocation (of vector `rows') will take place.
00145         std::vector<DB_Row<T> > new_rows;
00146         new_rows.reserve(compute_capacity(new_n_rows, max_num_rows()));
00147         new_rows.insert(new_rows.end(), new_n_rows, DB_Row<T>());
00148         // Construct the new rows (be careful: each new row must have
00149         // the same capacity as each one of the old rows).
00150         dimension_type i = new_n_rows;
00151         while (i-- > old_n_rows)
00152           new_rows[i].construct(new_n_rows, row_capacity);
00153         // Steal the old rows.
00154         ++i;
00155         while (i-- > 0)
00156           new_rows[i].swap(rows[i]);
00157         // Put the new vector into place.
00158         std::swap(rows, new_rows);
00159       }
00160       else {
00161         // Reallocation (of vector `rows') will NOT take place.
00162         rows.insert(rows.end(), new_n_rows - old_n_rows, DB_Row<T>());
00163         // Be careful: each new row must have
00164         // the same capacity as each one of the old rows.
00165         for (dimension_type i = new_n_rows; i-- > old_n_rows; )
00166           rows[i].construct(new_n_rows, row_capacity);
00167       }
00168     }
00169     else {
00170       // We cannot even recycle the old rows: allocate a new matrix and swap.
00171       DB_Matrix new_matrix(new_n_rows);
00172       swap(new_matrix);
00173       return;
00174     }
00175   }
00176   else if (new_n_rows < old_n_rows) {
00177     // Drop some rows.
00178     rows.erase(rows.begin() + new_n_rows, rows.end());
00179     // Shrink the existing rows.
00180     for (dimension_type i = new_n_rows; i-- > 0; )
00181       rows[i].shrink(new_n_rows);
00182     old_n_rows = new_n_rows;
00183   }
00184   // Here we have the right number of rows.
00185   if (new_n_rows > row_size) {
00186     // We need more columns.
00187     if (new_n_rows <= row_capacity)
00188       // But we have enough capacity: we resize existing rows.
00189       for (dimension_type i = old_n_rows; i-- > 0; )
00190         rows[i].expand_within_capacity(new_n_rows);
00191     else {
00192       // Capacity exhausted: we must reallocate the rows and
00193       // make sure all the rows have the same capacity.
00194       const dimension_type new_row_capacity
00195         = compute_capacity(new_n_rows, max_num_columns());
00196       for (dimension_type i = old_n_rows; i-- > 0; ) {
00197         DB_Row<T> new_row(new_n_rows, new_row_capacity);
00198         std::swap(rows[i], new_row);
00199       }
00200       row_capacity = new_row_capacity;
00201     }
00202   }
00203   // DB_Rows have grown or shrunk.
00204   row_size = new_n_rows;
00205 }

template<typename T>
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::num_rows (  )  const [inline]

template<typename T>
DB_Row< T > & Parma_Polyhedra_Library::DB_Matrix< T >::operator[] ( dimension_type  k  )  [inline]

Returns a reference to the k-th row of the matrix.

Definition at line 149 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00149                                                {
00150   assert(k < rows.size());
00151   return rows[k];
00152 }

template<typename T>
const DB_Row< T > & Parma_Polyhedra_Library::DB_Matrix< T >::operator[] ( dimension_type  k  )  const [inline]

Returns a constant reference to the k-th row of the matrix.

Definition at line 156 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::rows.

00156                                                      {
00157   assert(k < rows.size());
00158   return rows[k];
00159 }

template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::ascii_dump (  )  const

Writes to std::cerr an ASCII representation of *this.

template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::ascii_dump ( std::ostream &  s  )  const [inline]

Writes to s an ASCII representation of *this.

Definition at line 209 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::num_rows().

00209                                             {
00210   const DB_Matrix<T>& x = *this;
00211   const char separator = ' ';
00212   const dimension_type nrows = x.num_rows();
00213   s << nrows << separator << "\n";
00214   for (dimension_type i = 0; i < nrows;  ++i) {
00215     for (dimension_type j = 0; j < nrows; ++j) {
00216       using namespace IO_Operators;
00217       s << x[i][j] << separator;
00218     }
00219     s << "\n";
00220   }
00221 }

template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::print (  )  const

Prints *this to std::cerr using operator<<.

template<typename T>
bool Parma_Polyhedra_Library::DB_Matrix< T >::ascii_load ( std::istream &  s  )  [inline]

Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.

Definition at line 227 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::OK(), and Parma_Polyhedra_Library::DB_Matrix< T >::resize_no_copy().

00227                                       {
00228   dimension_type nrows;
00229    if (!(s >> nrows))
00230     return false;
00231   resize_no_copy(nrows);
00232   DB_Matrix& x = *this;
00233   for (dimension_type i = 0; i < nrows;  ++i)
00234     for (dimension_type j = 0; j < nrows; ++j) {
00235       Result r = input(x[i][j], s, ROUND_UP);
00236       // FIXME: V_CVT_STR_UNK is probably not the only possible error.
00237       if (!s || r == V_CVT_STR_UNK)
00238         return false;
00239     }
00240 
00241   // Check invariants.
00242   assert(OK());
00243   return true;
00244 }

template<typename T>
memory_size_type Parma_Polyhedra_Library::DB_Matrix< T >::total_memory_in_bytes (  )  const [inline]

Returns the total size in bytes of the memory occupied by *this.

Definition at line 56 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::external_memory_in_bytes().

00056                                           {
00057   return sizeof(*this) + external_memory_in_bytes();
00058 }

template<typename T>
memory_size_type Parma_Polyhedra_Library::DB_Matrix< T >::external_memory_in_bytes (  )  const [inline]

Returns the size in bytes of the memory managed by *this.

Definition at line 263 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::num_rows(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, and Parma_Polyhedra_Library::DB_Matrix< T >::rows.

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::total_memory_in_bytes().

00263                                              {
00264   memory_size_type n = rows.capacity() * sizeof(DB_Row<T>);
00265   for (dimension_type i = num_rows(); i-- > 0; )
00266     n += rows[i].external_memory_in_bytes(row_capacity);
00267   return n;
00268 }

template<typename T>
bool Parma_Polyhedra_Library::DB_Matrix< T >::OK (  )  const [inline]

Checks if all the invariants are satisfied.

Definition at line 272 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::num_rows(), Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity, and Parma_Polyhedra_Library::DB_Matrix< T >::row_size.

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::ascii_load(), and Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix().

00272                        {
00273 #ifndef NDEBUG
00274   using std::endl;
00275   using std::cerr;
00276 #endif
00277 
00278   // The matrix must be square.
00279   if (num_rows() != row_size) {
00280 #ifndef NDEBUG
00281     cerr << "DB_Matrix has fewer columns than rows:\n"
00282          << "row_size is " << row_size
00283          << ", num_rows() is " << num_rows() << "!"
00284          << endl;
00285 #endif
00286     return false;
00287   }
00288 
00289   const DB_Matrix& x = *this;
00290   const dimension_type n_rows = x.num_rows();
00291   for (dimension_type i = 0; i < n_rows; ++i) {
00292     if (!x[i].OK(row_size, row_capacity))
00293       return false;
00294   }
00295 
00296   // All checks passed.
00297   return true;
00298 }


Friends And Related Function Documentation

template<typename T>
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix [friend]

Definition at line 160 of file DB_Matrix.defs.hh.

template<typename T>
std::ostream & operator<< ( std::ostream &  s,
const DB_Matrix< T > &  c 
) [related]

Output operator.

Definition at line 305 of file DB_Matrix.templates.hh.

00305                                                              {
00306   const dimension_type n = c.num_rows();
00307   for (dimension_type i = 0; i < n; ++i) {
00308     for (dimension_type j = 0; j < n; ++j)
00309       s << c[i][j] << " ";
00310     s << "\n";
00311   }
00312   return s;
00313 }

template<typename T>
void swap ( Parma_Polyhedra_Library::DB_Matrix< T > &  x,
Parma_Polyhedra_Library::DB_Matrix< T > &  y 
) [related]

Specializes std::swap.

Definition at line 326 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::swap().

00327                                              {
00328   x.swap(y);
00329 }

template<typename T>
bool operator== ( const DB_Matrix< T > &  x,
const DB_Matrix< T > &  y 
) [related]

Returns true if and only if x and y are identical.

Definition at line 251 of file DB_Matrix.templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::num_rows().

00251                                                          {
00252   const dimension_type x_num_rows = x.num_rows();
00253   if (x_num_rows != y.num_rows())
00254     return false;
00255   for (dimension_type i = x_num_rows; i-- > 0; )
00256     if (x[i] != y[i])
00257       return false;
00258   return true;
00259 }

template<typename T>
bool operator!= ( const DB_Matrix< T > &  x,
const DB_Matrix< T > &  y 
) [related]

Returns true if and only if x and y are different.

Definition at line 172 of file DB_Matrix.inlines.hh.

00172                                                          {
00173   return !(x == y);
00174 }

template<typename Temp, typename To, typename T>
bool rectilinear_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const DB_Matrix< T > &  x,
const DB_Matrix< T > &  y,
Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Computes the rectilinear (or Manhattan) distance between x and y.

If the rectilinear distance between x and y is defined, stores an approximation of it into to r and returns true; returns false otherwise.

The direction of the approximation is specified by dir.

All computations are performed using the temporary variables tmp0, tmp1 and tmp2.

Definition at line 261 of file DB_Matrix.inlines.hh.

00267                                         {
00268   return
00269     l_m_distance_assign<Rectilinear_Distance_Specialization<Temp> >(r, x, y,
00270                                                                     dir,
00271                                                                     tmp0,
00272                                                                     tmp1,
00273                                                                     tmp2);
00274 }

template<typename Temp, typename To, typename T>
bool euclidean_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const DB_Matrix< T > &  x,
const DB_Matrix< T > &  y,
Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Computes the euclidean distance between x and y.

If the Euclidean distance between x and y is defined, stores an approximation of it into to r and returns true; returns false otherwise.

The direction of the approximation is specified by dir.

All computations are performed using the temporary variables tmp0, tmp1 and tmp2.

Definition at line 282 of file DB_Matrix.inlines.hh.

00288                                       {
00289   return
00290     l_m_distance_assign<Euclidean_Distance_Specialization<Temp> >(r, x, y,
00291                                                                   dir,
00292                                                                   tmp0,
00293                                                                   tmp1,
00294                                                                   tmp2);
00295 }

template<typename Temp, typename To, typename T>
bool l_infinity_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const DB_Matrix< T > &  x,
const DB_Matrix< T > &  y,
Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Computes the $L_\infty$ distance between x and y.

If the $L_\infty$ distance between x and y is defined, stores an approximation of it into to r and returns true; returns false otherwise.

The direction of the approximation is specified by dir.

All computations are performed using the temporary variables tmp0, tmp1 and tmp2.

Definition at line 302 of file DB_Matrix.inlines.hh.

00308                                        {
00309   return
00310     l_m_distance_assign<L_Infinity_Distance_Specialization<Temp> >(r, x, y,
00311                                                                    dir,
00312                                                                    tmp0,
00313                                                                    tmp1,
00314                                                                    tmp2);
00315 }

template<typename Specialization, typename Temp, typename To, typename T>
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 
) [related]

Definition at line 207 of file DB_Matrix.inlines.hh.

References Parma_Polyhedra_Library::assign_r(), Parma_Polyhedra_Library::combine(), Parma_Polyhedra_Library::finalize(), Parma_Polyhedra_Library::is_plus_infinity(), Parma_Polyhedra_Library::maybe_assign(), Parma_Polyhedra_Library::DB_Matrix< T >::num_rows(), and PLUS_INFINITY.

00213                                 {
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 }


Member Data Documentation

template<typename T>
std::vector<DB_Row<T> > Parma_Polyhedra_Library::DB_Matrix< T >::rows [private]

template<typename T>
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::row_size [private]

template<typename T>
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::row_capacity [private]


The documentation for this class was generated from the following files:

Generated on Sat Oct 11 10:41:16 2008 for PPL by  doxygen 1.5.6