21 this->fCols = columns;
22 fMem =
new TObj[Rows*columns];
26 pfinal = &(fMem[Rows*columns]);
27 for (pbeg = fMem; pbeg<pfinal; *pbeg++=0) ;
29 cout <<
"TPZGenMatrix<TObj>.ct-->Cannot create matrix structure\n";
41 fMem =
new TObj[naloc];
44 this->fCols = A.
fCols;
45 TObj *
f = fMem,*l = f+naloc,*fa = A.
fMem;
46 while(f<l) *f++ = *fa++;
55 TObj *sht =
new TObj[newrow*newcol];
57 int64_t minrow = (newrow <
Rows()) ? newrow :
Rows();
58 int64_t mincol = (newcol <
Cols()) ? newcol :
Cols();
59 for(int64_t i=0; i<minrow; i++) {
60 for(int64_t j=0; j<mincol; j++) {
61 sht[i*newcol+j] = (*this)(i,j);
72 if(fMem)
delete []fMem;
81 if(
this == &rval)
return *
this;
84 this->fCols = rval.
fCols;
85 fMem =
new TObj[fRows*this->fCols];
89 pfinal = &(fMem[fRows*this->fCols]);
90 TObj *rvalm = rval.
fMem;
91 for (pbeg = fMem; pbeg<pfinal; pbeg++,rvalm++) *pbeg = *rvalm;
93 cout <<
"TPZGenMatrix<TObj>.= -->Cannot allocate matrix storage\n";
101 if ( (this->fRows != rval.
fRows) || (this->fCols != rval.
fCols) )
102 cout <<
"ERROR-> different TPZGenMatrix<TObj> size for addition";
106 TObj *pbeg1 = this->fMem, *pfin;
107 TObj *pbeg2 = sum.
fMem, *pbeg3 = rval.
fMem;
108 pfin = pbeg1 + (this->fRows*this->fCols);
109 for ( ; pbeg1<pfin; pbeg1++, pbeg2++, pbeg3++)
110 *pbeg2 = *pbeg1 + *pbeg3;
114 template <
class TObj>
119 for (int64_t i=0; i<this->fRows*this->fCols; i++)
120 sum.
fMem[i] = this->fMem[i] + x;
124 template <
class TObj>
129 for (int64_t i=0; i<this->fRows*this->fCols; i++)
130 unaryminus.
fMem[i] = - this->fMem[i];
134 template <
class TObj>
137 if (this->fCols != rval.
fRows)
138 cout <<
"ERROR-> unsuitable TPZGenMatrix<TObj> size for multiplication\n";
143 TObj *ptr = result.
fMem;
144 for (int64_t i=0; i<(this->fRows*this->fCols); i+=this->fCols)
145 for (int64_t j=0; j<rval.
fCols; j++, ptr++)
146 for (int64_t k=0; k<this->fCols; k++)
147 *ptr += this->fMem[i+k] * rval.
fMem[j+k*rval.
fCols];
152 template <
class TObj>
157 for (int64_t i=0; i<this->fRows*this->fCols; i++)
158 result.
fMem[i] = this->fMem[i] * x;
162 template <
class TObj>
165 if ( (this->fRows != rval.
fRows) || (this->fCols != rval.
fCols) )
166 cout <<
"ERROR-> different TPZGenMatrix<TObj> size for addition";
169 TObj *pbeg1 = this->fMem, *pfin;
170 TObj *pbeg3 = rval.
fMem;
171 pfin = pbeg1 + (this->fRows*this->fCols);
172 for ( ; pbeg1<pfin; pbeg1++, pbeg3++)
177 template <
class TObj>
180 for (int64_t i=0; i<this->fRows*this->fCols; i++)
185 template <
class TObj>
188 if ( (this->fRows != rval.
fRows) || (this->fCols != rval.
fCols) )
189 cout <<
"ERROR-> different TPZGenMatrix<TObj> size for addition";
192 TObj *pbeg1 = this->fMem, *pfin;
193 TObj *pbeg3 = rval.
fMem;
194 pfin = pbeg1 + (this->fRows*this->fCols);
195 for ( ; pbeg1<pfin; pbeg1++, pbeg3++)
200 template <
class TObj>
203 for (int64_t i=0; i<this->fRows*this->fCols; i++)
208 template <
class TObj>
211 for (int64_t i=0; i<this->fRows*this->fCols; i++)
216 template <
class TObj>
219 if (i>=0 && i<this->fRows && j>=0 && j<this->fCols)
220 return fMem[i*this->fCols+j];
222 cout <<
"ERROR-> TPZGenMatrix<TObj> index out of range\n" 223 " i = " << i <<
" j = " << j <<
" Rows = " <<
224 this->fRows <<
" columns = " << this->fCols <<
"\n";
233 template <
class TObj>
238 TObj *ptr = this->fMem;
240 for (int64_t i=0; i < this->fRows; i++) {
241 TObj *trp = transp.
fMem + i;
242 for (int64_t j=0; j<this->fCols; j++, ptr++, trp += this->fRows) {
268 template <
class TObj>
272 cout <<
"NULL TPZGenMatrix<TObj>\n";
289 template <
class TObj>
291 if ( (this->fRows != rval.
fRows) || (this->fCols != rval.
fCols) )
292 cout <<
"ERROR-> different TPZGenMatrix<TObj> size for subtraction";
298 TObj *pbeg1 = this->fMem, *pfin;
299 TObj *pbeg2 = sum.
fMem, *pbeg3 = rval.
fMem;
300 pfin = pbeg1 + (this->fRows*this->fCols);
301 for ( ; pbeg1<pfin; pbeg1++, pbeg2++, pbeg3++)
302 *pbeg2 = *pbeg1 - *pbeg3;
306 template <
class TObj>
312 for (int64_t i=0; i<this->fRows*this->fCols; i++)
313 sum.
fMem[i] = this->fMem[i] - x;
TPZGenAMatrix< TObj > & operator*=(const TObj x)
TPZGenAMatrix< TObj > & operator-=(const TPZGenAMatrix< TObj > &rval)
Implements a generic matrix of objects which implement arithmetic operations. Matrix.
void Print(const char *mess, std::ostream &out=std::cout) const
TPZGenMatrix()
Constructor creating Null matrix.
TPZGenAMatrix operator+(const TPZGenAMatrix< TObj > &rval) const
void Resize(const int64_t newrow, const int64_t newcol)
TPZGenAMatrix< TObj > & operator+=(const TPZGenAMatrix< TObj > &rval)
int64_t fRows
Number of rows and columns.
TObj & operator()(const int64_t row, const int64_t column=0) const
#define DebugStop()
Returns a message to user put a breakpoint in.
TPZGenAMatrix operator-() const
int64_t Rows() const
Returns number of rows.
TPZGenAMatrix< TObj > Transpose() const
Implements generic class which holds a matrix of objects. Matrix.
TObj * fMem
Pointer to matrix.
TPZGenMatrix< TObj > & operator=(const TPZGenMatrix< TObj > &rval)
int64_t Cols() const
Returns number of cols.
Contains TPZGenMatrix class which implements generic class which holds a matrix of objects...
TPZGenAMatrix operator*(const TPZGenAMatrix< TObj > &rval) const