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

A matrix representing octagonal constraints. More...

#include <OR_Matrix_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::OR_Matrix< T >:

Classes

class  any_row_iterator
 A template class to derive both OR_Matrix::iterator and OR_Matrix::const_iterator. More...
 
class  Pseudo_Row
 An object that behaves like a matrix's row with respect to the subscript operators. More...
 

Public Types

typedef Pseudo_Row< T > row_reference_type
 A (non const) reference to a matrix's row. More...
 
typedef Pseudo_Row< const T > const_row_reference_type
 A const reference to a matrix's row. More...
 
typedef any_row_iterator< T > row_iterator
 A (non const) row iterator. More...
 
typedef any_row_iterator< const T > const_row_iterator
 A const row iterator. More...
 
typedef DB_Row< T >::iterator element_iterator
 A (non const) element iterator. More...
 
typedef DB_Row< T >::const_iterator const_element_iterator
 A const element iterator. More...
 

Public Member Functions

 OR_Matrix (dimension_type num_dimensions)
 Builds a matrix with specified dimensions. More...
 
 OR_Matrix (const OR_Matrix &y)
 Copy constructor. More...
 
template<typename U >
 OR_Matrix (const OR_Matrix< U > &y)
 Constructs a conservative approximation of y. More...
 
 ~OR_Matrix ()
 Destructor. More...
 
OR_Matrixoperator= (const OR_Matrix &y)
 Assignment operator. More...
 
void m_swap (OR_Matrix &y)
 Swaps *this with y. More...
 
void grow (dimension_type new_dim)
 Makes the matrix grow by adding more space dimensions. More...
 
void shrink (dimension_type new_dim)
 Makes the matrix shrink by removing the last space dimensions. More...
 
void resize_no_copy (dimension_type new_dim)
 Resizes the matrix without worrying about the old contents. More...
 
dimension_type space_dimension () const
 Returns the space-dimension of the matrix. More...
 
dimension_type num_rows () const
 Returns the number of rows in the matrix. More...
 
row_iterator row_begin ()
 Returns an iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator. More...
 
row_iterator row_end ()
 Returns the past-the-end const_iterator. More...
 
const_row_iterator row_begin () const
 Returns a const row iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator. More...
 
const_row_iterator row_end () const
 Returns the past-the-end const row iterator. More...
 
element_iterator element_begin ()
 Returns an iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator. More...
 
element_iterator element_end ()
 Returns the past-the-end const_iterator. More...
 
const_element_iterator element_begin () const
 Returns a const element iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator. More...
 
const_element_iterator element_end () const
 Returns the past-the-end const element iterator. More...
 
void clear ()
 Clears the matrix deallocating all its rows. 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.
row_reference_type operator[] (dimension_type k)
 Returns a reference to the k-th row of the matrix. More...
 
const_row_reference_type 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 of a OR_Matrix. More...
 
static dimension_type row_size (dimension_type k)
 Returns the size of the row of index k. More...
 

Private Member Functions

 OR_Matrix ()
 Private and not implemented: default construction is not allowed. More...
 

Static Private Member Functions

static dimension_type row_first_element_index (dimension_type k)
 Returns the index into vec of the first element of the row of index k. More...
 

Private Attributes

DB_Row< T > vec
 Contains the rows of the matrix. More...
 
dimension_type space_dim
 Contains the dimension of the space of the matrix. More...
 
dimension_type vec_capacity
 Contains the capacity of vec. More...
 

Friends

template<typename U >
class OR_Matrix
 
bool operator== (const OR_Matrix< T > &x, const OR_Matrix< T > &y)
 

Related Functions

(Note that these are not member functions.)

template<typename T >
bool operator== (const OR_Matrix< T > &x, const OR_Matrix< T > &y)
 Returns true if and only if x and y are identical. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &s, const OR_Matrix< T > &m)
 Output operator. More...
 
template<typename T >
void swap (OR_Matrix< T > &x, OR_Matrix< T > &y)
 Swaps x with y. More...
 
template<typename T >
bool operator!= (const OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_Matrix< T > &y)
 
