| 1 |
/*! \file ColumnMatrix.hpp |
| 2 |
\brief Rectangular matrix view as a set of column vectors |
| 3 |
\author Xavier Juvigny, ONERA |
| 4 |
\date Jan. 19th 2005 |
| 5 |
\modification allocation of array by STL vector class |
| 6 |
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions |
| 7 |
\date Jun. 11th 2013 |
| 8 |
\date Jul. 12th 2015 |
| 9 |
\date Nov. 30th 2016 |
| 10 |
*/ |
| 11 |
|
| 12 |
// This file is part of Dissection |
| 13 |
// |
| 14 |
// Dissection is free software: you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation, either version 3 of the License, or |
| 17 |
// (at your option) any later version. |
| 18 |
// |
| 19 |
// Linking Dissection statically or dynamically with other modules is making |
| 20 |
// a combined work based on Disssection. Thus, the terms and conditions of |
| 21 |
// the GNU General Public License cover the whole combination. |
| 22 |
// |
| 23 |
// As a special exception, the copyright holders of Dissection give you |
| 24 |
// permission to combine Dissection program with free software programs or |
| 25 |
// libraries that are released under the GNU LGPL and with independent modules |
| 26 |
// that communicate with Dissection solely through the Dissection-fortran |
| 27 |
// interface. You may copy and distribute such a system following the terms of |
| 28 |
// the GNU GPL for Dissection and the licenses of the other code concerned, |
| 29 |
// provided that you include the source code of that other code when and as |
| 30 |
// the GNU GPL requires distribution of source code and provided that you do |
| 31 |
// not modify the Dissection-fortran interface. |
| 32 |
// |
| 33 |
// Note that people who make modified versions of Dissection are not obligated |
| 34 |
// to grant this special exception for their modified versions; it is their |
| 35 |
// choice whether to do so. The GNU General Public License gives permission to |
| 36 |
// release a modified version without this exception; this exception also makes |
| 37 |
// it possible to release a modified version which carries forward this |
| 38 |
// exception. If you modify the Dissection-fortran interface, this exception |
| 39 |
// does not apply to your modified version of Dissection, and you must remove |
| 40 |
// this exception when you distribute your modified version. |
| 41 |
// |
| 42 |
// This exception is an additional permission under section 7 of the GNU |
| 43 |
// General Public License, version 3 ("GPLv3") |
| 44 |
// |
| 45 |
// Dissection is distributed in the hope that it will be useful, |
| 46 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 47 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 48 |
// GNU General Public License for more details. |
| 49 |
// |
| 50 |
// You should have received a copy of the GNU General Public License |
| 51 |
// along with Dissection. If not, see <http://www.gnu.org/licenses/>. |
| 52 |
// |
| 53 |
|
| 54 |
#ifndef _ALGEBRA_COLUMNMATRIX_HPP |
| 55 |
# define _ALGEBRA_COLUMNMATRIX_HPP |
| 56 |
|
| 57 |
# include "Algebra/PlainMatrix.hpp" |
| 58 |
|
| 59 |
template<typename T> |
| 60 |
class ColumnMatrix : public PlainMatrix<T> |
| 61 |
{ |
| 62 |
public: |
| 63 |
|
| 64 |
using PlainMatrix<T>::coefs; |
| 65 |
using PlainMatrix<T>::addrCoefs; |
| 66 |
using PlainMatrix<T>::addrCoefs_pt; |
| 67 |
|
| 68 |
ColumnMatrix() : PlainMatrix<T>(), _nrows(0), _ncols(0) |
| 69 |
{} |
| 70 |
|
| 71 |
ColumnMatrix(int nrows, int ncols) : |
| 72 |
PlainMatrix<T>(), _nrows(0), _ncols(0) |
| 73 |
{ init(nrows, ncols); } |
| 74 |
|
| 75 |
ColumnMatrix(int nrows, int ncols, T* coefs, bool isOwner) : |
| 76 |
PlainMatrix<T>(isOwner), _nrows(0), _ncols(0) |
| 77 |
{ init(nrows, ncols, coefs, isOwner); } |
| 78 |
|
| 79 |
void init(int nrows, int ncols, bool later_allocation = false) |
| 80 |
{ |
| 81 |
_nrows = nrows; |
| 82 |
_ncols = ncols; |
| 83 |
if (!later_allocation) { |
| 84 |
PlainMatrix<T>::init((_nrows * _ncols)); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
void init(int nrows, int ncols, T* cfs, bool isOwner) |
| 89 |
{ |
| 90 |
_nrows = nrows; |
| 91 |
_ncols = ncols; |
| 92 |
PlainMatrix<T>::init((_nrows * _ncols), cfs, isOwner); |
| 93 |
} |
| 94 |
|
| 95 |
void allocate() |
| 96 |
{ |
| 97 |
PlainMatrix<T>::init((_nrows * _ncols)); |
| 98 |
} |
| 99 |
|
| 100 |
~ColumnMatrix() { } |
| 101 |
|
| 102 |
int nbColumns() const { return _ncols; } |
| 103 |
int nbRows() const { return _nrows; } |
| 104 |
int size() const { return _ncols * _nrows; } |
| 105 |
|
| 106 |
virtual T& operator () (int i, int j) |
| 107 |
{ |
| 108 |
# ifdef DISDEBUG |
| 109 |
assert(int(i) < nbRows()); |
| 110 |
assert(int(j) < nbColumns()); |
| 111 |
#endif |
| 112 |
return coefs()[i + j * _nrows]; |
| 113 |
} |
| 114 |
|
| 115 |
virtual const T& operator () (int i, int j) const |
| 116 |
{ |
| 117 |
# ifdef DISDEBUG |
| 118 |
assert(int(i) < nbRows()); |
| 119 |
assert(int(j) < nbColumns()); |
| 120 |
#endif |
| 121 |
return coefs()[i + j * _nrows]; |
| 122 |
} |
| 123 |
|
| 124 |
void ZeroClear() |
| 125 |
{ |
| 126 |
PlainMatrix<T>::ZeroClear(); |
| 127 |
} |
| 128 |
|
| 129 |
virtual ColumnMatrix<T>* clone() const |
| 130 |
{ |
| 131 |
ColumnMatrix<T> *ret=new ColumnMatrix<T>; |
| 132 |
ret->copy(*this); |
| 133 |
return(ret); |
| 134 |
} |
| 135 |
/// \brief Deep copy of B |
| 136 |
void copy(const ColumnMatrix<T>& B) |
| 137 |
{ |
| 138 |
_nrows=B._nrows; |
| 139 |
_ncols=B._ncols; |
| 140 |
PlainMatrix<T>::copy(B); |
| 141 |
} |
| 142 |
|
| 143 |
void free() |
| 144 |
{ |
| 145 |
PlainMatrix<T>::free(); |
| 146 |
_nrows = 0; |
| 147 |
_ncols = 0; |
| 148 |
} |
| 149 |
|
| 150 |
private: |
| 151 |
ColumnMatrix(const ColumnMatrix& A); |
| 152 |
ColumnMatrix& operator = (const ColumnMatrix& A); |
| 153 |
int _nrows; |
| 154 |
int _ncols; |
| 155 |
}; |
| 156 |
|
| 157 |
#endif |