/usr/include/linbox/matrix/dense.inl is in liblinbox-dev 1.1.6~rc0-4.1.
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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* linbox/matrix/dense.inl
* Copyright (C) 2001 B. David Saunders,
* 2001-2002 Bradford Hovinen,
* 2002 Zhendong Wan
*
* Written by B. David Saunders <saunders@cis.udel.edu>,
* Bradford Hovinen <hovinen@cis.udel.edu>,
* Zhendong Wan <wan@mail.eecis.udel.edu>
*
* evolved from dense-matrix.h by -bds, Zhendong Wan
*
* --------------------------------------------------------
* 2003-01-11 Bradford Hovinen <bghovinen@math.uwaterloo.ca>
*
* Move from blackbox/dense-base.inl to matrix/dense.inl
* --------------------------------------------------------
* 2002-10-27 Bradford Hovinen <hovinen@cis.udel.edu>
*
* Split out container/iterator functionality into DenseMatrixBase
* --------------------------------------------------------
*
* See COPYING for license information
*/
#ifndef __MATRIX_DENSE_INL
#define __MATRIX_DENSE_INL
#include <iostream>
#include <cmath>
#include "linbox/matrix/dense.h"
#include "linbox/util/debug.h"
namespace LinBox
{
template <class Element>
class DenseMatrixBase<Element>::ConstRowIterator
{
public:
ConstRowIterator (const typename Rep::const_iterator& p, size_t len, size_t d)
: _row (p, p + len), _dis (d) {}
ConstRowIterator () {}
ConstRowIterator (const ConstRowIterator& colp)
: _row (colp._row), _dis (colp._dis) {}
ConstRowIterator& operator = (const ConstRowIterator& colp)
{
_row = colp._row;
_dis = colp._dis;
return *this;
}
ConstRowIterator& operator --()
{
_row = ConstRow (_row.begin () - _dis, _row.end () - _dis);
return *this;
}
ConstRowIterator operator-- (int)
{
ConstRowIterator tmp (*this);
--*this;
return tmp;
}
ConstRowIterator& operator++ ()
{
_row = ConstRow (_row.begin () + _dis, _row.end () + _dis);
return *this;
}
ConstRowIterator operator++ (int)
{
ConstRowIterator tmp (*this);
++*this;
return tmp;
}
ConstRowIterator operator+ (int i)
{ return ConstRowIterator (_row.begin () + _dis * i, _row.size (), _dis); }
ConstRowIterator& operator += (int i)
{
_row = ConstRow (_row.begin () + _dis * i, _row.end () + _dis * i);
return *this;
}
ConstRow operator[] (int i) const
{ return ConstRow (_row.begin () + _dis * i, _row.end () + _dis * i); }
ConstRow* operator-> ()
{ return &_row; }
ConstRow& operator* ()
{ return _row; }
bool operator!= (const ConstRowIterator& c) const
{ return (_row.begin () != c._row.begin ()) || (_row.end () != c._row.end ()) || (_dis != c._dis); }
private:
ConstRow _row;
size_t _dis;
};
template <class Element>
class DenseMatrixBase<Element>::RowIterator
{
public:
RowIterator (const typename Rep::iterator& p, size_t len, size_t d)
: _row (p, p + len), _dis (d){}
RowIterator () {}
RowIterator (const RowIterator& colp)
: _row (colp._row), _dis (colp._dis) {}
RowIterator& operator = (const RowIterator& colp)
{
_row = colp._row;
_dis = colp._dis;
return *this;
}
RowIterator& operator ++ ()
{
_row = Row (_row.begin () + _dis, _row.end () + _dis);
return *this;
}
RowIterator operator ++ (int)
{
RowIterator tmp (*this);
++*this;
return tmp;
}
RowIterator& operator -- ()
{
_row = Row (_row.begin () - _dis, _row.end () - _dis);
return *this;
}
RowIterator operator -- (int)
{
RowIterator tmp (*this);
--*this;
return tmp;
}
RowIterator operator + (int i)
{ return RowIterator (_row.begin () + _dis * i, _row.size (), _dis); }
RowIterator& operator += (int i)
{
_row = Row (_row.begin () + _dis * i, _row.end () + _dis * i);
return *this;
}
Row operator[] (int i) const
{ return Row (const_cast<Row&> (_row).begin () + _dis * i,
const_cast<Row&> (_row).end () + _dis * i); }
Row* operator-> ()
{ return &_row; }
Row& operator* ()
{ return _row; }
bool operator!= (const RowIterator& c) const
{ return (_row.begin () != c._row.begin ()) || (_row.end () != c._row.end ()) || (_dis != c._dis); }
operator ConstRowIterator ()
{ return ConstRowIterator (_row.begin (), _row.size (), _dis); }
private:
Row _row;
size_t _dis;
};
template <class Element>
class DenseMatrixBase<Element>::ConstColIterator
{
public:
ConstColIterator (typename Rep::const_iterator p, size_t stride, size_t len)
: _col (Subiterator<typename Rep::const_iterator> (p, stride),
Subiterator<typename Rep::const_iterator> (p + len * stride, stride)), _stride (stride)
{}
ConstColIterator (const ConstCol& col, size_t stride)
:_col (col), _stride (stride){}
ConstColIterator () {}
ConstColIterator (const ConstColIterator& rowp)
:_col (rowp._col){}
ConstColIterator& operator= (const ConstColIterator& rowp)
{
_col = rowp._col;
_stride = rowp._stride;
return *this;
}
ConstColIterator& operator++ ()
{
_col = ConstCol (Subiterator<typename Rep::const_iterator> (_col.begin ().operator-> () + 1, _stride),
Subiterator<typename Rep::const_iterator> (_col.end ().operator-> () + 1, _stride));
return *this;
}
ConstColIterator operator++ (int)
{
ConstColIterator old(*this);
this->operator++ ();
return old;
}
ConstColIterator operator + (int i)
{ return ConstColIterator (_col.begin ().operator-> () + i, _stride, _col.size ()); }
ConstColIterator& operator += (int i)
{
_col = ConstCol (Subiterator<typename Rep::const_iterator> (_col.begin ().operator-> () + i, _stride),
Subiterator<typename Rep::const_iterator> (_col.end ().operator-> () + i, _stride));
return *this;
}
ConstCol operator[] (int i) const
{ return ConstCol (Subiterator<typename Rep::const_iterator> (_col.begin ().operator-> () + i, _stride),
Subiterator<typename Rep::const_iterator> (_col.end ().operator-> () + i, _stride)); }
ConstCol* operator-> ()
{ return &_col; }
ConstCol& operator* ()
{ return _col; }
bool operator!= (const ConstColIterator& c) const
{ return (_col.begin () != c._col.begin ()) || (_col.end () != c._col.end ()); }
private:
ConstCol _col;
size_t _stride;
};
template <class Element>
class DenseMatrixBase<Element>::ColIterator
{
public:
ColIterator (typename Rep::iterator p, size_t stride, size_t len)
: _col (Subiterator<typename Rep::iterator> (p, stride),
Subiterator<typename Rep::iterator> (p + len * stride, stride)), _stride (stride)
{}
ColIterator () {}
ColIterator (const ColIterator& rowp)
:_col (rowp._col){}
ColIterator& operator= (const ColIterator& rowp)
{
_col = rowp._col;
_stride = rowp._stride;
return *this;
}
const ColIterator& operator= (const ColIterator& rowp) const
{
const_cast<ColIterator*> (this)->_col = rowp._col;
return *this;
}
ColIterator& operator++ ()
{
_col = Col (Subiterator<typename Rep::iterator> (_col.begin ().operator-> () + 1, _stride),
Subiterator<typename Rep::iterator> (_col.end ().operator-> () + 1, _stride));
return *this;
}
ColIterator operator++ (int)
{
Col tmp (_col);
this->operator++ ();
return tmp;
}
ColIterator operator + (int i)
{ return ColIterator (_col.begin ().operator-> () + i, _stride, _col.size ()); }
ColIterator& operator += (int i)
{
_col = Col (Subiterator<typename Rep::iterator> (_col.begin ().operator-> () + i, _stride),
Subiterator<typename Rep::iterator> (_col.end ().operator-> () + i, _stride));
return *this;
}
Col operator[] (int i) const
{ return Col (Subiterator<typename Rep::iterator> (const_cast<Col&> (_col).begin ().operator-> () + i, _stride),
Subiterator<typename Rep::iterator> (const_cast<Col&> (_col).end ().operator-> () + i, _stride)); }
Col* operator-> ()
{ return &_col; }
Col& operator* ()
{ return _col; }
bool operator!= (const ColIterator& c) const
{ return (_col.begin () != c._col.begin ()) || (_col.end () != c._col.end ()); }
operator ConstColIterator ()
{
return ConstColIterator (reinterpret_cast<ConstCol&> (_col) , _stride);
}
private:
Col _col;
size_t _stride;
};
template <class _Element>
template <class Field>
DenseMatrixBase<_Element>::DenseMatrixBase( MatrixStream<Field>& ms )
:_rep(0), _rows(0), _cols(0), _ptr(NULL)
{
if( !ms.getArray(_rep) || !ms.getRows(_rows) || !ms.getColumns(_cols) )
throw ms.reportError(__FUNCTION__,__LINE__);
_ptr = &_rep[0];
}
/// entry access raw view. Size m*n vector in C (row major) order.
template <class Element>
typename DenseMatrixBase<Element>::RawIterator DenseMatrixBase<Element>::rawBegin ()
{ return _rep.begin (); }
template <class Element>
typename DenseMatrixBase<Element>::RawIterator DenseMatrixBase<Element>::rawEnd ()
{ return _rep.end (); }
template <class Element>
typename DenseMatrixBase<Element>::ConstRawIterator DenseMatrixBase<Element>::rawBegin () const
{ return _rep.begin (); }
template <class Element>
typename DenseMatrixBase<Element>::ConstRawIterator DenseMatrixBase<Element>::rawEnd () const
{ return _rep.end (); }
template <class Element>
typename DenseMatrixBase<Element>::RowIterator DenseMatrixBase<Element>::rowBegin ()
{ return RowIterator (_rep.begin (), _cols, _cols); }
template <class Element>
typename DenseMatrixBase<Element>::RowIterator DenseMatrixBase<Element>::rowEnd ()
{ return RowIterator (_rep.end (), _cols, _cols); }
template <class Element>
typename DenseMatrixBase<Element>::ConstRowIterator DenseMatrixBase<Element>::rowBegin () const
{ return ConstRowIterator (_rep.begin (), _cols, _cols); }
template <class Element>
typename DenseMatrixBase<Element>::ConstRowIterator DenseMatrixBase<Element>::rowEnd () const
{return ConstRowIterator (_rep.end (), _cols, _cols); }
template <class Element>
typename DenseMatrixBase<Element>::ColIterator DenseMatrixBase<Element>::colBegin ()
{ return typename DenseMatrixBase<Element>::ColIterator (_rep.begin (), _cols, _rows); }
template <class Element>
typename DenseMatrixBase<Element>::ColIterator DenseMatrixBase<Element>::colEnd ()
{ return typename DenseMatrixBase<Element>::ColIterator (_rep.begin ()+_cols, _cols, _rows); }
template <class Element>
typename DenseMatrixBase<Element>::ConstColIterator DenseMatrixBase<Element>::colBegin () const
{ return typename DenseMatrixBase<Element>::ConstColIterator (_rep.begin (), _cols, _rows); }
template <class Element>
typename DenseMatrixBase<Element>::ConstColIterator DenseMatrixBase<Element>::colEnd () const
{ return typename DenseMatrixBase<Element>::ConstColIterator (_rep.begin ()+_cols, _cols, _rows); }
template <class Element>
template <class Field>
std::istream &DenseMatrixBase<Element>::read (std::istream &file, const Field &F)
{
// RawIterator p;
// int m,n;
// char c;
// file>>m>>n>>c;
// if (m*n < _rows*_cols)
// cerr<<"NOT ENOUGH ELEMENT TO READ\n";
// else {
// for (p = rawBegin (); p != rawEnd (); ++p) {
// integer tmp;
// file>>tmp;cout<<tmp<<endl;
// //file.ignore(1);
// F.read (file, *p);
// }
// }
RawIterator p;
int m,n;
char c;
file>>m>>n>>c;
_rows = m; _cols = n;
Element zero;
F.init(zero,0UL);
_rep.resize(_rows * _cols, zero);
_ptr= &_rep[0];
if ((c != 'M') && (c != 'm'))
for (p = rawBegin (); p != rawEnd (); ++p)
{
//file.ignore(1);
F.read (file, *p);
}
else { // sparse file format - needs fixing
int i, j;
while (true)
{
file >> i >> j;
//file.ignore(1);
//if (! file) break;
if (i+j <= 0) break;
F.read (file, _rep[_cols*(i-1) + j-1]);
}
}
return file;
}
template <class Element>
template <class Field>
std::ostream& DenseMatrixBase<Element>::write (std::ostream &os, const Field &F) const
{
integer c;
int wid;
ConstRowIterator p;
F.cardinality (c);
if (c >0)
wid = (int) ceil (log ((double) c) / M_LN10);
else {
integer tmp;
size_t max=0;
ConstRawIterator it = rawBegin();
for (; it != rawEnd(); ++it){
F.convert(tmp,*it);
if (tmp.bitsize() > max)
max= tmp.bitsize();
}
wid= (int) ceil ((double)max / M_LN10)+1;
}
for (p = rowBegin (); p != rowEnd (); ++p) {
typename ConstRow::const_iterator pe;
os << " [ ";
for (pe = p->begin (); pe != p->end (); ++pe) {
os.width (wid);
F.write (os, *pe);
os << " ";
}
os << "]" << std::endl;
}
return os;
}
template <class Element>
class DenseMatrixBase<Element>::RawIndexedIterator
{
size_t _r_index;
size_t _c_index;
size_t _dim;
typename Rep::iterator _begin;
public:
RawIndexedIterator (const size_t &dim,
const size_t &r_index,
const size_t &c_index,
const typename Rep::iterator &begin)
: _r_index (r_index), _c_index (c_index), _dim (dim), _begin (begin)
{}
RawIndexedIterator ():_r_index (0), _c_index (0), _dim (1), _begin (0){}
RawIndexedIterator (const RawIndexedIterator& r)
: _r_index (r._r_index), _c_index (r._c_index), _dim (r._dim), _begin (r._begin)
{}
RawIndexedIterator& operator = (const RawIndexedIterator &iter)
{
_r_index = iter._r_index;
_c_index = iter._c_index;
_dim = iter._dim;
_begin = iter._begin;
return *this;
}
bool operator == (const RawIndexedIterator &iter) const
{ return (_r_index == iter._r_index) &&
(_c_index == iter._c_index) &&
(_dim == iter._dim) &&
(_begin==iter._begin); }
bool operator != (const RawIndexedIterator& iter) const
{ return (_r_index != iter._r_index) ||
(_c_index != iter._c_index) ||
(_dim != iter._dim) ||
(_begin!=iter._begin); }
RawIndexedIterator &operator ++ ()
{
++_c_index;
if (_c_index == _dim) {
_c_index = 0;
++_r_index;
}
return *this;
}
RawIndexedIterator operator ++ (int)
{
RawIndexedIterator tmp = *this;
++(*this);
return tmp;
}
RawIndexedIterator &operator -- ()
{
if (_c_index)
--_c_index;
else {
--_r_index;
_c_index = _dim - 1;
}
return *this;
}
RawIndexedIterator operator -- (int)
{
RawIndexedIterator tmp = *this;
--(*this);
return tmp;
}
Element &operator * () const
{ return *(_begin + (_r_index * _dim + _c_index)); }
Element* operator -> () const
{ return _begin + (_r_index * _dim + _c_index); }
size_t rowIndex () const
{ return _r_index; }
size_t colIndex () const
{ return _c_index; }
};
template <class Element>
typename DenseMatrixBase<Element>::RawIndexedIterator DenseMatrixBase<Element>::rawIndexedBegin ()
{
return RawIndexedIterator (coldim (), 0, 0, _rep.begin ());
}
template <class Element>
typename DenseMatrixBase<Element>::RawIndexedIterator DenseMatrixBase<Element>::rawIndexedEnd ()
{
return RawIndexedIterator (coldim (), rowdim (), 0, _rep.begin ());
}
template <class Element>
class DenseMatrixBase<Element>::ConstRawIndexedIterator
{
size_t _r_index;
size_t _c_index;
size_t _dim;
typename Rep::const_iterator _begin;
public:
ConstRawIndexedIterator (const size_t &dim,
const size_t &r_index,
const size_t &c_index,
const typename Rep::const_iterator &begin)
: _r_index (r_index), _c_index (c_index), _dim (dim), _begin (begin)
{}
ConstRawIndexedIterator ():_r_index (0), _c_index (0), _dim (1), _begin (0){}
ConstRawIndexedIterator (const ConstRawIndexedIterator& r)
: _r_index (r._r_index), _c_index (r._c_index), _dim (r._dim), _begin (r._begin)
{}
ConstRawIndexedIterator& operator = (const ConstRawIndexedIterator &iter)
{
_r_index = iter._r_index;
_c_index = iter._c_index;
_dim = iter._dim;
_begin = iter._begin;
return *this;
}
bool operator == (const ConstRawIndexedIterator &iter) const
{ return (_r_index == iter._r_index) &&
(_c_index == iter._c_index) &&
(_dim == iter._dim) &&
(_begin==iter._begin); }
bool operator != (const ConstRawIndexedIterator& iter) const
{ return (_r_index != iter._r_index) ||
(_c_index != iter._c_index) ||
(_dim != iter._dim) ||
(_begin!=iter._begin); }
ConstRawIndexedIterator &operator ++ ()
{
++_c_index;
if (_c_index == _dim) {
_c_index = 0;
++_r_index;
}
return *this;
}
ConstRawIndexedIterator operator ++ (int)
{
ConstRawIndexedIterator tmp = *this;
++(*this);
return tmp;
}
ConstRawIndexedIterator &operator -- ()
{
if (_c_index)
--_c_index;
else {
--_r_index;
_c_index = _dim - 1;
}
return *this;
}
ConstRawIndexedIterator operator -- (int)
{
ConstRawIndexedIterator tmp = *this;
--(*this);
return tmp;
}
const Element &operator * () const
{ return *(_begin + (_r_index * _dim + _c_index)); }
const Element *operator -> () const
{ return _begin + (_r_index * _dim + _c_index); }
size_t rowIndex () const
{ return _r_index; }
size_t colIndex () const
{ return _c_index; }
};
template <class Element>
typename DenseMatrixBase<Element>::ConstRawIndexedIterator DenseMatrixBase<Element>::rawIndexedBegin () const
{
return ConstRawIndexedIterator (coldim (), 0, 0, _rep.begin ());
}
template <class Element>
typename DenseMatrixBase<Element>::ConstRawIndexedIterator DenseMatrixBase<Element>::rawIndexedEnd () const
{
return ConstRawIndexedIterator (coldim (), rowdim (), 0, _rep.begin ());
}
} // namespace LinBox
#endif // __MATRIX_DENSE_INL
|