PPL  1.2
Parma_Polyhedra_Library::DB_Matrix< T > Class Template Reference

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

#include <DB_Matrix_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::DB_Matrix< T >:

Classes

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

Public Member Functions

 DB_Matrix ()
 Builds an empty matrix. More...
 
 DB_Matrix (dimension_type n_rows)
 Builds a square matrix having the specified dimension. More...
 
 DB_Matrix (const DB_Matrix &y)
 Copy constructor. More...
 
template<typename U >
 DB_Matrix (const DB_Matrix< U > &y)
 Constructs a conservative approximation of y. More...
 
 ~DB_Matrix ()
 Destructor. More...
 
DB_Matrixoperator= (const DB_Matrix &y)
 Assignment operator. More...
 
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. More...
 
const_iterator end () const
 Returns the past-the-end const_iterator. More...
 
void m_swap (DB_Matrix &y)
 Swaps *this with y. More...
 
void grow (dimension_type new_n_rows)
 Makes the matrix grow by adding more rows and more columns. More...
 
void resize_no_copy (dimension_type new_n_rows)
 Resizes the matrix without worrying about the old contents. More...
 
dimension_type num_rows () const
 Returns the number of rows in the matrix. More...
 
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this. More...
 
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this. More...
 
void print () const
 Prints *this to std::cerr using operator<<. More...
 
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. More...
 
memory_size_type total_memory_in_bytes () const
 Returns the total size in bytes of the memory occupied by *this. More...
 
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this. More...
 
bool OK () const
 Checks if all the invariants are satisfied. More...
 
Subscript operators.
DB_Row< T > & operator[] (dimension_type k)
 Returns a reference to the k-th row of the matrix. More...
 
const DB_Row< T > & operator[] (dimension_type k) const
 Returns a constant reference to the k-th row of the matrix. More...
 

Static Public Member Functions

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

Private Attributes

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

Friends

template<typename U >
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. More...
 
template<typename T >
void swap (DB_Matrix< T > &x, DB_Matrix< T > &y)
 Swaps x with y. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
template<typename T >
bool operator!= (const DB_Matrix< T > &x, const DB_Matrix< T > &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)
 
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, const Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 
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, const Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 
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, const Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 
template<typename T >
void swap (DB_Matrix< T > &x, DB_Matrix< T > &y)
 
template<typename T >
bool operator== (const DB_Matrix< T > &x, const DB_Matrix< T > &y)
 
template<typename T >
std::ostream & operator<< (std::ostream &s, const DB_Matrix< T > &c)
 

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 62 of file DB_Matrix_defs.hh.

Constructor & Destructor Documentation

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

Builds an empty matrix.

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

Definition at line 138 of file DB_Matrix_inlines.hh.

139  : rows(),
140  row_size(0),
141  row_capacity(0) {
142 }
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.
template<typename T >
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix ( dimension_type  n_rows)
explicit

Builds a square matrix having the specified dimension.

Definition at line 30 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.

31  : rows(n_rows),
32  row_size(n_rows),
34  // Construct in direct order: will destroy in reverse order.
35  for (dimension_type i = 0; i < n_rows; ++i) {
36  rows[i].construct(n_rows, row_capacity);
37  }
38  PPL_ASSERT(OK());
39 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::vector< DB_Row< T > > rows
The rows of the matrix.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
bool OK() const
Checks if all the invariants are satisfied.
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.
static dimension_type max_num_columns()
Returns the maximum number of columns a DB_Matrix can handle.
template<typename T >
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix ( const DB_Matrix< T > &  y)
inline

Copy constructor.

Definition at line 180 of file DB_Matrix_inlines.hh.

181  : rows(y.rows),
182  row_size(y.row_size),
184 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
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.
static dimension_type max_num_columns()
Returns the maximum number of columns a DB_Matrix can handle.
template<typename T >
template<typename U >
Parma_Polyhedra_Library::DB_Matrix< T >::DB_Matrix ( const DB_Matrix< U > &  y)
explicit

Constructs a conservative approximation of y.

Definition at line 43 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.

