PPL  1.2
Matrix_inlines.hh
Go to the documentation of this file.
1 /* Matrix class implementation: inline functions.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Matrix_inlines_hh
25 #define PPL_Matrix_inlines_hh 1
26 
27 namespace Parma_Polyhedra_Library {
28 
29 template <typename Row>
30 inline dimension_type
32  return std::vector<Row>().max_size();
33 }
34 
35 template <typename Row>
36 inline dimension_type
38  return Row::max_size();
39 }
40 
41 template <typename Row>
42 inline void
44  using std::swap;
45  swap(rows, x.rows);
46  swap(num_columns_, x.num_columns_);
47 }
48 
49 template <typename Row>
50 inline dimension_type
52  return rows.size();
53 }
54 
55 template <typename Row>
56 inline dimension_type
58  return num_columns_;
59 }
60 
61 template <typename Row>
62 inline dimension_type
64  return rows.capacity();
65 }
66 
67 template <typename Row>
68 inline bool
70  return num_rows() == 0;
71 }
72 
73 template <typename Row>
74 inline void
76  resize(n, n);
77 }
78 
79 template <typename Row>
80 inline void
82 
83  rows.reserve(requested_capacity);
84 }
85 
86 template <typename Row>
87 inline void
89  resize(num_rows() + n, num_columns() + m);
90 }
91 
92 template <typename Row>
93 inline void
95  resize(num_rows() + n, num_columns());
96 }
97 
98 template <typename Row>
99 inline void
100 Matrix<Row>::add_row(const Row& x) {
101  // TODO: Optimize this.
102  Row row(x);
103  add_zero_rows(1);
104  // Now x may have been invalidated, if it was a row of this matrix.
105  swap(rows.back(), row);
106  PPL_ASSERT(OK());
107 }
108 
109 template <typename Row>
110 inline void
112  add_zero_rows(1);
113  swap(rows.back(), x);
114  PPL_ASSERT(OK());
115 }
116 
117 template <typename Row>
118 inline void
120  resize(num_rows() - n, num_columns());
121 }
122 
123 template <typename Row>
124 inline void
126  rows.erase(first, last);
127 }
128 
129 template <typename Row>
130 inline void
132  resize(num_rows(), num_columns() + n);
133 }
134 
135 template <typename Row>
136 inline void
138  PPL_ASSERT(n <= num_columns());
139  resize(num_rows(), num_columns() - n);
140 }
141 
142 template <typename Row>
143 inline void
145  resize(0, 0);
146 }
147 
148 template <typename Row>
149 inline typename Matrix<Row>::iterator
151  return rows.begin();
152 }
153 
154 template <typename Row>
155 inline typename Matrix<Row>::iterator
157  return rows.end();
158 }
159 
160 template <typename Row>
161 inline typename Matrix<Row>::const_iterator
163  return rows.begin();
164 }
165 
166 template <typename Row>
167 inline typename Matrix<Row>::const_iterator
169  return rows.end();
170 }
171 
172 template <typename Row>
173 inline Row&
175  PPL_ASSERT(i < rows.size());
176  return rows[i];
177 }
178 
179 template <typename Row>
180 inline const Row&
182  PPL_ASSERT(i < rows.size());
183  return rows[i];
184 }
185 
186 template <typename Row>
187 inline memory_size_type
189  return sizeof(*this) + external_memory_in_bytes();
190 }
191 
192 template <typename Row>
193 inline void
195  x.m_swap(y);
196 }
197 
198 } // namespace Parma_Polyhedra_Library
199 
200 #endif // !defined(PPL_Matrix_inlines_hh)
void swap(Matrix< Row > &x, Matrix< Row > &y)
void swap(CO_Tree &x, CO_Tree &y)
size_t dimension_type
An unsigned integral type for representing space dimensions.
static dimension_type max_num_columns()
Returns the maximum number of columns of a Sparse_Matrix.
iterator end()
Returns an iterator pointing after the last row.
void remove_trailing_columns(dimension_type n)
Shrinks the matrix by removing its n trailing columns.
Swapping_Vector< Row >::iterator iterator
Definition: Matrix_defs.hh:40
A sparse matrix of Coefficient.
Definition: Matrix_defs.hh:37
Swapping_Vector< Row >::const_iterator const_iterator
Definition: Matrix_defs.hh:41
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
void add_zero_rows_and_columns(dimension_type n, dimension_type m)
Adds n rows and m columns of zeroes to the matrix.
void add_zero_rows(dimension_type n)
Adds to the matrix n rows of zeroes.
void clear()
Equivalent to resize(0,0).
void remove_rows(iterator first, iterator last)
iterator begin()
Returns an iterator pointing to the first row.
void add_row(const Row &x)
Adds a copy of the row x at the end of the matrix.
dimension_type num_columns() const
Returns the number of columns in the matrix.
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
bool has_no_rows() const
Returns true if and only if *this has no rows.
void remove_trailing_rows(dimension_type n)
Removes from the matrix the last n rows.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
static dimension_type max_num_rows()
Returns the maximum number of rows of a Sparse_Matrix.
The entire library is confined to this namespace.
Definition: version.hh:61
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
Row & operator[](dimension_type i)
Returns a reference to the i-th row.
dimension_type capacity() const
Returns the capacity of the row vector.
void reserve_rows(dimension_type n)
Reserves space for at least n rows.
void add_recycled_row(Row &y)
Adds the row y to the matrix.
void resize(dimension_type n)
Equivalent to resize(n, n).
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
void add_zero_columns(dimension_type n)
Adds n columns of zeroes to the matrix.
dimension_type num_rows() const
Returns the number of rows in the matrix.
void m_swap(Matrix &x)
Swaps (*this) with x.