template<typename T >
bool operator!= (const OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_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 OR_Matrix< T > &x, const OR_Matrix< T > &y, const Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 
template<typename T >
void swap (OR_Matrix< T > &x, OR_Matrix< T > &y)
 
template<typename T >
std::ostream & operator<< (std::ostream &s, const OR_Matrix< T > &m)
 

Detailed Description

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

A matrix representing octagonal constraints.

An OR_Matrix object is a DB_Row object that allows the representation of a pseudo-triangular matrix, like the following:

         _ _
   0    |_|_|
   1    |_|_|_ _
   2    |_|_|_|_|
   3    |_|_|_|_|_ _
   4    |_|_|_|_|_|_|
   5    |_|_|_|_|_|_|
         . . .
         _ _ _ _ _ _       _
 2n-2   |_|_|_|_|_|_| ... |_|
 2n-1   |_|_|_|_|_|_| ... |_|
         0 1 2 3 4 5  ... 2n-1

It is characterized by parameter n that defines the structure, and such that there are 2*n rows (and 2*n columns). It provides row_iterators for the access to the rows and element_iterators for the access to the elements.

Definition at line 105 of file OR_Matrix_defs.hh.

Member Typedef Documentation

template<typename T>
typedef DB_Row<T>::const_iterator Parma_Polyhedra_Library::OR_Matrix< T >::const_element_iterator

A const element iterator.

Definition at line 341 of file OR_Matrix_defs.hh.

template<typename T>
typedef any_row_iterator<const T> Parma_Polyhedra_Library::OR_Matrix< T >::const_row_iterator

A const row iterator.

Definition at line 335 of file OR_Matrix_defs.hh.

template<typename T>
typedef Pseudo_Row<const T> Parma_Polyhedra_Library::OR_Matrix< T >::const_row_reference_type

A const reference to a matrix's row.

Definition at line 193 of file OR_Matrix_defs.hh.

template<typename T>
typedef DB_Row<T>::iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_iterator

A (non const) element iterator.

Definition at line 338 of file OR_Matrix_defs.hh.

template<typename T>
typedef any_row_iterator<T> Parma_Polyhedra_Library::OR_Matrix< T >::row_iterator

A (non const) row iterator.

Definition at line 332 of file OR_Matrix_defs.hh.

template<typename T>
typedef Pseudo_Row<T> Parma_Polyhedra_Library::OR_Matrix< T >::row_reference_type

A (non const) reference to a matrix's row.

Definition at line 190 of file OR_Matrix_defs.hh.

Constructor & Destructor Documentation

template<typename T >
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( dimension_type  num_dimensions)
inline

Builds a matrix with specified dimensions.

Parameters
num_dimensionsThe space dimension of the matrix that will be created.

This constructor creates a matrix with 2*num_dimensions rows. Each element is initialized to plus infinity.

Definition at line 483 of file OR_Matrix_inlines.hh.

484  : vec(2*num_dimensions*(num_dimensions + 1)),
485  space_dim(num_dimensions),
486  vec_capacity(vec.size()) {
487 }
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
template<typename T >
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( const OR_Matrix< T > &  y)
inline

Copy constructor.

Definition at line 552 of file OR_Matrix_inlines.hh.

553  : vec(y.vec),
554  space_dim(y.space_dim),
555  vec_capacity(compute_capacity(y.vec.size(),
556  DB_Row<T>::max_size())) {
557 }
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
static dimension_type max_size()
Returns the size() of the largest possible DB_Row.
template<typename T >
template<typename U >
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( const OR_Matrix< U > &  y)
inlineexplicit

Constructs a conservative approximation of y.

Definition at line 562 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::OK(), Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

563  : vec(),
564  space_dim(y.space_dim),
565  vec_capacity(compute_capacity(y.vec.size(),
566  DB_Row<T>::max_size())) {
567  vec.construct_upward_approximation(y.vec, vec_capacity);
568  PPL_ASSERT(OK());
569 }
bool OK() const
Checks if all the invariants are satisfied.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
static dimension_type max_size()
Returns the size() of the largest possible DB_Row.
template<typename T >
Parma_Polyhedra_Library::OR_Matrix< T >::~OR_Matrix ( )
inline

Destructor.

Definition at line 491 of file OR_Matrix_inlines.hh.

491  {
492 }
template<typename T>
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( )
private

Private and not implemented: default construction is not allowed.

Member Function Documentation

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

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

template<typename T >
void Parma_Polyhedra_Library::OR_Matrix< T >::ascii_dump ( std::ostream &  s) const

Writes to s an ASCII representation of *this.

Definition at line 66 of file OR_Matrix_templates.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::row_begin(), Parma_Polyhedra_Library::OR_Matrix< T >::row_end(), Parma_Polyhedra_Library::Implementation::BD_Shapes::separator, and Parma_Polyhedra_Library::OR_Matrix< T >::space_dimension().

66  {
67  const OR_Matrix<T>& x = *this;
68  const char separator = ' ';
69  dimension_type space = x.space_dimension();
70  s << space << separator << "\n";
71  for (const_row_iterator i = x.row_begin(),
72  x_row_end = x.row_end(); i != x_row_end; ++i) {
74  dimension_type rs = i.row_size();
75  for (dimension_type j = 0; j < rs; ++j) {
76  using namespace IO_Operators;
77  s << r[j] << separator;
78  }
79  s << "\n";
80  }
81 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Pseudo_Row< const T > const_row_reference_type
A const reference to a matrix's row.
any_row_iterator< const T > const_row_iterator
A const row iterator.
template<typename T >
bool Parma_Polyhedra_Library::OR_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 87 of file OR_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.

87  {
88  dimension_type space;
89  if (!(s >> space)) {
90  return false;
91  }
92  resize_no_copy(space);
93  for (row_iterator i = row_begin(),
94  this_row_end = row_end(); i != this_row_end; ++i) {
95  row_reference_type r_i = *i;
96  const dimension_type rs = i.row_size();
97  for (dimension_type j = 0; j < rs; ++j) {
98  Result r = input(r_i[j], s, ROUND_CHECK);
99  if (result_relation(r) != VR_EQ || is_minus_infinity(r_i[j])) {
100  return false;
101  }
102  }
103  }
104  PPL_ASSERT(OK());
105  return true;
106 }
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_minus_infinity(const T &x)
row_iterator row_end()
Returns the past-the-end const_iterator.
size_t dimension_type
An unsigned integral type for representing space dimensions.
any_row_iterator< T > row_iterator
A (non const) row iterator.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Result_Relation result_relation(Result r)
void resize_no_copy(dimension_type new_dim)
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
Pseudo_Row< T > row_reference_type
A (non const) reference to a matrix's row.
row_iterator row_begin()
Returns an iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the...
template<typename T >
void Parma_Polyhedra_Library::OR_Matrix< T >::clear ( )
inline

Clears the matrix deallocating all its rows.

Definition at line 528 of file OR_Matrix_inlines.hh.

528  {
529  OR_Matrix<T>(0).m_swap(*this);
530 }
void m_swap(OR_Matrix &y)
Swaps *this with y.
template<typename T >
OR_Matrix< T >::element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_begin ( )
inline

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

Definition at line 417 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::grow(), and Parma_Polyhedra_Library::OR_Matrix< T >::l_m_distance_assign().

417  {
418  return vec.begin();
419 }
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
OR_Matrix< T >::const_element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_begin ( ) const
inline

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

Definition at line 429 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

429  {
430  return vec.begin();
431 }
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
OR_Matrix< T >::element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_end ( )
inline

Returns the past-the-end const_iterator.

Definition at line 423 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::l_m_distance_assign().

423  {
424  return vec.end();
425 }
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
OR_Matrix< T >::const_element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_end ( ) const
inline

Returns the past-the-end const element iterator.

Definition at line 435 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

435  {
436  return vec.end();
437 }
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
memory_size_type Parma_Polyhedra_Library::OR_Matrix< T >::external_memory_in_bytes ( ) const

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

Definition at line 33 of file OR_Matrix_templates.hh.

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

33  {
34  return vec.external_memory_in_bytes();
35 }
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
void Parma_Polyhedra_Library::OR_Matrix< T >::grow ( dimension_type  new_dim)
inline

Makes the matrix grow by adding more space dimensions.

Parameters
new_dimThe new dimension of the resized matrix.

Adds new rows of right dimension to the end if there is enough capacity; otherwise, creates a new matrix, with the specified dimension, copying the old elements in the upper part of the new matrix, which is then assigned to *this. Each new element is initialized to plus infinity.

Definition at line 582 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::assign_or_swap(), and Parma_Polyhedra_Library::OR_Matrix< T >::element_begin().

582  {
583  PPL_ASSERT(new_dim >= space_dim);
584  if (new_dim > space_dim) {
585  const dimension_type new_size = 2*new_dim*(new_dim + 1);
586  if (new_size <= vec_capacity) {
587  // We can recycle the old vec.
588  vec.expand_within_capacity(new_size);
589  space_dim = new_dim;
590  }
591  else {
592  // We cannot recycle the old vec.
593  OR_Matrix<T> new_matrix(new_dim);
594  element_iterator j = new_matrix.element_begin();
595  for (element_iterator i = element_begin(),
596  mend = element_end(); i != mend; ++i, ++j) {
597  assign_or_swap(*j, *i);
598  }
599  m_swap(new_matrix);
600  }
601  }
602 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Enable_If< Has_Assign_Or_Swap< T >::value, void >::type assign_or_swap(T &to, T &from)
void m_swap(OR_Matrix &y)
Swaps *this with y.
element_iterator element_begin()
Returns an iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
DB_Row< T >::iterator element_iterator
A (non const) element iterator.
element_iterator element_end()
Returns the past-the-end const_iterator.
template<typename T >
void Parma_Polyhedra_Library::OR_Matrix< T >::m_swap ( OR_Matrix< T > &  y)
inline

Swaps *this with y.

Definition at line 441 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, Parma_Polyhedra_Library::OR_Matrix< T >::swap(), Parma_Polyhedra_Library::swap(), Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

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

441  {
442  using std::swap;
443  swap(vec, y.vec);
444  swap(space_dim, y.space_dim);
445  swap(vec_capacity, y.vec_capacity);
446 }
void swap(OR_Matrix< T > &x, OR_Matrix< T > &y)
Swaps x with y.
void swap(CO_Tree &x, CO_Tree &y)
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
template<typename T >
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::max_num_rows ( )
inlinestatic

Returns the maximum number of rows of a OR_Matrix.

Definition at line 468 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::isqrt().

Referenced by Parma_Polyhedra_Library::Octagonal_Shape< T >::max_space_dimension().

468  {
469  // Compute the maximum number of rows that are contained in a DB_Row
470  // that allocates a pseudo-triangular matrix.
471  const dimension_type k = isqrt(2*DB_Row<T>::max_size() + 1);
472  return (k - 1) - (k - 1) % 2;
473 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type isqrt(dimension_type x)
Returns the integer square root of x.
template<typename T >
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::num_rows ( ) const
inline

Returns the number of rows in the matrix.

Definition at line 522 of file OR_Matrix_inlines.hh.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::l_m_distance_assign(), Parma_Polyhedra_Library::OR_Matrix< T >::row_begin(), and Parma_Polyhedra_Library::OR_Matrix< T >::row_end().

522  {
523  return 2*space_dimension();
524 }
dimension_type space_dimension() const
Returns the space-dimension of the matrix.
template<typename T >
bool Parma_Polyhedra_Library::OR_Matrix< T >::OK ( ) const

Checks if all the invariants are satisfied.

Definition at line 39 of file OR_Matrix_templates.hh.

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

39  {
40 #ifndef NDEBUG
41  using std::endl;
42  using std::cerr;
43 #endif
44  // The right number of cells should be in use.
45  const dimension_type dim = space_dimension();
46  if (vec.size() != 2*dim*(dim + 1)) {
47 #ifndef NDEBUG
48  cerr << "OR_Matrix has a wrong number of cells:\n"
49  << "vec.size() is " << vec.size()
50  << ", expected size is " << (2*dim*(dim+1)) << "!\n";
51 #endif
52  return false;
53  }
54 
55  // The underlying DB_Row should be OK.
56  if (!vec.OK(vec.size(), vec_capacity)) {
57  return false;
58  }
59 
60  // All checks passed.
61  return true;
62 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type space_dimension() const
Returns the space-dimension of the matrix.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
template<typename T >
OR_Matrix< T > & Parma_Polyhedra_Library::OR_Matrix< T >::operator= ( const OR_Matrix< T > &  y)
inline

Assignment operator.

Definition at line 573 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::DB_Row< T >::max_size(), Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

573  {
574  vec = y.vec;
575  space_dim = y.space_dim;
577  return *this;
578 }
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
static dimension_type max_size()
Returns the size() of the largest possible DB_Row.
template<typename T >
OR_Matrix< T >::row_reference_type Parma_Polyhedra_Library::OR_Matrix< T >::operator[] ( dimension_type  k)
inline

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

Definition at line 496 of file OR_Matrix_inlines.hh.

References PPL_OR_MATRIX_EXTRA_DEBUG.

496  {
499  , row_size(k)
500 #endif
501  );
502 }
#define PPL_OR_MATRIX_EXTRA_DEBUG
static dimension_type row_first_element_index(dimension_type k)
Returns the index into vec of the first element of the row of index k.
static dimension_type row_size(dimension_type k)
Returns the size of the row of index k.
DB_Row< T > vec
Contains the rows of the matrix.
Pseudo_Row< T > row_reference_type
A (non const) reference to a matrix's row.
template<typename T >
OR_Matrix< T >::const_row_reference_type Parma_Polyhedra_Library::OR_Matrix< T >::operator[] ( dimension_type  k) const
inline

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

Definition at line 506 of file OR_Matrix_inlines.hh.

References PPL_OR_MATRIX_EXTRA_DEBUG.

506  {
509  , row_size(k)
510 #endif
511  );
512 }
Pseudo_Row< const T > const_row_reference_type
A const reference to a matrix's row.
#define PPL_OR_MATRIX_EXTRA_DEBUG
static dimension_type row_first_element_index(dimension_type k)
Returns the index into vec of the first element of the row of index k.
static dimension_type row_size(dimension_type k)
Returns the size of the row of index k.
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::print ( ) const

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

template<typename T >
void Parma_Polyhedra_Library::OR_Matrix< T >::resize_no_copy ( dimension_type  new_dim)
inline

Resizes the matrix without worrying about the old contents.

Parameters
new_dimThe new dimension of the resized matrix.

If the new dimension is greater than the old one, it adds new rows of right dimension to the end if there is enough capacity; otherwise, it creates a new matrix, with the specified dimension, which is then assigned to *this. If the new dimension is less than the old one, it erase from the matrix the rows having index greater than 2*new_dim-1

Definition at line 615 of file OR_Matrix_inlines.hh.

615  {
616  if (new_dim > space_dim) {
617  const dimension_type new_size = 2*new_dim*(new_dim + 1);
618  if (new_size <= vec_capacity) {
619  // We can recycle the old vec.
620  vec.expand_within_capacity(new_size);
621  space_dim = new_dim;
622  }
623  else {
624  // We cannot recycle the old vec.
625  OR_Matrix<T> new_matrix(new_dim);
626  m_swap(new_matrix);
627  }
628  }
629  else if (new_dim < space_dim) {
630  shrink(new_dim);
631  }
632 }
void shrink(dimension_type new_dim)
Makes the matrix shrink by removing the last space dimensions.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void m_swap(OR_Matrix &y)
Swaps *this with y.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
dimension_type vec_capacity
Contains the capacity of vec.
template<typename T >
OR_Matrix< T >::row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_begin ( )
inline

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

Definition at line 393 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::num_rows(), and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::ascii_dump(), Parma_Polyhedra_Library::Octagonal_Shape< T >::get_limiting_octagon(), and Parma_Polyhedra_Library::Octagonal_Shape< T >::map_space_dimensions().

393  {
394  return num_rows() == 0 ? row_iterator(0) : row_iterator(vec[0]);
395 }
dimension_type num_rows() const
Returns the number of rows in the matrix.
any_row_iterator< T > row_iterator
A (non const) row iterator.
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
OR_Matrix< T >::const_row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_begin ( ) const
inline

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

Definition at line 405 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::num_rows(), and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

405  {
406  return num_rows() == 0 ? const_row_iterator(0) : const_row_iterator(vec[0]);
407 }
dimension_type num_rows() const
Returns the number of rows in the matrix.
any_row_iterator< const T > const_row_iterator
A const row iterator.
DB_Row< T > vec
Contains the rows of the matrix.
template<typename T >
OR_Matrix< T >::row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_end ( )
inline

Returns the past-the-end const_iterator.

Definition at line 399 of file OR_Matrix_inlines.hh.

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

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::ascii_dump().

399  {
400  return row_iterator(num_rows());
401 }
dimension_type num_rows() const
Returns the number of rows in the matrix.
any_row_iterator< T > row_iterator
A (non const) row iterator.
template<typename T >
OR_Matrix< T >::const_row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_end ( ) const
inline

Returns the past-the-end const row iterator.

Definition at line 411 of file OR_Matrix_inlines.hh.

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

411  {
412  return const_row_iterator(num_rows());
413 }
dimension_type num_rows() const
Returns the number of rows in the matrix.
any_row_iterator< const T > const_row_iterator
A const row iterator.
template<typename T >
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::row_first_element_index ( dimension_type  k)
inlinestaticprivate

Returns the index into vec of the first element of the row of index k.

Definition at line 39 of file OR_Matrix_inlines.hh.

39  {
40  return ((k + 1)*(k + 1))/2;
41 }
template<typename T >
void Parma_Polyhedra_Library::OR_Matrix< T >::shrink ( dimension_type  new_dim)
inline

Makes the matrix shrink by removing the last space dimensions.

Parameters
new_dimThe new dimension of the resized matrix.

Erases from matrix to the end the rows with index greater than 2*new_dim-1.

Definition at line 606 of file OR_Matrix_inlines.hh.

606  {
607  PPL_ASSERT(new_dim <= space_dim);
608  const dimension_type new_size = 2*new_dim*(new_dim + 1);
609  vec.shrink(new_size);
610  space_dim = new_dim;
611 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
template<typename T >
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::space_dimension ( ) const
inline

Returns the space-dimension of the matrix.

Definition at line 516 of file OR_Matrix_inlines.hh.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::ascii_dump().

516  {
517  return space_dim;
518 }
dimension_type space_dim
Contains the dimension of the space of the matrix.
template<typename T >
memory_size_type Parma_Polyhedra_Library::OR_Matrix< T >::total_memory_in_bytes ( ) const
inline

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

Definition at line 477 of file OR_Matrix_inlines.hh.

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

477  {
478  return sizeof(*this) + external_memory_in_bytes();
479 }
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 Temp , typename To , typename T >
bool euclidean_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_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 euclidean_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 714 of file OR_Matrix_inlines.hh.

720  {
721  return
722  l_m_distance_assign<Euclidean_Distance_Specialization<Temp> >(r, x, y,
723  dir,
724  tmp0,
725  tmp1,
726  tmp2);
727 }
template<typename Temp , typename To , typename T >
bool l_infinity_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_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 Temp , typename To , typename T >
bool l_infinity_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 734 of file OR_Matrix_inlines.hh.

740  {
741  return
742  l_m_distance_assign<L_Infinity_Distance_Specialization<Temp> >(r, x, y,
743  dir,
744  tmp0,
745  tmp1,
746  tmp2);
747 }
template<typename Specialization , typename Temp , typename To , typename T >
bool l_m_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 639 of file OR_Matrix_inlines.hh.

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

645  {
646  if (x.num_rows() != y.num_rows()) {
647  return false;
648  }
649  assign_r(tmp0, 0, ROUND_NOT_NEEDED);
650  for (typename OR_Matrix<T>::const_element_iterator
651  i = x.element_begin(), j = y.element_begin(),
652  mat_end = x.element_end(); i != mat_end; ++i, ++j) {
653  const T& x_i = *i;
654  const T& y_i = *j;
655  if (is_plus_infinity(x_i)) {
656  if (is_plus_infinity(y_i)) {
657  continue;
658  }
659  else {
660  pinf:
662  return true;
663  }
664  }
665  else if (is_plus_infinity(y_i)) {
666  goto pinf;
667  }
668  const Temp* tmp1p;
669  const Temp* tmp2p;
670  if (x_i > y_i) {
671  maybe_assign(tmp1p, tmp1, x_i, dir);
672  maybe_assign(tmp2p, tmp2, y_i, inverse(dir));
673  }
674  else {
675  maybe_assign(tmp1p, tmp1, y_i, dir);
676  maybe_assign(tmp2p, tmp2, x_i, inverse(dir));
677  }
678  sub_assign_r(tmp1, *tmp1p, *tmp2p, dir);
679  PPL_ASSERT(sgn(tmp1) >= 0);
680  Specialization::combine(tmp0, tmp1, dir);
681  }
682 
683  Specialization::finalize(tmp0, dir);
684  assign_r(r, tmp0, dir);
685  return true;
686 }
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &, Rounding_Dir dir)
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 OR_Matrix< T > &  x,
const OR_Matrix< T > &  y 
)
related

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

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

Definition at line 546 of file OR_Matrix_inlines.hh.

546  {
547  return !(x == y);
548 }
template<typename T >
std::ostream & operator<< ( std::ostream &  s,
const OR_Matrix< T > &  m 
)
related

Output operator.

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

Definition at line 113 of file OR_Matrix_templates.hh.

113  {
114  for (typename OR_Matrix<T>::const_row_iterator m_iter = m.row_begin(),
115  m_end = m.row_end(); m_iter != m_end; ++m_iter) {
116  typename OR_Matrix<T>::const_row_reference_type r_m = *m_iter;
117  const dimension_type mr_size = m_iter.row_size();
118  for (dimension_type j = 0; j < mr_size; ++j) {
119  s << r_m[j] << " ";
120  }
121  s << "\n";
122  }
123  return s;
124 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<typename T >
bool operator== ( const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y 
)
related

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

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

Definition at line 537 of file OR_Matrix_inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

537  {
538  return x.space_dim == y.space_dim && x.vec == y.vec;
539 }
template<typename T>
template<typename U >
friend class OR_Matrix
friend

Definition at line 371 of file OR_Matrix_defs.hh.

template<typename Temp , typename To , typename T >
bool rectilinear_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_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 Temp , typename To , typename T >
bool rectilinear_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
)
related

Definition at line 694 of file OR_Matrix_inlines.hh.

700  {
701  return
702  l_m_distance_assign<Rectilinear_Distance_Specialization<Temp> >(r, x, y,
703  dir,
704  tmp0,
705  tmp1,
706  tmp2);
707 }
template<typename T >
void swap ( OR_Matrix< T > &  x,
OR_Matrix< T > &  y 
)
related

Swaps x with y.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::m_swap().

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

Definition at line 752 of file OR_Matrix_inlines.hh.

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

752  {
753  x.m_swap(y);
754 }

Member Data Documentation

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::space_dim
private
template<typename T>
DB_Row<T> Parma_Polyhedra_Library::OR_Matrix< T >::vec
private

Contains the rows of the matrix.

A DB_Row which contains the rows of the OR_Matrix inserting each successive row to the end of the vec. To contain all the elements of OR_Matrix the size of the DB_Row is 2*n*(n+1), where the n is the characteristic parameter of OR_Matrix.

Definition at line 381 of file OR_Matrix_defs.hh.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::element_begin(), Parma_Polyhedra_Library::OR_Matrix< T >::element_end(), Parma_Polyhedra_Library::OR_Matrix< T >::m_swap(), Parma_Polyhedra_Library::OR_Matrix< T >::operator=(), Parma_Polyhedra_Library::OR_Matrix< T >::operator==(), Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix(), and Parma_Polyhedra_Library::OR_Matrix< T >::row_begin().

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity
private

Contains the capacity of vec.

Definition at line 387 of file OR_Matrix_defs.hh.

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


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