21 if ((*shares)>1) detach();
35 int rows()
const {
return nrows; }
55 elems=
new X[nrows*ncols];
57 for (
int i=0;i<nrows;i++) mrows[i]=elems+ncols*i;
58 for (
int i=0;i<nrows*ncols;i++) elems[i]=X(0);
64 if (--(*shares))
return;
98 for (
int i=0;i<nrows;i++) {
100 for (;k<nrows&&aux1.mrows[k][i]==X(0);k++);
102 X val=aux1.mrows[k][i];
103 for (
int j=0;j<nrows;j++) {
104 aux1.mrows[k][j]=aux1.mrows[k][j]/val;
108 for (
int j=0;j<nrows;j++) {
109 X tmp=aux1.mrows[k][j];
110 aux1.mrows[k][j]=aux1.mrows[i][j];
111 aux1.mrows[i][j]=tmp;
112 tmp=aux2.
mrows[k][j];
114 aux2.
mrows[i][j]=tmp;
117 for (
int j=0;j<nrows;j++)
119 X tmp=aux1.mrows[j][i];
120 for (
int l=0;l<nrows;l++) {
121 aux1.mrows[j][l]=aux1.mrows[j][l]-tmp*aux1.mrows[i][l];
134 for (
int i=0;i<nrows;i++) {
136 for (;k<nrows&&aux.
mrows[k][i]==X(0);k++);
137 if (k>=nrows)
return X(0);
138 X val=aux.
mrows[k][i];
139 for (
int j=0;j<nrows;j++) {
140 aux.
mrows[k][j]/=val;
144 for (
int j=0;j<nrows;j++) {
145 X tmp=aux.
mrows[k][j];
151 for (
int j=i+1;j<nrows;j++){
152 X tmp=aux.
mrows[j][i];
154 for (
int l=0;l<nrows;l++) {
166 for (
int i=0; i<nrows; i++)
167 for (
int j=0; j<ncols; j++)
168 aux[j][i]=mrows[i][j];
175 for (
int i=0;i<nrows;i++)
176 for (
int j=0;j<m.
ncols;j++){
178 for (
int k=0;k<ncols;k++)
179 a+=mrows[i][k]*m.
mrows[k][j];
188 for (
int i=0;i<nrows*ncols;i++) aux.
elems[i]=elems[i]+m.
elems[i];
195 for (
int i=0;i<nrows*ncols;i++) aux.
elems[i]=elems[i]-m.
elems[i];
201 for (
int i=0;i<nrows*ncols;i++) aux.
elems[i]=elems[i]*e;
207 for (
int i=0;i<nrows*ncols;i++) aux.
elems[i]=elems[i];
213 for (
int i=0;i<
n;i++) aux[i][i]=X(1);
217 template <
class X> std::ostream& operator<<(std::ostream& os, const DMatrix<X> &m) {
219 for (
int i=0;i<m.rows();i++) {
222 for (
int j=0;j<m.columns();j++) {
point< T > operator-(const point< T > &p1, const point< T > &p2)
const X * operator[](int i) const
DMatrix operator+(const DMatrix &) const
point< T > operator*(const point< T > &p, const T &v)
DMatrix operator-(const DMatrix &) const
point< T > operator+(const point< T > &p1, const point< T > &p2)
DMatrix & operator=(const DMatrix &)
DMatrix operator*(const DMatrix &) const
DMatrix(int n=0, int m=0)
DMatrix transpose() const