/usr/include/polymake/ListMatrix.h is in libpolymake-dev-common 3.2r2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | /* Copyright (c) 1997-2018
Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
http://www.polymake.org
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl.txt.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
--------------------------------------------------------------------------------
*/
/** @file ListMatrix.h
@brief Implementation of pm::ListMatrix class
*/
#ifndef POLYMAKE_LIST_MATRIX_H
#define POLYMAKE_LIST_MATRIX_H
#include "polymake/GenericMatrix.h"
#include "polymake/internal/CombArray.h"
namespace pm {
/** @class ListMatrix
@brief List of row vectors.
A list of row vectors. The implementation is based on std::list. It can be parameterized with any @ref persistent vector type.
*/
template <typename TVector>
class ListMatrix
: public GenericMatrix< ListMatrix<TVector>, typename TVector::element_type> {
protected:
typedef std::list<TVector> row_list;
shared_object<ListMatrix_data<TVector>, AliasHandlerTag<shared_alias_handler>> data;
friend ListMatrix& make_mutable_alias(ListMatrix& alias, ListMatrix& owner)
{
alias.data.make_mutable_alias(owner.data);
return alias;
}
// elementwise
template <typename Iterator>
void copy_impl(int r, int c, Iterator src, std::false_type)
{
data->dimr=r;
data->dimc=c;
row_list& R=data->R;
while (--r>=0) {
Iterator src_next=src;
std::advance(src_next, c);
R.push_back(TVector(c, make_iterator_range(src, src_next)));
src=src_next;
}
}
// rowwise
template <typename Iterator>
void copy_impl(int r, int c, Iterator src, std::true_type)
{
data->dimr=r;
data->dimc=c;
row_list& R=data->R;
while (--r>=0) {
R.push_back(TVector(*src)); ++src;
}
}
public:
typedef typename TVector::value_type value_type;
typedef typename TVector::reference reference;
typedef typename TVector::const_reference const_reference;
typedef typename TVector::element_type element_type;
/// create as empty
ListMatrix() {}
/// create matrix with r rows and c columns, initialize all elements to 0
ListMatrix(int r, int c)
{
data->dimr=r;
data->dimc=c;
data->R.assign(r, TVector(c));
}
ListMatrix(int r, int c, const element_type& init)
{
data->dimr=r;
data->dimc=c;
data->R.assign(r, same_element_vector(init, c));
}
/** Create a matrix with given dimensions. Elements are initialized from an input sequence.
Elements are assumed to come in the row order.
*/
template <typename Iterator>
ListMatrix(int r, int c, Iterator src)
{
copy_impl(r, c, src, bool_constant<isomorphic_types<TVector, typename iterator_traits<Iterator>::value_type>::value>());
}
template <typename Matrix2>
ListMatrix(const GenericMatrix<Matrix2,element_type>& M)
{
copy_impl(M.rows(), M.cols(), pm::rows(M).begin(), std::true_type());
}
template <typename Matrix2, typename E2>
explicit ListMatrix(const GenericMatrix<Matrix2,E2>& M)
{
copy_impl(M.rows(), M.cols(), pm::rows(M).begin(), std::true_type());
}
template <typename Container, typename enabled=typename std::enable_if<isomorphic_to_container_of<Container, TVector>::value>::type>
ListMatrix(const Container& src)
{
copy_impl(src.size(), src.empty() ? 0 : get_dim(src.front()), src.begin(), std::true_type());
}
private:
template <typename Input>
void input(Input& is)
{
if ((data->dimr=retrieve_container(is, data->R, io_test::as_list< array_traits<TVector> >())))
data->dimc=data->R.front().dim();
}
public:
template <typename Input> friend
Input& operator>> (GenericInput<Input>& is, ListMatrix& M)
{
M.input(is.top());
return is.top();
}
/**
Persistent matrix objects have after the assignment the same dimensions as the right hand side operand.
Alias objects, such as matrix minor or block matrix, cannot be resized, thus must have the same dimensions as on the right hand side.
*/
ListMatrix& operator= (const ListMatrix& other) { assign(other); return *this; }
using ListMatrix::generic_type::operator=;
/// Exchange the contents of two matrices in a most efficient way.
/// If at least one non-persistent object is involved, the operands must have equal dimensions.
void swap(ListMatrix& M) { data.swap(M.data); }
friend void relocate(ListMatrix* from, ListMatrix* to)
{
relocate(&from->data, &to->data);
}
/// Resize to new dimensions, added elements initialized with default constructor.
void resize(int r, int c)
{
row_list& R=data->R;
int old_r=data->dimr;
data->dimr=r;
for (; old_r>r; --old_r) R.pop_back();
if (data->dimc != c) {
for (typename Entire<row_list>::iterator row=entire(R); !row.at_end(); ++row)
row->resize(c);
data->dimc=c;
}
for (; old_r<r; ++old_r) R.push_back(TVector(c));
}
/// Truncate to 0x0 matrix.
void clear() { data.apply(shared_clear()); }
/// the number of rows of the matrix
int rows() const { return data->dimr; }
/// the number of columns of the matrix
int cols() const { return data->dimc; }
/// Insert a new row at the given position: before the row pointed to by where.
template <typename TVector2>
typename row_list::iterator
insert_row(const typename row_list::iterator& where, const GenericVector<TVector2>& v)
{
if (!this->rows()) {
data->dimc=v.dim();
} else if (POLYMAKE_DEBUG || !Unwary<TVector2>::value) {
if (this->cols() != v.dim())
throw std::runtime_error("ListMatrix::insert_row - dimension mismatch");
}
++data->dimr;
return data->R.insert(where,v.top());
}
/// Delete the row pointed to by where. Be aware that the iterator becomes void after the removal unless rescued in good time (with postincrement or postdecrement).
void delete_row(const typename row_list::iterator& where)
{
--data->dimr;
data->R.erase(where);
}
protected:
template <typename, typename> friend class GenericMatrix;
friend class Rows<ListMatrix>;
template <typename,typename,typename> friend class ListMatrix_cols;
void assign(const GenericMatrix<ListMatrix>& M) { data=M.top().data; }
template <typename Matrix2>
void assign(const GenericMatrix<Matrix2>& M)
{
int old_r=data->dimr, r=M.rows();
data->dimr=r;
data->dimc=M.cols();
row_list& R=data->R;
for (; old_r>r; --old_r) R.pop_back();
auto row2=pm::rows(M).begin();
for (auto row=entire(R); !row.at_end(); ++row, ++row2)
*row=*row2;
for (; old_r<r; ++old_r, ++row2) R.push_back(*row2);
}
template <typename Matrix2>
void append_rows(const Matrix2& m)
{
copy_range(entire(pm::rows(m)), std::back_inserter(data->R));
data->dimr+=m.rows();
}
template <typename TVector2>
void append_row(const TVector2& v)
{
data->R.push_back(v);
++data->dimr;
}
template <typename Matrix2>
void append_cols(const Matrix2& m)
{
auto row2=pm::rows(m).begin();
for (auto row=entire(data->R); !row.at_end(); ++row, ++row2)
*row |= *row2;
data->dimc+=m.cols();
}
template <typename TVector2>
void append_col(const TVector2& v)
{
auto e=ensure(v.top(), (dense*)0).begin();
for (auto row=entire(data->R); !row.at_end(); ++row, ++e)
*row |= *e;
++data->dimc;
}
};
template <typename TVector>
struct check_container_feature<ListMatrix<TVector>, sparse>
: check_container_feature<TVector, sparse> {};
template <typename TVector>
struct check_container_feature<ListMatrix<TVector>, pure_sparse>
: check_container_feature<TVector, pure_sparse> {};
template <typename TVector>
class Rows< ListMatrix<TVector> >
: public redirected_container< Rows< ListMatrix<TVector> >,
mlist< ContainerTag< std::list<TVector> >,
MasqueradedTop > > {
typedef redirected_container<Rows> base_t;
protected:
Rows();
~Rows();
public:
typename base_t::container& get_container() { return this->hidden().data->R; }
const typename base_t::container& get_container() const { return this->hidden().data->R; }
int size() const { return this->hidden().rows(); }
void resize(int n) { this->hidden().resize(n, this->hidden().cols()); }
void clear() { this->hidden().clear(); }
template <typename TVector2>
typename base_t::iterator insert(typename base_t::iterator where, const GenericVector<TVector2>& v)
{
return this->hidden().insert_row(where, v);
}
};
template <typename TVector>
class Cols< ListMatrix<TVector> >
: public ListMatrix_cols<ListMatrix<TVector>, TVector> {
protected:
Cols();
~Cols();
};
} // end namespace pm
namespace polymake {
using pm::ListMatrix;
}
#endif // POLYMAKE_LIST_MATRIX_H
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
|