/usr/include/linbox/matrix/blas-submatrix.inl is in liblinbox-dev 1.3.2-1.1build2.
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 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | /* linbox/matrix/blas-matrix.h
* Copyright (C) 2004 Pascal Giorgi, Clément Pernet
*
* Written by :
* Pascal Giorgi <pascal.giorgi@ens-lyon.fr>
* Clément Pernet <clement.pernet@imag.fr>
* Brice Boyer <bboyer@imag.fr>
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
/*!@internal
* @file matrix/blas-matrix.inl
* @ingroup matrix
* A \c BlasMatrix<\c _Field > represents a matrix as an array of
* <code>_Field</code>s.
*/
#ifndef __LINBOX_blas_submatrix_INL
#define __LINBOX_blas_submatrix_INL
/////////////////
// PRIVATE //
/////////////////
namespace LinBox
{
}
//////////////////
// CONSTRUCTORS //
//////////////////
namespace LinBox
{
template <class _Field>
BlasSubmatrix<_Field>::BlasSubmatrix () :
_Mat(NULL),_row(0),_col(0),_r0(0),_c0(0),_stride(0),_off(0)
{
#ifndef NDEBUG
std::cerr << "***Warning*** you are creating a NULL BlasSubmatrix. You are stuck with it now." << std::endl;
#endif
}
template <class _Field>
BlasSubmatrix<_Field>::BlasSubmatrix (const BlasMatrix<_Field> &Mat,
size_t row,
size_t col,
size_t Rowdim,
size_t Coldim) :
_Mat (&(const_cast<BlasMatrix<Field>& >(Mat))),
_row (Rowdim), _col(Coldim),
_r0(row),_c0(col),
_stride(Mat.coldim()),_off(row*_stride+col)
{
linbox_check ( _r0 <= Mat.rowdim() ); // allow for NULL matrix
linbox_check ( _c0 <= Mat.coldim() );
// linbox_check ( _row <= Mat.rowdim() );
linbox_check ( _off <= Mat.rowdim()*Mat.coldim() );
linbox_check ( _col <= Mat.coldim() );
}
template <class _Field>
BlasSubmatrix<_Field>::BlasSubmatrix (const BlasMatrix<_Field> &Mat) :
_Mat(&(const_cast<BlasMatrix<Field>& >(Mat))),
_row(Mat.rowdim()), _col(Mat.coldim()),
_r0(0), _c0(0),
_stride(Mat.coldim()),_off(0)
{}
template <class _Field>
BlasSubmatrix<_Field>::BlasSubmatrix (const BlasSubmatrix<_Field> &SM,
size_t row,
size_t col,
size_t Rowdim,
size_t Coldim) :
_Mat (SM._Mat),
_row ( Rowdim ), _col ( Coldim ) ,
_r0 ( SM._r0 + row ), _c0 ( SM._c0 + col ),
_stride(SM._stride),_off(SM._off+(row*_stride+col))
{
linbox_check ( _r0 <= SM._Mat->rowdim() ); // allow for NULL matrix
linbox_check ( _c0 <= SM._stride );
linbox_check ( _row <= SM._Mat->rowdim() );
linbox_check ( _col <= SM._stride );
linbox_check ( _off <= SM._Mat->rowdim()*(SM._Mat->coldim()+1) );
}
template <class _Field>
BlasSubmatrix<_Field>::BlasSubmatrix (const BlasSubmatrix<_Field> &SM) :
_Mat (SM._Mat),
_row ( SM._row ), _col ( SM._col ) ,
_r0 ( SM._r0 ), _c0 (SM._c0 ),
_stride(SM._stride),_off(SM._off)
{
linbox_check ( _r0 <= SM._Mat->rowdim() ); // allow for NULL matrix
linbox_check ( _c0 <= SM._stride );
linbox_check ( _row <= SM._Mat->rowdim() );
linbox_check ( _col <= SM._stride );
linbox_check ( _off <= SM._Mat->rowdim()*(SM._Mat->coldim()+1) );
}
template <class _Field>
BlasSubmatrix<_Field>& BlasSubmatrix<_Field>::operator=(const BlasSubmatrix<_Field> &SM)
{
if ( &SM == this)
return *this ;
_Mat = SM._Mat ;
_r0 = SM._r0 ;
_row = SM._row;
_c0 = SM._c0 ;
_col = SM._col;
_stride = SM._stride;
_off = SM._off ;
return *this;
}
} // LinBox
//////////////////
// DIMENSIONS //
//////////////////
namespace LinBox
{
template <class _Field>
size_t BlasSubmatrix< _Field>::rowdim() const
{
return _row ;
}
template <class _Field>
size_t BlasSubmatrix< _Field>::coldim() const
{
return _col ;
}
template <class _Field>
size_t BlasSubmatrix< _Field>::getStride() const
{
return _stride;
}
} // LinBox
//////////////////
// ELEMENTS //
//////////////////
namespace LinBox
{
template <class _Field>
typename BlasSubmatrix< _Field>::pointer
BlasSubmatrix< _Field>::getPointer() const
{
return _Mat->getPointer()+_off;
}
template <class _Field>
typename BlasSubmatrix< _Field>::const_pointer &
BlasSubmatrix< _Field>::getConstPointer() const
{
return _Mat->getConstPointer()+_off;
}
template <class _Field>
typename BlasSubmatrix< _Field>::pointer&
BlasSubmatrix< _Field>::getWritePointer()
{
return _Mat->getWritePointer()+_off;
}
template <class _Field>
void BlasSubmatrix< _Field>::setEntry (size_t i, size_t j, const Element &a_ij)
{
_Mat->setEntry (_r0 + i, _c0 + j, a_ij);
}
template <class _Field>
typename _Field:: Element &BlasSubmatrix< _Field>::refEntry (size_t i, size_t j)
{
return _Mat->refEntry ( _r0+i, _c0+j );
}
template <class _Field>
const typename _Field:: Element &BlasSubmatrix< _Field>::getEntry (size_t i, size_t j) const
{
return _Mat->getEntry ( _r0+i , _c0+j );
}
template <class _Field>
typename _Field:: Element &BlasSubmatrix< _Field>::getEntry (Element &x, size_t i, size_t j) const
{
return _Mat->getEntry (x, _r0+i , _c0+j );
}
}
///////////////////
// TRANSPOSE &AL //
///////////////////
namespace LinBox
{
}
///////////////////
// ITERATORS //
///////////////////
namespace LinBox
{
/*! Raw Iterators.
* @ingroup iterators
*
* The raw iterator is a method for accessing all entries in the matrix
* in some unspecified order. This can be used, e.g. to reduce all
* matrix entries modulo a prime before passing the matrix into an
* algorithm.
*/
template <class _Field>
class BlasSubmatrix<_Field>::Iterator {
public:
Iterator (){}
/*! @internal
* @brief NO DOC
*/
Iterator (const typename BlasMatrix<_Field>::Iterator& cur,
const size_t c_dim,
const size_t stride,
const size_t c_idx) :
_cur (cur), _c_dim (c_dim), _stride(stride), _c_idx (c_idx)
{}
/*! @internal
* @brief copy operator.
* @param r Iterator to copy.
*/
Iterator& operator = (const Iterator& r)
{
_cur = r._cur;
_c_dim = r._c_dim;
_stride = r._stride;
_c_idx = r._c_idx;
return *this;
}
/*! @internal
* increment.
* ??
*/
Iterator& operator ++()
{
if (_c_idx < _c_dim - 1){
++_cur; ++_c_idx;
}
else {
_cur = _cur + _stride - _c_dim + 1;
_c_idx = 0;
}
return *this;
}
/*! @internal
* increment.
* ??
*/
Iterator& operator++ (int)
{
return this->operator++ ();
}
/*! @internal
* @brief operator !=.
* @param r Iterator to test inequaltity from.
*/
bool operator != (const Iterator& r) const
{
return (_cur != r._cur || _c_dim != r._c_dim) || (_stride != r._stride) || (_c_idx != r._c_idx);
}
//! @internal operator *.
_Field& operator * ()
{
return *_cur;
}
//! @internal operator *.
const _Field& operator * () const
{
return *_cur;
}
protected:
typename BlasMatrix<_Field>::Iterator _cur;
size_t _c_dim;
size_t _stride;
size_t _c_idx;
};
/*! Raw Iterators (const version).
* @ingroup iterators
* The raw iterator is a method for accessing all entries in the matrix
* in some unspecified order. This can be used, e.g. to reduce all
* matrix entries modulo a prime before passing the matrix into an
* algorithm.
*/
template <class _Field>
class BlasSubmatrix<_Field>::ConstIterator {
public:
//! @internal Null constructor
ConstIterator (){}
/*! @internal
* @brief NO DOC
*/
ConstIterator (const typename BlasMatrix<_Field>::ConstIterator& cur,
const size_t c_dim,
const size_t stride,
const size_t c_idx) :
_cur (cur), _c_dim (c_dim), _stride(stride), _c_idx (c_idx)
{}
/*! @internal
* @brief copy operator.
* @param r Iterator to copy.
*/
ConstIterator& operator = (const ConstIterator& r)
{
_cur = r._cur;
_c_dim = r._c_dim;
_stride = r._stride;
_c_idx = r._c_idx;
return *this;
}
/*! @internal
* increment.
* ??
*/
ConstIterator& operator ++()
{
if (_c_idx < _c_dim - 1){
++_cur; ++_c_idx;
}
else {
_cur = _cur + _stride - _c_dim + 1;
_c_idx = 0;
}
return *this;
}
/*! @internal
* increment.
* ??
*/
ConstIterator& operator++ (int)
{
return this->operator++ ();
}
/*! @internal
* @brief operator !=.
* @param r Iterator to test inequaltity from.
*/
bool operator != (const ConstIterator& r) const
{
return (_cur != r._cur) || (_c_dim != r._c_dim) || (_stride != r._stride) || (_c_idx != r._c_idx);
}
//! @internal operator *.
const _Field& operator * () const
{
return *_cur;
}
protected:
typename BlasMatrix<_Field>::ConstIterator _cur;
size_t _c_dim;
size_t _stride;
size_t _c_idx;
};
#if 0
template <class _Field>
class BlasSubmatrix< _Field>::ConstIterator {
public:
ConstIterator (){}
ConstIterator ( const typename BlasMatrix< _Field>::ConstIterator& cur,
size_t cont_len,
size_t gap_len) :
_beg (beg), _cur (cur), _cont_len (cont_len), _gap_len (gap_len)
{}
ConstIterator& operator = (const Iterator& r)
{
_cur = r._cur;
_beg = r._beg;
_cont_len = r._cont_len;
_gap_len = r._gap_len;
return *this;
}
ConstIterator& operator = (const ConstIterator& r)
{
_cur = r._cur;
_beg = r._beg;
_cont_len = r._cont_len;
_gap_len = r._gap_len;
return *this;
}
ConstIterator& operator++()
{
if (((_cur - _beg + 1) % _cont_len) != 0)
++_cur;
else {
_cur = _cur + _gap_len + 1;
_beg = _beg + _gap_len + _cont_len;
}
return *this;
}
ConstIterator operator++(int)
{
ConstIterator tmp = *this;
this->operator++();
return tmp;
}
bool operator != (const ConstIterator& r) const
{
return (_cur != r._cur) || (_beg != r._beg) || (_cont_len != r._cont_len) || (_gap_len != r._gap_len);
}
const _Field& operator*()
{ return *_cur; }
_Field& operator*()
{ return *_cur; }
const _Field& operator*() const
{ return *_cur; }
protected:
typename BlasMatrix< _Field>::ConstIterator _beg;
typename BlasMatrix< _Field>::ConstIterator _cur;
size_t _cont_len;
size_t _gap_len;
};
#endif
template <class _Field>
typename BlasSubmatrix<_Field>::Iterator BlasSubmatrix<_Field>::Begin ()
{
return Iterator (_Mat->Begin () + ( _off ),
_col, _stride, 0);
}
template <class _Field>
typename BlasSubmatrix<_Field>::Iterator BlasSubmatrix<_Field>::End ()
{
return Iterator (_Mat->Begin () + ( (_row) * _stride + _off ),
_col, _stride, 0);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstIterator BlasSubmatrix<_Field>::Begin () const
{
return ConstIterator (_Mat->Begin () + ( _off ),
_col, _stride, 0);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstIterator BlasSubmatrix<_Field>::End () const
{
return ConstIterator (_Mat->Begin () + ( (_row) * _stride + _off ),
_col, _stride, 0);
}
#if 0
template <class _Field>
typename BlasSubmatrix< _Field>::ConstIterator BlasSubmatrix< _Field>::Begin () const
{
return ConstIterator (_Mat->Begin () + ( _off ),
_Mat->Begin () + ( _off ),
_col, _stride - _col);
}
template <class _Field>
typename BlasSubmatrix< _Field>::ConstIterator BlasSubmatrix< _Field>::End () const
{
return ConstIterator (_Mat->Begin () + ( (_row) * _stride + _off ),
_Mat->Begin () + ( (_row) * _stride + _off ),
_col, _stride - _col);
}
#endif
/*! Raw Indexed Iterator.
* @ingroup iterators
*
* Like the raw iterator, the indexed iterator is a method for
* accessing all entries in the matrix in some unspecified order.
* At each position of the the indexed iterator, it also provides
* the row and column indices of the currently referenced entry.
* This is provided through it's \c rowIndex() and \c colIndex() functions.
*/
template <class _Field>
class BlasSubmatrix<_Field>::IndexedIterator {
public:
IndexedIterator (){}
IndexedIterator (const typename BlasMatrix<_Field>::Iterator& cur,
size_t c_dim,
size_t stride,
size_t r_idx,
size_t c_idx) :
_cur (cur), _c_dim (c_dim), _stride (stride), _r_idx(r_idx), _c_idx (c_idx)
{}
IndexedIterator& operator = (const IndexedIterator& r)
{
_cur = r._cur;
_stride = r._stride;
_c_dim = r._c_dim;
_r_idx = r._r_idx;
_c_idx = r._c_idx;
return *this;
}
IndexedIterator& operator++()
{
if (_c_idx < _c_dim - 1){
++_c_idx;
++_cur;
}
else {
_cur = _cur + _stride - _c_dim + 1;
_c_idx = 0;
++_r_idx;
}
return *this;
}
IndexedIterator& operator--()
{
if (_c_idx > 0){
--_c_idx;
--_cur;
}
else {
_cur = _cur - _stride + _c_dim -1;
_c_idx = 0;
--_r_idx;
}
return *this;
}
IndexedIterator operator++(int)
{
IndexedIterator tmp = *this;
this->operator++();
return tmp;
}
IndexedIterator operator--(int)
{
IndexedIterator tmp = *this;
this->operator--();
return tmp;
}
bool operator != (const IndexedIterator& r) const
{
return ((_c_idx != r._c_idx) || (_r_idx != r._r_idx) ||(_stride != r._stride) || (_c_dim != r._c_dim) );
}
const _Field& operator*() const {return *_cur;}
_Field& operator*() {return *_cur;}
size_t rowIndex () const { return _r_idx; }
size_t colIndex () const { return _c_idx; }
const _Field& value () const {return *_cur;}
protected:
typename BlasMatrix<_Field>::Iterator _cur;
size_t _stride;
size_t _c_dim;
size_t _r_idx;
size_t _c_idx;
};
template <class _Field>
typename BlasSubmatrix<_Field>::IndexedIterator BlasSubmatrix<_Field>::IndexedBegin ()
{
return IndexedIterator (_Mat->Begin () + ( (_off) ),
_col , _stride, 0, 0);
}
template <class _Field>
typename BlasSubmatrix<_Field>::IndexedIterator BlasSubmatrix<_Field>::IndexedEnd ()
{
return IndexedIterator (_Mat->Begin () + ( (_row) * _stride + (_col+_off) ),
_col, _stride, _row-1, _col-1);
}
/*! Raw Indexed Iterator (const version).
* @ingroup iterators
*
* Like the raw iterator, the indexed iterator is a method for
* accessing all entries in the matrix in some unspecified order.
* At each position of the the indexed iterator, it also provides
* the row and column indices of the currently referenced entry.
* This is provided through it's \c rowIndex() and \c colIndex() functions.
*/
template <class _Field>
class BlasSubmatrix<_Field>::ConstIndexedIterator {
public:
ConstIndexedIterator (){}
ConstIndexedIterator (const typename BlasMatrix<_Field>::ConstIterator& cur,
size_t c_dim,
size_t stride,
size_t r_idx,
size_t c_idx) :
_cur (cur), _stride (stride), _c_dim (c_dim), _r_idx(r_idx), _c_idx (c_idx)
{}
ConstIndexedIterator& operator = (const IndexedIterator& r)
{
_cur = r._cur;
_stride = r._stride;
_c_dim = r._c_dim;
_r_idx = r._r_idx;
_c_idx = r._c_idx;
return *this;
}
ConstIndexedIterator& operator = (const ConstIndexedIterator& r)
{
_cur = r._cur;
_stride = r._stride;
_c_dim = r._c_dim;
_r_idx = r._r_idx;
_c_idx = r._c_idx;
return *this;
}
ConstIndexedIterator& operator++()
{
if (_c_idx < _c_dim - 1){
++_c_idx;
++_cur;
}
else {
_cur = _cur + _stride - _c_dim +1;
_c_idx = 0;
++_r_idx;
}
return *this;
}
IndexedIterator& operator--()
{
if (_c_idx > 0){
--_c_idx;
--_cur;
}
else {
_cur = _cur - _stride + _c_dim -1;
_c_idx = 0;
--_r_idx;
}
return *this;
}
ConstIndexedIterator operator++(int)
{
ConstIndexedIterator tmp = *this;
this->operator++();
return tmp;
}
ConstIndexedIterator operator--(int)
{
ConstIndexedIterator tmp = *this;
this->operator--();
return tmp;
}
size_t rowIndex () const
{
return _r_idx;
}
size_t colIndex () const
{
return _c_idx;
}
bool operator != (const ConstIndexedIterator& r) const
{
return ((_c_idx != r._c_idx) || (_r_idx != r._r_idx) ||(_stride != r._stride) || (_c_dim != r._c_dim) );
}
const _Field& operator*() const
{
return *_cur;
}
friend std::ostream& operator<<(std::ostream& out, const ConstIndexedIterator m)
{
return out /* << m._cur << ' ' */
<< m._stride << ' '
<< m._c_dim << ' '
<< m._r_idx << ' '
<< m._c_idx;
}
const _Field & value() const
{
return this->operator*();
}
protected:
typename BlasMatrix<_Field>::ConstIterator _cur;
size_t _stride;
size_t _c_dim;
size_t _r_idx;
size_t _c_idx;
};
template <class _Field>
typename BlasSubmatrix<_Field>::ConstIndexedIterator BlasSubmatrix<_Field>::IndexedBegin () const
{
return ConstIndexedIterator (_Mat->Begin () + ( _off ),
_row, _stride, 0, 0);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstIndexedIterator BlasSubmatrix<_Field>::IndexedEnd () const
{
return ConstIndexedIterator (_Mat->Begin () + ( (_row) * _stride + (_off+_col) ),
_col, _stride, _row-1, _col-1);
}
////////
template <class _Field>
typename BlasSubmatrix<_Field>::RowIterator BlasSubmatrix<_Field>::rowBegin ()
{
return RowIterator (_Mat->Begin () + ( _off ),
_col, _stride);
}
template <class _Field>
typename BlasSubmatrix<_Field>::RowIterator BlasSubmatrix<_Field>::rowEnd ()
{
return RowIterator (_Mat->Begin () + ( (_row) * _stride + _off ),
_col, _stride);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstRowIterator BlasSubmatrix<_Field>::rowBegin () const
{
return ConstRowIterator (_Mat->Begin () + ( _off ),
_col, _stride);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstRowIterator BlasSubmatrix<_Field>::rowEnd () const
{
return ConstRowIterator (_Mat->Begin () + ( (_row) * _stride + _off ),
_col, _stride);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ColIterator BlasSubmatrix<_Field>::colBegin ()
{
return ColIterator (_Mat->Begin () + ( _off ),
_stride, _row);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ColIterator BlasSubmatrix<_Field>::colEnd ()
{
return ColIterator (_Mat->Begin () + ( (_col) + _off ),
_stride, _row);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstColIterator BlasSubmatrix<_Field>::colBegin () const
{
return ConstColIterator (_Mat->Begin () + ( _off ),
_stride, _row);
}
template <class _Field>
typename BlasSubmatrix<_Field>::ConstColIterator BlasSubmatrix<_Field>::colEnd () const
{
return ConstColIterator (_Mat->Begin () + ( (_col) + _off ),
_stride, _row);
}
/* operators */
template <class _Field>
typename BlasSubmatrix< _Field>::Row BlasSubmatrix< _Field>::operator[] (size_t i)
{
return Row (_Mat->Begin () + (_r0+i) * _stride, _Mat->Begin () + ((_r0+i) * _stride + _stride) );
}
template <class _Field>
typename BlasSubmatrix< _Field>::ConstRow BlasSubmatrix< _Field>::operator[] (size_t i) const
{
return Row (_Mat->Begin () + (_r0+i) * _stride, _Mat->Begin () + ((_r0+i) * _stride + _stride) );
}
} // LinBox
///////////////////
// I/O //
///////////////////
namespace LinBox
{
template <class _Field>
std::istream& BlasSubmatrix< _Field>::read (std::istream &file)
{
#if 0
Iterator p;
int m,n;
char c;
file>>m>>n>>c;
if (m*n < _row*_col)
cerr<<"NOT ENOUGH ELEMENT TO READ\n";
else {
for (p = Begin (); p != End (); ++p) {
integer tmp;
file>>tmp;cout<<tmp<<endl;
//file.ignore(1);
_Mat->_field.read (file, *p);
}
}
#endif
Iterator p;
int m,n;
char c;
file>>m>>n>>c;
// std::cout << m << 'x' << n << ':' << c << std::endl;
_row = m; _col = n;
_Field zero;
_Mat->_field.init(zero,0UL);
// resize(_row,_col);
if ((c != 'M') && (c != 'm')) {
for (p = Begin (); p != End (); ++p) {
//file.ignore(1);
_Mat->_field.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;
// std::cout << i << ',' << j << ':' ;
_Mat->_field.read (file, _Mat->refEntry(i-1, j-1));
}
}
return file;
}
template <class _Field>
std::ostream &BlasSubmatrix< _Field>::write (std::ostream &os,
enum LinBoxTag::Format f) const
{
ConstRowIterator p;
switch(f) {
case (LinBoxTag::FormatPlain) : /* raw output */
{
integer c;
int wid;
_Mat->_field.cardinality (c);
if (c >0)
wid = (int) ceil (log ((double) c) / M_LN10);
else {
integer tmp;
size_t max=0;
ConstIterator it = Begin();
for (; it != End(); ++it){
_Mat->_field.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);
/*! @warning
* matrix base does not provide this field(), maybe should?
* _Mat.field ().write (os, *pe);
* os << *pe;
* fixed by using extra field
*/
_Mat->_field.write (os, *pe);
os << " ";
}
os << "]" << std::endl;
}
}
break;
case (LinBoxTag::FormatMaple) : /* maple format */
{
os << "Matrix( " << rowdim() << ',' << coldim() << ",[" ;
for (p = rowBegin (); p != rowEnd (); ) {
typename ConstRow::const_iterator pe;
os << " [ ";
for (pe = p->begin (); pe != p->end (); ) {
_Mat->_field.write (os, *pe);
++pe ;
if (pe != p->end())
os << ", ";
}
os << "]" ;
++p ;
if (p != rowEnd() )
os << ',' << std::endl;;
}
os << "])" ;
}
break;
case (LinBoxTag::FormatHTML) : /* HTML format */
{
os << "<table border=\"1\">" ;
for (p = rowBegin (); p != rowEnd (); ) {
typename ConstRow::const_iterator pe;
os << "<tr>";
for (pe = p->begin (); pe != p->end (); ) {
_Mat->_field.write (os<< "<td>", *pe)<<"</td>";
++pe ;
}
os << "</tr>" << std::endl;
++p ;
}
os << "</table>" ;
}
break;
case (LinBoxTag::FormatLaTeX) : /* LaTex format */
{
os << "\\begin{pmatrix} " << std::endl;
for (p = rowBegin (); p != rowEnd (); ) {
typename ConstRow::const_iterator pe;
for (pe = p->begin (); pe != p->end (); ) {
_Mat->_field.write (os, *pe);
++pe ;
if (pe != p->end())
os << "& ";
}
os << "\\\\" << std::endl;
++p ;
}
os << "\\end{pmatrix}" ;
}
break;
default : /* this is an error */
{
throw LinBoxError("unknown format to write matrix in");
}
}
return os;
}
template <class _Field>
template<typename _Tp1>
struct BlasSubmatrix< _Field>::rebind {
typedef BlasMatrix<_Tp1> other;
void operator() (other & Ap, const Self_t& A) {
typedef typename BlasSubmatrix<_Field>::ConstIterator ConstSelfIterator ;
typedef typename other::Iterator OtherIterator ;
OtherIterator Ap_i;
ConstSelfIterator A_i;
Hom<Field, _Tp1> hom(A. field(), Ap. field());
for (A_i = A. Begin(), Ap_i = Ap.Begin();
A_i != A. End(); ++ A_i, ++ Ap_i)
hom.image (*Ap_i, *A_i);
}
};
} // LinBox
//////////////////
// MISC //
//////////////////
namespace LinBox
{
} // LinBox
#endif // __LINBOX_blas_submatrix_INL
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|