44  : rows(y.rows.size()),
45  row_size(y.row_size),
47  // Construct in direct order: will destroy in reverse order.
48  for (dimension_type i = 0, n_rows = rows.size(); i < n_rows; ++i) {
49  rows[i].construct_upward_approximation(y[i], row_capacity);
50  }
51  PPL_ASSERT(OK());
52 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::vector< DB_Row< T > > rows
The rows of the matrix.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
bool OK() const
Checks if all the invariants are satisfied.
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.
static dimension_type max_num_columns()
Returns the maximum number of columns a DB_Matrix can handle.
template<typename T >
Parma_Polyhedra_Library::DB_Matrix< T >::~DB_Matrix ( )
inline

Destructor.

Definition at line 146 of file DB_Matrix_inlines.hh.

146  {
147 }

Member Function Documentation

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

Writes to s an ASCII representation of *this.

Definition at line 226 of file DB_Matrix_templates.hh.

References Parma_Polyhedra_Library::DB_Matrix< T >::num_rows(), and Parma_Polyhedra_Library::Implementation::BD_Shapes::separator.

226  {
227  const DB_Matrix<T>& x = *this;
228  const char separator = ' ';
229  const dimension_type nrows = x.num_rows();
230  s << nrows << separator << "\n";
231  for (dimension_type i = 0; i < nrows; ++i) {
232  for (dimension_type j = 0; j < nrows; ++j) {
233  using namespace IO_Operators;
234  s << x[i][j] << separator;
235  }
236  s << "\n";
237  }
238 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<typename T >
bool Parma_Polyhedra_Library::DB_Matrix< T >::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.

Definition at line 244 of file DB_Matrix_templates.hh.

References Parma_Polyhedra_Library::is_minus_infinity(), Parma_Polyhedra_Library::result_relation(), Parma_Polyhedra_Library::ROUND_CHECK, and Parma_Polyhedra_Library::VR_EQ.

244  {
245  dimension_type nrows;
246  if (!(s >> nrows)) {
247  return false;
248  }
249  resize_no_copy(nrows);
250  DB_Matrix& x = *this;
251  for (dimension_type i = 0; i < nrows; ++i) {
252  for (dimension_type j = 0; j < nrows; ++j) {
253  Result r = input(x[i][j], s, ROUND_CHECK);
254  if (result_relation(r) != VR_EQ || is_minus_infinity(x[i][j])) {
255  return false;
256  }
257  }
258  }
259 
260  // Check invariants.
261  PPL_ASSERT(OK());
262  return true;
263 }
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_minus_infinity(const T &x)
size_t dimension_type
An unsigned integral type for representing space dimensions.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Result_Relation result_relation(Result r)
DB_Matrix()
Builds an empty matrix.
void resize_no_copy(dimension_type new_n_rows)
Resizes the matrix without worrying about the old contents.
bool OK() const
Checks if all the invariants are satisfied.
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
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 126 of file DB_Matrix_inlines.hh.

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

126  {
127  return const_iterator(rows.begin());
128 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
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 132 of file DB_Matrix_inlines.hh.

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

132  {
133  return const_iterator(rows.end());
134 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
template<typename T >
memory_size_type Parma_Polyhedra_Library::DB_Matrix< T >::external_memory_in_bytes ( ) const

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

Definition at line 285 of file DB_Matrix_templates.hh.

285  {
286  memory_size_type n = rows.capacity() * sizeof(DB_Row<T>);
287  for (dimension_type i = num_rows(); i-- > 0; ) {
288  n += rows[i].external_memory_in_bytes(row_capacity);
289  }
290  return n;
291 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::vector< DB_Row< T > > rows
The rows of the matrix.
dimension_type num_rows() const
Returns the number of rows in the matrix.
dimension_type row_capacity
Capacity allocated for each row, i.e., number of long objects that each row can contain.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
template<typename T >
void Parma_Polyhedra_Library::DB_Matrix< T >::grow ( dimension_type  new_n_rows)

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

Parameters
new_n_rowsThe 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 56 of file DB_Matrix_templates.hh.

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

56  {
57  const dimension_type old_n_rows = rows.size();
58  PPL_ASSERT(new_n_rows >= old_n_rows);
59 
60  if (new_n_rows > old_n_rows) {
61  if (new_n_rows <= row_capacity) {
62  // We can recycle the old rows.
63  if (rows.capacity() < new_n_rows) {
64  // Reallocation will take place.
65  std::vector<DB_Row<T> > new_rows;
66  new_rows.reserve(compute_capacity(new_n_rows, max_num_rows()));
67  new_rows.insert(new_rows.end(), new_n_rows, DB_Row<T>());
68  // Construct the new rows.
69  dimension_type i = new_n_rows;
70  while (i-- > old_n_rows) {
71  new_rows[i].construct(new_n_rows, row_capacity);
72  }
73  // Steal the old rows.
74  ++i;
75  while (i-- > 0) {
76  swap(new_rows[i], rows[i]);
77  }
78  // Put the new vector into place.
79  using std::swap;
80  swap(rows, new_rows);
81  }
82  else {
83  // Reallocation will NOT take place.
84  rows.insert(rows.end(), new_n_rows - old_n_rows, DB_Row<T>());
85  for (dimension_type i = new_n_rows; i-- > old_n_rows; ) {
86  rows[i].construct(new_n_rows, row_capacity);
87  }
88  }
89  }
90  else {
91  // We cannot even recycle the old rows.
92  DB_Matrix new_matrix;
93  new_matrix.rows.reserve(compute_capacity(new_n_rows, max_num_rows()));
94  new_matrix.rows.insert(new_matrix.rows.end(), new_n_rows, DB_Row<T>());
95  // Construct the new rows.
96  new_matrix.row_size = new_n_rows;
97  new_matrix.row_capacity = compute_capacity(new_n_rows,
98  max_num_columns());
99  dimension_type i = new_n_rows;
100  while (i-- > old_n_rows) {
101  new_matrix.rows[i].construct(new_matrix.row_size,
102  new_matrix.row_capacity);
103  }
104  // Copy the old rows.
105  ++i;
106  while (i-- > 0) {
107  // FIXME: copying may be unnecessarily costly.
108  DB_Row<T> new_row(rows[i],
109  new_matrix.row_size,
110  new_matrix.row_capacity);
111  swap(new_matrix.rows[i], new_row);
112  }
113  // Put the new vector into place.
114  m_swap(new_matrix);
115  return;
116  }
117  }
118  // Here we have the right number of rows.
119  if (new_n_rows > row_size) {
120  // We need more columns.
121  if (new_n_rows <= row_capacity) {
122  // But we have enough capacity: we resize existing rows.
123  for (dimension_type i = old_n_rows; i-- > 0; ) {
124  rows[i].expand_within_capacity(new_n_rows);
125  }
126  }
127  else {
128  // Capacity exhausted: we must reallocate the rows and
129  // make sure all the rows have the same capacity.
130  const dimension_type new_row_capacity
131  = compute_capacity(new_n_rows, max_num_columns());
132  for (dimension_type i = old_n_rows; i-- > 0; ) {
133  // FIXME: copying may be unnecessarily costly.
134  DB_Row<T> new_row(rows[i], new_n_rows, new_row_capacity);
135  swap(rows[i], new_row);
136  }
137  row_capacity = new_row_capacity;
138  }
139  // Rows have grown or shrunk.
140  row_size = new_n_rows;
141  }
142 }
void swap(CO_Tree &x, CO_Tree &y)
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::vector< DB_Row< T > > rows
The rows of the matrix.
DB_Matrix()
Builds an empty matrix.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
static dimension_type max_num_rows()
Returns the maximum number of rows a DB_Matrix can handle.
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.
void m_swap(DB_Matrix &y)
Swaps *this with y.
static dimension_type max_num_columns()
Returns the maximum number of columns a DB_Matrix can handle.
void swap(DB_Matrix< T > &x, DB_Matrix< T > &y)
Swaps x with y.
template<typename T >
void Parma_Polyhedra_Library::DB_Matrix< T >::m_swap ( DB_Matrix< T > &  y)
inline

Swaps *this with y.

Definition at line 37 of file DB_Matrix_inlines.hh.

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

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

37  {
38  using std::swap;
39  swap(rows, y.rows);
40  swap(row_size, y.row_size);
41  swap(row_capacity, y.row_capacity);
42 }
void swap(CO_Tree &x, CO_Tree &y)
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.
void swap(DB_Matrix< T > &x, DB_Matrix< T > &y)
Swaps x with y.
template<typename T >
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::max_num_columns ( )
inlinestatic

Returns the maximum number of columns a DB_Matrix can handle.

Definition at line 52 of file DB_Matrix_inlines.hh.

References Parma_Polyhedra_Library::DB_Row< T >::max_size().

52  {
53  return DB_Row<T>::max_size();
54 }
static dimension_type max_size()
Returns the size() of the largest possible DB_Row.
template<typename T >
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::max_num_rows ( )
inlinestatic

Returns the maximum number of rows a DB_Matrix can handle.

Definition at line 46 of file DB_Matrix_inlines.hh.

46  {
47  return std::vector<DB_Row<T> >().max_size();
48 }
template<typename T >
dimension_type Parma_Polyhedra_Library::DB_Matrix< T >::num_rows ( ) const
inline

Returns the number of rows in the matrix.

Definition at line 165 of file DB_Matrix_inlines.hh.

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::ascii_dump(), Parma_Polyhedra_Library::DB_Matrix< T >::l_m_distance_assign(), Parma_Polyhedra_Library::DB_Matrix< T >::OK(), and Parma_Polyhedra_Library::DB_Matrix< T >::operator==().

165  {
166  return rows.size();
167 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
template<typename T >
bool Parma_Polyhedra_Library::DB_Matrix< T >::OK ( ) const

Checks if all the invariants are satisfied.

Definition at line 295 of file DB_Matrix_templates.hh.

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

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

295  {
296 #ifndef NDEBUG
297  using std::endl;
298  using std::cerr;
299 #endif
300 
301  // The matrix must be square.
302  if (num_rows() != row_size) {
303 #ifndef NDEBUG
304  cerr << "DB_Matrix has fewer columns than rows:\n"
305  << "row_size is " << row_size
306  << ", num_rows() is " << num_rows() << "!"
307  << endl;
308 #endif
309  return false;
310  }
311 
312  const DB_Matrix& x = *this;
313  const dimension_type n_rows = x.num_rows();
314  for (dimension_type i = 0; i < n_rows; ++i) {
315  if (!x[i].OK(row_size, row_capacity)) {
316  return false;
317  }
318  }
319 
320  // All checks passed.
321  return true;
322 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
DB_Matrix()
Builds an empty matrix.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type row_size
Size of the initialized part of each row.
dimension_type num_rows() const
Returns the number of rows in the matrix.
dimension_type row_capacity
Capacity allocated for each row, i.e., number of long objects that each row can contain.
template<typename T >
DB_Matrix< T > & Parma_Polyhedra_Library::DB_Matrix< T >::operator= ( const DB_Matrix< T > &  y)
inline

Assignment operator.

Definition at line 188 of file DB_Matrix_inlines.hh.

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

188  {
189  // Without the following guard against auto-assignments we would
190  // recompute the row capacity based on row size, possibly without
191  // actually increasing the capacity of the rows. This would lead to
192  // an inconsistent state.
193  if (this != &y) {
194  // The following assignment may do nothing on auto-assignments...
195  rows = y.rows;
196  row_size = y.row_size;
197  // ... hence the following assignment must not be done on
198  // auto-assignments.
200  }
201  return *this;
202 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
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.
static dimension_type max_num_columns()
Returns the maximum number of columns a DB_Matrix can handle.
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 151 of file DB_Matrix_inlines.hh.

151  {
152  PPL_ASSERT(k < rows.size());
153  return rows[k];
154 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
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 158 of file DB_Matrix_inlines.hh.

158  {
159  PPL_ASSERT(k < rows.size());
160  return rows[k];
161 }
std::vector< DB_Row< T > > rows
The rows of the matrix.
template<typename T>
void Parma_Polyhedra_Library::DB_Matrix< T >::print ( ) const

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

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

Resizes the matrix without worrying about the old contents.

Parameters
new_n_rowsThe 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 146 of file DB_Matrix_templates.hh.

References Parma_Polyhedra_Library::compute_capacity(), and Parma_Polyhedra_Library::swap().

146  {
147  dimension_type old_n_rows = rows.size();
148 
149  if (new_n_rows > old_n_rows) {
150  // Rows will be inserted.
151  if (new_n_rows <= row_capacity) {
152  // We can recycle the old rows.
153  if (rows.capacity() < new_n_rows) {
154  // Reallocation (of vector `rows') will take place.
155  std::vector<DB_Row<T> > new_rows;
156  new_rows.reserve(compute_capacity(new_n_rows, max_num_rows()));
157  new_rows.insert(new_rows.end(), new_n_rows, DB_Row<T>());
158  // Construct the new rows (be careful: each new row must have
159  // the same capacity as each one of the old rows).
160  dimension_type i = new_n_rows;
161  while (i-- > old_n_rows) {
162  new_rows[i].construct(new_n_rows, row_capacity);
163  // Steal the old rows.
164  }
165  ++i;
166  while (i-- > 0) {
167  swap(new_rows[i], rows[i]);
168  }
169  // Put the new vector into place.
170  using std::swap;
171  swap(rows, new_rows);
172  }
173  else {
174  // Reallocation (of vector `rows') will NOT take place.
175  rows.insert(rows.end(), new_n_rows - old_n_rows, DB_Row<T>());
176  // Be careful: each new row must have
177  // the same capacity as each one of the old rows.
178  for (dimension_type i = new_n_rows; i-- > old_n_rows; ) {
179  rows[i].construct(new_n_rows, row_capacity);
180  }
181  }
182  }
183  else {
184  // We cannot even recycle the old rows: allocate a new matrix and swap.
185  DB_Matrix new_matrix(new_n_rows);
186  m_swap(new_matrix);
187  return;
188  }
189  }
190  else if (new_n_rows < old_n_rows) {
191  // Drop some rows.
192  rows.resize(new_n_rows);
193  // Shrink the existing rows.
194  for (dimension_type i = new_n_rows; i-- > 0; ) {
195  rows[i].shrink(new_n_rows);
196  }
197  old_n_rows = new_n_rows;
198  }
199  // Here we have the right number of rows.
200  if (new_n_rows > row_size) {
201  // We need more columns.
202  if (new_n_rows <= row_capacity) {
203  // But we have enough capacity: we resize existing rows.
204  for (dimension_type i = old_n_rows; i-- > 0; ) {
205  rows[i].expand_within_capacity(new_n_rows);
206  }
207  }
208  else {
209  // Capacity exhausted: we must reallocate the rows and
210  // make sure all the rows have the same capacity.
211  const dimension_type new_row_capacity
212  = compute_capacity(new_n_rows, max_num_columns());
213  for (dimension_type i = old_n_rows; i-- > 0; ) {
214  DB_Row<T> new_row(new_n_rows, new_row_capacity);
215  swap(rows[i], new_row);
216  }
217  row_capacity = new_row_capacity;
218  }
219  }
220  // DB_Rows have grown or shrunk.
221  row_size = new_n_rows;
222 }
void swap(CO_Tree &x, CO_Tree &y)
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::vector< DB_Row< T > > rows
The rows of the matrix.
DB_Matrix()
Builds an empty matrix.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
static dimension_type max_num_rows()
Returns the maximum number of rows a DB_Matrix can handle.
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.
void m_swap(DB_Matrix &y)
Swaps *this with y.
static dimension_type max_num_columns()
Returns the maximum number of columns a DB_Matrix can handle.
void swap(DB_Matrix< T > &x, DB_Matrix< T > &y)
Swaps x with y.
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 58 of file DB_Matrix_inlines.hh.

References Parma_Polyhedra_Library::external_memory_in_bytes().

58  {
59  return sizeof(*this) + external_memory_in_bytes();
60 }
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.

Friends And Related Function Documentation

template<typename T>
template<typename U >
friend class DB_Matrix
friend

Definition at line 161 of file DB_Matrix_defs.hh.

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,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 286 of file DB_Matrix_inlines.hh.

292  {
293  return
294  l_m_distance_assign<Euclidean_Distance_Specialization<Temp> >(r, x, y,
295  dir,
296  tmp0,
297  tmp1,
298  tmp2);
299 }
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.

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,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 306 of file DB_Matrix_inlines.hh.

312  {
313  return
314  l_m_distance_assign<L_Infinity_Distance_Specialization<Temp> >(r, x, y,
315  dir,
316  tmp0,
317  tmp1,
318  tmp2);
319 }
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.

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 209 of file DB_Matrix_inlines.hh.

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

215  {
216  const dimension_type x_num_rows = x.num_rows();
217  if (x_num_rows != y.num_rows()) {
218  return false;
219  }
220  assign_r(tmp0, 0, ROUND_NOT_NEEDED);
221  for (dimension_type i = x_num_rows; i-- > 0; ) {
222  const DB_Row<T>& x_i = x[i];
223  const DB_Row<T>& y_i = y[i];
224  for (dimension_type j = x_num_rows; j-- > 0; ) {
225  const T& x_i_j = x_i[j];
226  const T& y_i_j = y_i[j];
227  if (is_plus_infinity(x_i_j)) {
228  if (is_plus_infinity(y_i_j)) {
229  continue;
230  }
231  else {
232  pinf:
234  return true;
235  }
236  }
237  else if (is_plus_infinity(y_i_j)) {
238  goto pinf;
239  }
240  const Temp* tmp1p;
241  const Temp* tmp2p;
242  if (x_i_j > y_i_j) {
243  maybe_assign(tmp1p, tmp1, x_i_j, dir);
244  maybe_assign(tmp2p, tmp2, y_i_j, inverse(dir));
245  }
246  else {
247  maybe_assign(tmp1p, tmp1, y_i_j, dir);
248  maybe_assign(tmp2p, tmp2, x_i_j, inverse(dir));
249  }
250  sub_assign_r(tmp1, *tmp1p, *tmp2p, dir);
251  PPL_ASSERT(sgn(tmp1) >= 0);
252  Specialization::combine(tmp0, tmp1, dir);
253  }
254  }
255  Specialization::finalize(tmp0, dir);
256  assign_r(r, tmp0, dir);
257  return true;
258 }
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &, Rounding_Dir dir)
size_t dimension_type
An unsigned integral type for representing space dimensions.
Rounding_Dir inverse(Rounding_Dir dir)
void finalize()
Finalizes the library.
Definition: initializer.hh:60
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_plus_infinity(const T &x)
Plus_Infinity PLUS_INFINITY
Definition: checked.cc:31
I_Result combine(Result l, Result u)
int sgn(Boundary_Type type, const T &x, const Info &info)
Result maybe_assign(const To *&top, To &tmp, const From &from, Rounding_Dir dir)
Assigns to top a pointer to a location that holds the conversion, according to dir, of from to type To. When necessary, and only when necessary, the variable tmp is used to hold the result of conversion.
template<typename T >
bool operator!= ( const DB_Matrix< T > &  x,
const DB_Matrix< T > &  y 
)
related

Definition at line 174 of file DB_Matrix_inlines.hh.

174  {
175  return !(x == y);
176 }
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.

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

Output operator.

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

Definition at line 329 of file DB_Matrix_templates.hh.

References c.

329  {
330  const dimension_type n = c.num_rows();
331  for (dimension_type i = 0; i < n; ++i) {
332  for (dimension_type j = 0; j < n; ++j) {
333  s << c[i][j] << " ";
334  }
335  s << "\n";
336  }
337  return s;
338 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Coefficient c
Definition: PIP_Tree.cc:64
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.

Referenced by Parma_Polyhedra_Library::DB_Matrix< T >::const_iterator::operator!=().

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

Definition at line 270 of file DB_Matrix_templates.hh.

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

270  {
271  const dimension_type x_num_rows = x.num_rows();
272  if (x_num_rows != y.num_rows()) {
273  return false;
274  }
275  for (dimension_type i = x_num_rows; i-- > 0; ) {
276  if (x[i] != y[i]) {
277  return false;
278  }
279  }
280  return true;
281 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
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,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 265 of file DB_Matrix_inlines.hh.

271  {
272  return
273  l_m_distance_assign<Rectilinear_Distance_Specialization<Temp> >(r, x, y,
274  dir,
275  tmp0,
276  tmp1,
277  tmp2);
278 }
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.

template<typename T >
void swap ( DB_Matrix< T > &  x,
DB_Matrix< T > &  y 
)
related

Swaps x with y.

template<typename T >
void swap ( DB_Matrix< T > &  x,
DB_Matrix< T > &  y 
)
related

Definition at line 326 of file DB_Matrix_inlines.hh.

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

326  {
327  x.m_swap(y);
328 }

Member Data Documentation

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

Capacity allocated for each row, i.e., number of long objects that each row can contain.

Definition at line 173 of file DB_Matrix_defs.hh.

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


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