/usr/include/seqan/align/matrix_base.h is in seqan-dev 1.3-1ubuntu2.
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 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | // ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2010, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Andreas Gogol-Doering <andreas.doering@mdc-berlin.de>
// ==========================================================================
// Simple matrices; Used in many alignment algorithms.
// ==========================================================================
#ifndef SEQAN_HEADER_MATRIX_BASE_H
#define SEQAN_HEADER_MATRIX_BASE_H
namespace SEQAN_NAMESPACE_MAIN
{
//////////////////////////////////////////////////////////////////////////////
struct NDimensional;
template <typename TValue, unsigned DIMENSION = 0/*typename TSpec = NDimensional*/>
class Matrix;
//////////////////////////////////////////////////////////////////////////////
template <typename T> struct SizeArr_;
template <typename TValue, unsigned DIMENSION>
struct SizeArr_<Matrix<TValue, DIMENSION> >
{
typedef Matrix<TValue, DIMENSION> TMatrix_;
typedef typename Size<TMatrix_>::Type TSize_;
typedef String<TSize_> Type;
};
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
struct Host<Matrix<TValue, DIMENSION> >
{
typedef String<TValue> Type;
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
.Class.Matrix:
..cat:Miscellaneous
..summary:A simple n-dimensional matrix type.
..signature:Matrix<TValue, unsigned DIMENSION = 0>
..param.TValue:Type of matrix entries.
..param.unsigned DIMENSION:The specializing type (0: NDimensional matrix; 2: two dimensional matrix).
..remarks: The following operators and functions are supported: A*B, A*a, A+B,A-B,<<, transpose
..include:seqan/align.h
*/
template <typename TValue>
class Matrix<TValue, 0>
{
//____________________________________________________________________________
public:
typedef typename Size<Matrix>::Type TSize;
typedef String<TSize> TSizeArr;
typedef String<TValue> THost;
TSizeArr data_lengths; //Length of every dimension
TSizeArr data_factors; //used for positions of dimensions in host ("size of jumps" to get to next entry of specified dimension)
Holder<THost> data_host;
//____________________________________________________________________________
public:
Matrix()
{
create(data_host);
}
Matrix(Matrix const & other_):
data_lengths(other_.data_lengths),
data_factors(other_.data_factors),
data_host(other_.data_host)
{
}
inline Matrix const &
operator = (Matrix const & other_)
{
data_lengths = other_.data_lengths;
data_factors = other_.data_factors;
data_host = other_.data_host;
return *this;
}
~Matrix()
{
}
//____________________________________________________________________________
//____________________________________________________________________________
inline TValue &
operator () (TSize x1, TSize x2)
{
return value(*this, x1, x2);
}
inline TValue &
operator () (TSize x1, TSize x2, TSize x3)
{
return value(*this, x1, x2, x3);
}
inline TValue &
operator () (TSize x1, TSize x2, TSize x3, TSize x4)
{
return value(*this, x1, x2, x3, x4);
}
//____________________________________________________________________________
};
template <typename TValue>
class Matrix<TValue, 2>
{
//____________________________________________________________________________
public:
typedef typename Size<Matrix>::Type TSize;
typedef String<TSize> TSizeArr;
typedef String<TValue> THost;
TSizeArr data_lengths;
TSizeArr data_factors;
Holder<THost> data_host;
//____________________________________________________________________________
public:
Matrix()
{
create(data_host);
//setDimension to 2
resize(data_lengths, 2, 0);
resize(data_factors, 2);
data_factors[0] = 1;
}
Matrix(Matrix const & other_):
data_lengths(other_.data_lengths),
data_factors(other_.data_factors),
data_host(other_.data_host)
{
}
inline Matrix const &
operator = (Matrix const & other_)
{
data_lengths = other_.data_lengths;
data_factors = other_.data_factors;
data_host = other_.data_host;
return *this;
}
~Matrix()
{
}
//____________________________________________________________________________
//____________________________________________________________________________
inline TValue &
operator () (TSize x1, TSize x2)
{
return value(*this, x1, x2);
}
//____________________________________________________________________________
};
template <typename TValue>
class Matrix<TValue, 3>
{
//____________________________________________________________________________
public:
typedef typename Size<Matrix>::Type TSize;
typedef String<TSize> TSizeArr;
typedef String<TValue> THost;
TSizeArr data_lengths;
TSizeArr data_factors;
Holder<THost> data_host;
//____________________________________________________________________________
public:
Matrix()
{
create(data_host);
//setDimension to 3
resize(data_lengths, 3, 0);
resize(data_factors, 3);
data_factors[0] = 1;
}
Matrix(Matrix const & other_):
data_lengths(other_.data_lengths),
data_factors(other_.data_factors),
data_host(other_.data_host)
{
}
inline Matrix const &
operator = (Matrix const & other_)
{
data_lengths = other_.data_lengths;
data_factors = other_.data_factors;
data_host = other_.data_host;
return *this;
}
~Matrix()
{
}
//____________________________________________________________________________
//____________________________________________________________________________
inline TValue &
operator () (TSize x1, TSize x2, TSize x3)
{
return value(*this, x1, x2, x3);
}
//____________________________________________________________________________
};
template <typename TValue, unsigned DIMENSION>
inline typename SizeArr_<Matrix<TValue, DIMENSION> >::Type &
_dataLengths(Matrix<TValue, DIMENSION> & me)
{
return me.data_lengths;
}
template <typename TValue, unsigned DIMENSION>
inline typename SizeArr_<Matrix<TValue, DIMENSION> >::Type const &
_dataLengths(Matrix<TValue, DIMENSION> const & me)
{
return me.data_lengths;
}
template <typename TValue, unsigned DIMENSION>
inline typename SizeArr_<Matrix<TValue, DIMENSION> >::Type &
_dataFactors(Matrix<TValue, DIMENSION> & me)
{
return me.data_factors;
}
template <typename TValue, unsigned DIMENSION>
inline typename SizeArr_<Matrix<TValue, DIMENSION> >::Type &
_dataFactors(Matrix<TValue, DIMENSION> const & me)
{
return me.data_factors;
}
//____________________________________________________________________________
template <typename TValue, unsigned DIMENSION>
inline bool
dependent(Matrix<TValue, DIMENSION> & me)
{
return dependent(me.data_host);
}
//____________________________________________________________________________
template <typename TValue, unsigned DIMENSION, typename THost>
inline void
setHost(Matrix<TValue, DIMENSION> & me, THost & host_)
{
setValue(me.data_host, host_);
}
//____________________________________________________________________________
template <typename TValue, unsigned DIMENSION>
inline typename Host<Matrix<TValue, DIMENSION> >::Type &
host(Matrix<TValue, DIMENSION> & me)
{
return value(me.data_host);
}
template <typename TValue, unsigned DIMENSION>
inline typename Host<Matrix<TValue, DIMENSION> >::Type const &
host(Matrix<TValue, DIMENSION> const & me)
{
return value(me.data_host);
}
//____________________________________________________________________________
template <typename TValue, unsigned DIMENSION, typename THost>
inline void
assignHost(Matrix<TValue, DIMENSION> & me, THost const & value_)
{
assignValue(me.data_host, value_);
}
//____________________________________________________________________________
template <typename TValue, unsigned DIMENSION, typename THost>
inline void
moveHost(Matrix<TValue, DIMENSION> & me, THost const & value_)
{
moveValue(me.data_host, value_);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
struct Value< Matrix<TValue, DIMENSION> >
{
typedef TValue Type;
};
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TIteratorSpec>
struct Iterator< Matrix<TValue, DIMENSION>, TIteratorSpec >
{
typedef Iter<Matrix<TValue, DIMENSION>, PositionIterator> Type;
};
template <typename TValue, unsigned DIMENSION, typename TIteratorSpec>
struct Iterator< Matrix<TValue, DIMENSION> const, TIteratorSpec >
{
typedef Iter<Matrix<TValue, DIMENSION> const, PositionIterator> Type;
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
inline unsigned int
dimension(Matrix<TValue, DIMENSION> & me)
{
return length(_dataLengths(me));
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
inline void
setDimension(Matrix<TValue, DIMENSION> & me,
unsigned int dim_)
{
SEQAN_ASSERT(dim_ > 0)
//std::cout<<"\npress enter1\n";
//std::cin.get();
resize(_dataLengths(me), dim_, 0);
resize(_dataFactors(me), dim_);
_dataFactors(me)[0] = 1;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
inline typename Size<Matrix<TValue, DIMENSION> >::Type
length(Matrix<TValue, DIMENSION> const & me,
unsigned int dim_)
{
return me.data_lengths[dim_];
}
template <typename TValue, unsigned DIMENSION>
inline typename Size<Matrix <TValue, DIMENSION> >::Type
length(Matrix<TValue, DIMENSION> const & me)
{
return length(host(me));
}
template <typename TValue, unsigned DIMENSION>
inline bool empty(Matrix<TValue, DIMENSION> const & me)
{
return empty(host(me));
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TSize>
inline void
setLength(Matrix<TValue, DIMENSION> & me,
unsigned int dim_,
TSize length_)
{
SEQAN_ASSERT(length_ > 0);
SEQAN_ASSERT(dim_ < dimension(me));
_dataLengths(me)[dim_] = length_;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
inline void
resize(Matrix<TValue, DIMENSION> & me)
{
typedef Matrix<TValue, DIMENSION> TMatrix;
typedef typename Size<TMatrix>::Type TSize;
unsigned int dimension_ = dimension(me);
SEQAN_ASSERT(dimension_ > 0);
TSize factor_ = _dataFactors(me)[0] * length(me, 0);
for (unsigned int i = 1; (factor_ > 0) && (i < dimension_); ++i)
{
_dataFactors(me)[i] = factor_;
factor_ *= length(me, i);
}
if (factor_ > 0)
{
resize(host(me), factor_);
}
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TFillValue>
inline void
resize(Matrix<TValue, DIMENSION> & me, TFillValue myValue) //resize the matrix and fill with value
{
typedef Matrix<TValue, DIMENSION> TMatrix;
typedef typename Size<TMatrix>::Type TSize;
unsigned int dimension_ = dimension(me);
SEQAN_ASSERT(dimension_ > 0);
TSize factor_ = _dataFactors(me)[0] * length(me, 0);
for (unsigned int i = 1; (factor_ > 0) && (i < dimension_); ++i)
{
_dataFactors(me)[i] = factor_;
factor_ *= length(me, i);
}
if (factor_ > 0)
resize(host(me), factor_, myValue);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TPosition>
inline typename Position<Matrix <TValue, DIMENSION> >::Type
nextPosition(Matrix<TValue, DIMENSION> & me,
TPosition position_,
unsigned int dimension_)
{
return position_ + _dataFactors(me)[dimension_];
}
template <typename TValue, unsigned DIMENSION, typename TPosition>
inline typename Position<Matrix <TValue, DIMENSION> >::Type
nextPosition(Matrix<TValue, DIMENSION> const & me,
TPosition position_,
unsigned int dimension_)
{
return position_ + _dataFactors(me)[dimension_];
}
template <typename TValue, unsigned DIMENSION, typename TPosition>
inline typename Position<Matrix <TValue, DIMENSION> >::Type
previousPosition(Matrix<TValue, DIMENSION> & me,
TPosition position_,
unsigned int dimension_)
{
return position_ - _dataFactors(me)[dimension_];
}
template <typename TValue, unsigned DIMENSION, typename TPosition>
inline typename Position<Matrix <TValue, DIMENSION> >::Type
previousPosition(Matrix<TValue, DIMENSION> const & me,
TPosition position_,
unsigned int dimension_)
{
return position_ - _dataFactors(me)[dimension_];
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TPosition>
inline typename Size< Matrix <TValue, DIMENSION> >::Type
coordinate(Matrix<TValue, DIMENSION> & me,
TPosition position_,
unsigned int dimension_)
{
SEQAN_ASSERT(dimension_ < dimension(me));
if (dimension_ < dimension(me) - 1)
{
return (position_ / _dataFactors(me)[dimension_]) % _dataFactors(me)[dimension_ + 1];
}
else
{
return position_ / _dataFactors(me)[dimension_];
}
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TTag>
inline typename Iterator<Matrix <TValue, DIMENSION>, Tag<TTag> const>::Type
begin(Matrix<TValue, DIMENSION> & me,
Tag<TTag> const)
{
return typename Iterator<Matrix <TValue, DIMENSION>, Tag<TTag> const >::Type(me, 0);
}
template <typename TValue, unsigned DIMENSION, typename TTag>
inline typename Iterator<Matrix <TValue, DIMENSION> const, Tag<TTag> const>::Type
begin(Matrix<TValue, DIMENSION> const & me,
Tag<TTag> const)
{
return typename Iterator<Matrix <TValue, DIMENSION> const, Tag<TTag> const >::Type(me, 0);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TTag>
inline typename Iterator<Matrix <TValue, DIMENSION>, Tag<TTag> const >::Type
end(Matrix<TValue, DIMENSION> & me,
Tag<TTag> const)
{
return typename Iterator<Matrix <TValue, DIMENSION>, Tag<TTag> const >::Type(me, length(host(me)));
}
template <typename TValue, unsigned DIMENSION, typename TTag>
inline typename Iterator<Matrix <TValue, DIMENSION> const, Tag<TTag> const >::Type
end(Matrix<TValue, DIMENSION> const & me,
Tag<TTag> const)
{
return typename Iterator<Matrix <TValue, DIMENSION>, Tag<TTag> const >::Type(me, length(host(me)));
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TPosition>
inline typename Reference<Matrix<TValue, DIMENSION> >::Type
value(Matrix<TValue, DIMENSION> & me,
TPosition position_)
{
return value(host(me), position_);
}
//____________________________________________________________________________
//two dimensional value access
template <typename TValue, unsigned DIMENSION, typename TOrdinate1, typename TOrdinate2>
inline typename Reference<Matrix<TValue, DIMENSION> >::Type
value(Matrix<TValue, DIMENSION> & me,
TOrdinate1 i1,
TOrdinate2 i2)
{
return value(host(me), i1 + i2 * _dataFactors(me)[1]);
}
//____________________________________________________________________________
//3 dimensional value access
template <typename TValue, unsigned DIMENSION, typename TOrdinate1, typename TOrdinate2, typename TOrdinate3>
inline typename Reference<Matrix<TValue, DIMENSION> >::Type
value(Matrix<TValue, DIMENSION> & me,
TOrdinate1 i1,
TOrdinate2 i2,
TOrdinate3 i3)
{
return value(host(me), i1 + i2 * _dataFactors(me)[1] + i3 * _dataFactors(me)[2]);
}
//____________________________________________________________________________
//4 dimensional value access
template <typename TValue, unsigned DIMENSION, typename TOrdinate1, typename TOrdinate2, typename TOrdinate3, typename TOrdinate4>
inline typename Reference<Matrix<TValue, DIMENSION> >::Type
value(Matrix<TValue, DIMENSION> & me,
TOrdinate1 i1,
TOrdinate2 i2,
TOrdinate3 i3,
TOrdinate4 i4)
{
return value(host(me), i1 + i2 * _dataFactors(me)[1] + i3 * _dataFactors(me)[2] + i4 * _dataFactors(me)[3]);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// Iterator: goNext
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
inline void
goNext(Iter<Matrix<TValue, DIMENSION>, PositionIterator> & me,
unsigned int dimension_)
{
setPosition(me, nextPosition(container(me), position(me), dimension_));
}
template <typename TValue, unsigned DIMENSION>
inline void
goNext(Iter<Matrix<TValue, DIMENSION> const, PositionIterator> & me,
unsigned int dimension_)
{
setPosition(me, nextPosition(container(me), position(me), dimension_));
}
template <typename TValue, unsigned DIMENSION>
inline void
goNext(Iter<Matrix<TValue, DIMENSION>, PositionIterator> & me)
{
goNext(me, 0);
}
template <typename TValue, unsigned DIMENSION>
inline void
goNext(Iter<Matrix<TValue, DIMENSION> const, PositionIterator> & me)
{
goNext(me, 0);
}
//////////////////////////////////////////////////////////////////////////////
// Iterator: goPrevious
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION>
inline void
goPrevious(Iter< Matrix<TValue, DIMENSION>, PositionIterator > & me,
unsigned int dimension_)
{
setPosition(me, previousPosition(container(me), position(me), dimension_));
}
template <typename TValue, unsigned DIMENSION>
inline void
goPrevious(Iter< Matrix<TValue, DIMENSION> const, PositionIterator > & me,
unsigned int dimension_)
{
setPosition(me, previousPosition(container(me), position(me), dimension_));
}
template <typename TValue, unsigned DIMENSION>
inline void
goPrevious(Iter< Matrix<TValue, DIMENSION>, PositionIterator > & me)
{
goPrevious(me, 0);
}
template <typename TValue, unsigned DIMENSION>
inline void
goPrevious(Iter< Matrix<TValue, DIMENSION> const, PositionIterator > & me)
{
goPrevious(me, 0);
}
//////////////////////////////////////////////////////////////////////////////
// goTo
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, unsigned DIMENSION, typename TPosition0, typename TPosition1>
inline void
goTo(Iter<Matrix<TValue, DIMENSION>, PositionIterator> & me, TPosition0 pos0, TPosition1 pos1)
{
setPosition(me, pos0 + pos1 * _dataFactors(container(me))[1]);
}
template <typename TValue, unsigned DIMENSION, typename TPosition0, typename TPosition1>
inline void
goTo(Iter<Matrix<TValue, DIMENSION> const, PositionIterator> & me, TPosition0 pos0, TPosition1 pos1)
{
setPosition(me, pos0 + pos1 * _dataFactors(container(me))[1]);
}
template <typename TValue, unsigned DIMENSION, typename TPosition0, typename TPosition1, typename TPosition2>
inline void
goTo(Iter<Matrix<TValue, DIMENSION>, PositionIterator> & me, TPosition0 pos0, TPosition1 pos1, TPosition2 pos2)
{
setPosition(me, pos0 + pos1 * _dataFactors(container(me))[1] + pos2 * _dataFactors(container(me))[2]);
}
template <typename TValue, unsigned DIMENSION, typename TPosition0, typename TPosition1, typename TPosition2>
inline void
goTo(Iter<Matrix<TValue, DIMENSION> const, PositionIterator> & me, TPosition0 pos0, TPosition1 pos1, TPosition2 pos2)
{
setPosition(me, pos0 + pos1 * _dataFactors(container(me))[1] + pos2 * _dataFactors(container(me))[2]);
}
//////////////////////////////////////////////////////////////////////////////
// Iterator: coordinate
template <typename TValue, unsigned DIMENSION>
inline typename Size< Matrix<TValue, DIMENSION> >::Type
coordinate(Iter<Matrix<TValue, DIMENSION>, PositionIterator > & me,
unsigned int dimension_)
{
return coordinate(container(me), position(me), dimension_);
}
template <typename TValue, unsigned DIMENSION>
inline typename Size< Matrix<TValue, DIMENSION> >::Type
coordinate(Iter<Matrix<TValue, DIMENSION> const, PositionIterator > & me,
unsigned int dimension_)
{
return coordinate(container(me), position(me), dimension_);
}
/*
operator +
Computes the matricial sum between two matrices
..signature:Matrix +(matrix1,matrix2)
..param.matrix1:The first matrix.
...type:Class.Matrix
..param.matrix2:The second matrix.
...type:Class.Matrix
..returns:The sum of the two matrices (another nxm matrix).
..remarks:The number of rows and columns of matrix1 must be equal to the number of rows and columns of matrix2 (length of dimensions for NDimensional matrices)
*/
template <typename TValue,unsigned DIMENSION>
Matrix<TValue,DIMENSION>
operator + (Matrix<TValue,DIMENSION> const & matrix1,Matrix<TValue,DIMENSION> const & matrix2)
{
//the two matrices must have same dimension
SEQAN_ASSERT(_dataLengths(matrix1)==_dataLengths(matrix2));
Matrix<TValue,DIMENSION> result;
//copy the first matrix
setDimension(result,length(_dataLengths(matrix1)));
_dataLengths(result) = _dataLengths(matrix1);
resize(result);
//add the matrices
for(unsigned int i = 0;i< length(host(result));++i)
{
value(host(result), i)=value(host(matrix1), i)+value(host(matrix2), i);
}
//Return matrix sum
return result;
}
template <typename TValue,unsigned DIMENSION>
Matrix<TValue,DIMENSION>
operator - (Matrix<TValue,DIMENSION> const & matrix1,Matrix<TValue,DIMENSION> const & matrix2)
{
//the two matrices must have same dimension
SEQAN_ASSERT(_dataLengths(matrix1)==_dataLengths(matrix2))
Matrix<TValue,DIMENSION> result;
//resize the matrix
setDimension(result,length(_dataLengths(matrix1)));
_dataLengths(result) = _dataLengths(matrix1);
resize(result);
//subtract the matrices
for(unsigned int i = 0;i< length(host(result));++i)
{
value(host(result), i)=value(host(matrix1), i)-value(host(matrix2), i);
}
//Return matrix difference
return result;
}
template <typename TValue>
Matrix<TValue, 2>
operator * (Matrix<TValue, 2> const & matrix1, Matrix<TValue, 2> const & matrix2)
{
SEQAN_ASSERT(length(matrix1,1) == length(matrix2,0))
unsigned int nrow1=length(matrix1,0);
unsigned int ncol2=length(matrix2,1);
Matrix<TValue, 2> result;
//resize the matrix
setLength(result, 0, nrow1);
setLength(result, 1, ncol2);
resize(result,(TValue) 0);
//Matrix product
for(unsigned int row = 0; row < nrow1; row++)
{
for(unsigned int col = 0; col < ncol2; col++)
{
for(unsigned int colRes = 0; colRes < length(matrix1,1); colRes++)
{
value(result,row,col)+= value(host(matrix1), row + colRes * matrix1.data_factors[1])*value(host(matrix2), colRes + col * matrix2.data_factors[1]);
}
}
}
//return the matrix product
return result;
}
template <typename TValue>
Matrix<TValue, 2>
operator * (TValue const & scalar, Matrix<TValue, 2> const & matrix)
{
Matrix<TValue, 2> result;
result= matrix;
//scalar multiplication
for(unsigned int i = 0;i< length(host(result));++i)
{
value(host(result), i)*=scalar;
}
//return the matrix product
return result;
}
template <typename TValue>
Matrix<TValue, 2>
operator * (Matrix<TValue, 2> const & matrix, TValue const & scalar)
{
Matrix<TValue, 2> result;
result= matrix;
//scalar multiplication
for(unsigned int i = 0;i< length(host(result));++i)
{
value(host(result), i)*=scalar;
}
//return the matrix product
return result;
}
template <typename TValue, unsigned DIMENSION1, unsigned DIMENSION2>
bool
operator == (Matrix<TValue, DIMENSION1> const & matrix1, Matrix<TValue, DIMENSION2> const & matrix2)
{
bool result;
result= (matrix1.data_lengths==matrix2.data_lengths)&&(matrix1.data_factors==matrix2.data_factors)&&(value(matrix1.data_host)==value(matrix2.data_host))&&(DIMENSION1==DIMENSION2);
return result;
}
/*
.Function.matricialSum:
..summary:Computes the matricial sum between two nxm matrixes
..signature:matricialSum(matrix1,matrix2)
..param.matrix1:The first matrix.
...type:Matrix<TValue, 2>&
..param.matrix2:The second matrix.
...type:Matrix<TValue, 2>&
..returns:The sum of the two matrices (another nxm matrix).
..remarks:The number of rows and columns of matrix1 must be equal to the number of rows and columns of matrix2.
..include:seqan/align.h
*/
/*
template <typename TValue>
Matrix<TValue,2>
matricialSum(Matrix<TValue,2> &matrix1,Matrix<TValue,2> &matrix2)
{
//the two matrices must have same dimension
if(length(matrix1,0) != length(matrix2,0)||length(matrix1,1) != length(matrix2,1))
{
fprintf(stderr,"Error: The two matrices have different dimensions");
}
unsigned int nrow=length(matrix1,0);
unsigned int ncol=length(matrix1,1);
Matrix<TValue,2> result;
//resize the matrix
setLength(result, 0, nrow);
setLength(result, 1, ncol);
resize(result);
//add the matrices
for(unsigned int i = 0;i< nrow*ncol;++i)
{
value(host(result), i)=value(host(matrix1), i)+value(host(matrix2), i);
}
//Return matrix difference
return result;
}
*/
//////////////////////////////////////////////////////////////////////////////
// _matricialDifference
//////////////////////////////////////////////////////////////////////////////
/*
.Function.matricialDifference:
..summary:Computes the matricial difference between two matrixes
..signature:matricialDifference(matrix1,matrix2)
..param.matrix1:The first matrix.
...type:Matrix<TValue, 2>&
..param.matrix2:The second matrix.
...type:Matrix<TValue, 2>&
..returns:The difference of the two matrices (another matrix).
..remarks:The number of rows and columns of matrix1 must be equal to the number of rows and columns of matrix2.
..include:seqan/align.h
*/
/*
template <typename TValue>
inline Matrix<TValue,2>
matricialDifference(Matrix<TValue,2> & matrix1, Matrix<TValue,2> & matrix2)
{
//the two matrices must have same dimension
if(length(matrix1,0) != length(matrix2,0)||length(matrix1,1) != length(matrix2,1))
{
fprintf(stderr,"Error: The two matrices have different dimensions");
}
unsigned int nrow=length(matrix1,0);
unsigned int ncol=length(matrix1,1);
Matrix<TValue,2> result;
//resize the matrix
//setDimension(result, 2);
setLength(result, 0, nrow);
setLength(result, 1, ncol);
resize(result);
//Substract the matrices
for(unsigned int i1 = 0;i1< nrow;++i1)
{
for(unsigned int i2 = 0;i2<ncol;++i2)
{
value(host(result), i1 + i2 * _dataFactors(result)[1])=value(host(matrix1), i1 + i2 * _dataFactors(matrix1)[1])-value(host(matrix2), i1 + i2 * _dataFactors(matrix2)[1]);
}
}
//Return matrix difference
return result;
}
*/
/*
.Function.matricialProduct:
..summary:Computes the matricial product between two 2-dimensional matrixes
..signature:matricialProduct(matrix1,matrix2)
..param.matrix1:The first matrix (mxn).
...type:Matrix<TValue,2>&
..param.matrix2:The second matrix (nxp).
...type:Matrix<TValue,2>&
..returns:The products of the two matrices (another matrix, mxp).
..remarks:The number of columns of matrix1 (left matrix) must be equal to the number of rows of matrix2(right matrix).
..include:seqan/align.h
*/
/*
template <typename TValue>
inline Matrix<TValue, 2>
matricialProduct(Matrix<TValue, 2> &matrix1,
Matrix<TValue, 2> &matrix2)
{
//SEQAN_ASSERT(dimension_ < dimension(me));
if(length(matrix1,1) != length(matrix2,0))
{
fprintf(stderr,"Error: Number of columns of matrix1 is unequal to number of rows of matrix2");
}
unsigned int nrow1=length(matrix1,0);
unsigned int ncol2=length(matrix2,1);
Matrix<TValue, 2> result;
//resize the matrix
setLength(result, 0, nrow1);
setLength(result, 1, ncol2);
resize(result,(TValue) 0);
//Matrix product
for(unsigned int row = 0; row < nrow1; row++)
{
for(unsigned int col = 0; col < ncol2; col++)
{
for(unsigned int colRes = 0; colRes < length(matrix1,1); colRes++)
{
value(result,row,col)+=value(matrix1, row,colRes)*value(matrix2,colRes,col);
}
}
}
//return the matrix product
return result;
}
*/
// TODO(holtgrew): Should work as the graph-transpose.
/**
.Function.transpose:
..Xsummary:Transposes matrix
..signature:Matrix transpose(matrix)
..param.matrix:The matrix (mxn) to transpose.
...type:Class.Matrix
...remarks: must be of type Matrix<TValue,2> (two dimensional)
..returns:Transposed matrix
..remarks:Only works on two dimensional matrices
..include:seqan/align.h
*/
template <typename TValue>
Matrix<TValue,2>
transpose(Matrix<TValue,2> const & matrix)
{
unsigned int nrow=length(matrix,0);
unsigned int ncol=length(matrix,1);
Matrix<TValue,2> result;
//resize the matrix
setLength(result, 0, ncol);
setLength(result, 1, nrow);
resize(result);
for(unsigned int i1 = 0;i1< nrow;++i1)
{
for(unsigned int i2 = 0;i2<ncol;++i2)
{
value(host(result), i2 + i1 * _dataFactors(result)[1])=value(host(matrix), i1 + i2 * matrix.data_factors[1]);
}
}
//Return transposed matrix
return result;
}
template < typename TValue >
::std::ostream& operator<<(::std::ostream &out, const Matrix<TValue,2> &matrix)
{
for(unsigned int i1 = 0;i1< matrix.data_lengths[0];++i1)
{
for(unsigned int i2 = 0;i2<(matrix.data_lengths[1]-1);++i2)
{
out<<value(host(matrix), i1 + i2 * matrix.data_factors[1])<<"\t";
}
//Last line is followd by \n instead of \t
out<<value(host(matrix), i1 + (matrix.data_lengths[1]-1) *matrix.data_factors[1])<<"\n";
}
return out;
}
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///// READ
/*
* TODO(goeke) only square matrices of fixed size can be read in...
*/
///////////////////////////////////////////////////////////////
// template < typename TValue >
// void read(FILE *file, Matrix<TValue,2> & matrix)
// {
// //unsigned int column_size=3;
// unsigned int column_size=pow(4,5);
// //read the transition matrix
// setLength(matrix, 0, column_size);
// setLength(matrix, 1, column_size);
// resize(matrix,0.0);
// for(unsigned int row=0; row<column_size; row++)
// {
// for(unsigned int col=0; col<column_size; col++)
// {
// fscanf(file,"%lf ", & value(matrix, row,col));
// }
// fscanf(file,"\n");
// }
// }
}// namespace SEQAN_NAMESPACE_MAIN
#endif //#ifndef SEQAN_HEADER_...
|