26 #include "ProtoMatrix.h" 27 #include "BoxConstRef.h" 28 #include "RowConstRef.h" 29 #include "ColumnConstRef.h" 36 template <
class T,
class STO>
40 inline virtual size_t Indice(
const size_t &iRow,
const size_t &iCol)
const 41 {
return iRow*n_columns-n_columns+iCol-1; }
45 typedef std::list<T> lst_T;
46 typedef typename STO::iterator iterator;
47 typedef typename STO::const_iterator const_iterator;
48 typedef typename STO::value_type value_type;
49 typedef typename STO::reference reference;
50 typedef typename STO::const_reference const_reference;
55 TMatrix(
size_t rows= 1,
size_t n_columns= 1);
56 TMatrix(
size_t n_rows,
size_t n_columns,T val);
57 template <
class InputIterator>
58 TMatrix(
const size_t &n_rows,
const size_t &n_columns,InputIterator b,InputIterator e);
64 void resize(
size_t n_rows,
size_t n_columns,T val);
65 inline size_t size(
void)
const 66 {
return STO::size(); }
67 inline const STO &getVector(
void)
const 68 {
return static_cast<const STO &
>(*this); }
70 inline const_reference front()
const 71 {
return STO::front(); }
72 inline reference front()
73 {
return STO::front(); }
74 inline const_reference back()
const 75 {
return STO::back(); }
76 inline reference back()
77 {
return STO::back(); }
78 inline const_iterator begin()
const 79 {
return STO::begin(); }
80 inline iterator begin()
81 {
return STO::begin(); }
82 inline const_iterator end()
const 83 {
return STO::end(); }
85 {
return STO::end(); }
87 virtual reference operator()(
size_t iRow=1,
size_t col=1)
88 {
return STO::operator[](Indice(iRow,col)); }
89 virtual const_reference operator()(
size_t iRow=1,
size_t col=1)
const 90 {
return STO::operator[](Indice(iRow,col)); }
91 virtual reference at(
size_t iRow=1,
size_t col=1)
92 {
return STO::at(Indice(iRow,col)); }
93 virtual const_reference at(
size_t iRow=1,
size_t col=1)
const 94 {
return STO::at(Indice(iRow,col)); }
96 void assign(
size_t row,
size_t col,
const T &value)
97 { STO::assign(Indice(row,col),value); }
98 void swap(
size_t f1,
size_t c1,
size_t f2,
size_t c2)
99 { std::swap((*
this)(f1,c1),(*
this)(f2,c2)); }
107 TMatrix<T,STO> getBox(
size_t f1,
size_t c1,
size_t f2,
size_t c2)
const 109 box_const_ref GetBoxConstRef(
size_t f1,
size_t c1,
size_t f2,
size_t c2)
const 110 {
return box_const_ref(*
this,f1,c1,f2,c2); }
112 {
return box_const_ref(*
this,row_range,column_range); }
113 box_const_ref GetBoxConstRef(
size_t f=1,
size_t c=1)
const 114 {
return box_const_ref(*
this,f,c); }
116 {
return getBox(iRow,1,iRow,n_columns); }
117 row_const_ref getRowConstRef(
size_t f,
size_t c1,
size_t c2)
const 118 {
return row_const_ref(*
this,f,c1,c2); }
119 row_const_ref getRowConstRef(
size_t f,
const RangoIndice &column_range)
const 120 {
return row_const_ref(*
this,f,column_range); }
121 row_const_ref getRowConstRef(
size_t f=1,
size_t c=1)
const 122 {
return row_const_ref(*
this,f,c); }
123 const_ref_col getColumnConstRef(
size_t c,
size_t f1,
size_t f2)
const 124 {
return const_ref_col(*
this,c,f1,f2); }
125 const_ref_col getColumnConstRef(
const RangoIndice &row_range,
size_t c)
const 126 {
return const_ref_col(*
this,row_range,c); }
127 const_ref_col getColumnConstRef(
size_t c=1,
size_t f=1)
const 128 {
return const_ref_col(*
this,c,f); }
130 {
return getBox(1,col,n_rows,col); }
135 if (!compareColumnNumber(*
this,f))
return;
140 if (!compareRowNumber(*
this,c))
return;
147 m.PutCol(n_columns+1,c);
154 m.putRow(n_rows+1,f);
157 void swapRows(
size_t f1,
size_t f2);
158 void swapColumns(
size_t c1,
size_t c2);
159 virtual void Print(std::ostream &)
const;
160 virtual void Input(std::istream &);
161 virtual void Input(
const std::string &);
166 template <
class T,
class STO>
170 template <
class T,
class STO>
174 template <
class T,
class STO>
179 template <
class T,
class STO>
template<
class InputIterator>
183 if(STO::size()!=(n_rows*n_columns))
184 std::cerr <<
"TMatrix; the number of elements of the list" 185 <<
" is not equal to the number of elements of the" 186 <<
" matrix." << std::endl;
191 template <
class T,
class STO>
194 ProtoMatrix::operator=(m);
200 template <
class T,
class STO>
203 ProtoMatrix::resize(n_rows,n_columns);
208 template <
class T,
class STO>
216 retval= ProtoMatrix::operator==(other);
218 retval= this->equal_to(other);
223 template <
class MATR>
224 MATR
GetMenor(
const MATR &matrix,
const size_t &f,
const size_t &c)
226 const size_t fl= matrix.getNumberOfRows();
227 const size_t cl= matrix.getNumberOfColumns();
228 MATR menor(fl-1,cl-1);
230 for(m= m1= 1; m<=fl;m++)
232 if (m == f)
continue;
233 for(p= p1= 1;p<=cl;p++)
235 if (p == c)
continue;
236 menor(m1,p1)= matrix(m,p);
246 template <
class T,
class STO>
248 { return ::GetMenor(*
this,f,c); }
251 template <
class T,
class STO>
254 check_put_box(f,c,box);
255 for(
size_t i=1;i<=box.n_rows;i++)
256 for(
size_t j=1;j<=box.n_columns;j++)
261 template <
class T,
class STO>
262 std::ostream &operator<<(std::ostream &os,const TMatrix<T,STO> &m)
269 template <
class T,
class STO>
272 std::cerr <<
"TMatrix<T,STO>::" << __FUNCTION__
273 <<
" not implemented." << std::endl;
278 template <
class T,
class STO>
281 std::istringstream iss(str);
285 template <
class T,
class STO>
293 inline M traspuesta(
const M &m)
294 {
return m.GetTrn(); }
296 template<
class T,
class STO>
299 orig.check_get_box(f1,c1,f2,c2);
300 for(
size_t i=1;i<=n_rows;i++)
301 for(
size_t j=1;j<=n_columns;j++)
302 (*
this)(i,j)= orig(i+f1-1,j+c1-1);
305 template<
class T,
class STO>
308 for(
size_t i=1;i<=n_rows;i++)
309 for(
size_t j=1;j<=n_columns;j++)
314 template<
class T,
class STO>
318 for(
size_t i=1;i<=n_rows;i++)
319 for(
size_t j=1;j<=n_columns;j++)
320 retval(j,i)= (*this)(i,j);
323 template<
class T,
class STO>
325 {
for(
size_t c=1;c<=n_columns;c++) swap(f1,c,f2,c); }
326 template<
class T,
class STO>
328 {
for(
size_t f=1;f<=n_rows;f++) swap(f,c1,f,c2); }
329 template<
class T,
class STO>
333 const size_t n_rows= getNumberOfRows(),n_columns= getNumberOfColumns();
334 for(
size_t i= 1;i<=n_rows;i++)
337 if(n_columns > 0) os << (*this)(i,1);
338 for(
size_t j= 2;j<=n_columns;j++)
339 os <<
',' << (*
this)(i,j);
344 template<
class T,
class STO>
347 if (!CompDim(*
this,m2))
return false;
348 for(
size_t i=1;i<=n_rows;i++)
349 for(
size_t j=1;j<=n_columns;j++)
350 if ((*
this)(i,j) != m2(i,j))
return false;
360 template <
class MATRV,
class MATRI>
361 MATRV ExtraeValores(
const MATRV &matrix,
const MATRI &row_indexes,
const size_t &icol= 1)
363 MATRV retval(row_indexes.getNumberOfRows(),1);
364 for(
size_t iRow=1;iRow<=retval.getNumberOfRows();iRow++)
365 retval(iRow,1)= matrix(row_indexes(iRow),icol);
Reference to a matrix box.
Definition: BoxConstRef.h:47
Definition: ProtoMatrix.h:32
TMatrix< T, STO > & operator=(const TMatrix< T, STO > &m)
Assignment operator.
Definition: TMatrix.h:192
Constant reference to a column of a matrix.
Definition: ColumnConstRef.h:30
virtual bool operator==(const TMatrix< T, STO > &) const
Comparison operator.
Definition: TMatrix.h:209
void assign(size_t row, size_t col, const T &value)
Put the box int the position (f,c) of this matrix.
Definition: TMatrix.h:96
TMatrix< T, STO > GetMenor(size_t f, size_t c) const
Return the minor of the matrix that corresponds to the row and the column arguments.
Definition: TMatrix.h:247
virtual void Input(std::istream &)
Lectura desde istream.
Definition: TMatrix.h:270
Reference to a matrix row.
Definition: RowConstRef.h:30
void putBox(size_t f, size_t c, const TMatrix< T, STO > &)
Put the box int the position (f,c) of this matrix.
Definition: TMatrix.h:252
void resize(size_t n_rows, size_t n_columns, T val)
Assignment operator.
Definition: TMatrix.h:201
Rango de variación de un índice, se emplea en BoxConstRef.
Definition: RangoIndice.h:30