5 #define WANT_MATH // include.h will get math fns 22 #define REPORT { static ExeCounter ExeCount(__LINE__,10); ++ExeCount; } 27 static inline int my_min(
int x,
int y) {
return x <
y ?
x :
y; }
28 static inline int my_max(
int x,
int y) {
return x >
y ?
x :
y; }
36 GetMatrix(gmx); CornerClear();
43 lower = bw.
lower; upper = bw.upper;
49 Tracer tr(
"BandMatrix::ReSize");
51 lower = (lb<=
n) ? lb :
n-1; upper = (ub<=
n) ? ub :
n-1;
86 Tracer tr(
"UpperBandMatrix::ReSize");
97 Tracer tr(
"LowerBandMatrix::ReSize");
109 Tracer tr(
"BandMatrix::ReSize(GM)");
118 if (Type() !=
A.Type()) {
REPORT return false; }
120 return BandWidth() ==
A.BandWidth();
126 Tracer tr(
"BandMatrix::ReSizeForAdd");
129 | (A_BW.
Upper() < 0))
132 ReSize(
A.Nrows(), my_max(A_BW.
Lower(), B_BW.
Lower()),
139 Tracer tr(
"BandMatrix::ReSizeForSP");
142 | (A_BW.
Upper() < 0))
145 ReSize(
A.Nrows(), my_min(A_BW.
Lower(), B_BW.
Lower()),
161 int i = lower;
Real* s = store;
int bw = lower + 1 + upper;
163 {
int j = i--;
Real* sj = s; s += bw;
while (j--) *sj++ = 0.0; }
164 i = upper; s = store + storage;
166 {
int j = i--;
Real* sj = s; s -= bw;
while (j--) *(--sj) = 0.0; }
173 l = (lower < 0 || l < 0) ? -1 : (lower > l) ? lower : l;
174 u = (upper < 0 || u < 0) ? -1 : (upper > u) ? upper : u;
182 l = (lower < 0 || l < 0) ? -1 : lower+l;
183 u = (upper < 0 || u < 0) ? -1 : upper+u;
191 if ((lower >= 0) && ( (l < 0) || (l > lower) )) l = lower;
192 if ((upper >= 0) && ( (u < 0) || (u > upper) )) u = upper;
201 GetMatrix(gmx); CornerClear();
216 GetMatrix(gmx); CornerClear();
229 Tracer tr(
"BandLUMatrix");
230 storage2 = 0; store2 = 0;
235 d =
true; sing =
false;
238 storage2 = nrows * m1;
249 delete [] indx;
delete [] store2;
258 if (sing)
return 0.0;
261 if (i)
for (;;) { sum *= *a;
if (!(--i))
break; a += w; }
276 Real* a = store2;
int i = storage2;
279 while (i--) *a++ = 0.0;
281 i = m1;
int j = m2;
int k;
int n = nrows;
int w = m1 + 1 + m2;
285 k = ++j;
while (k--) *a++ = *ai++;
286 k = i--;
while (k--) *a++ = 0.0;
289 a = store;
int l = m1;
294 for (j=k+1; j<l; j++)
295 { aj += w;
if (std::fabs(
x) < std::fabs(*aj)) {
x = *aj; i = j; } }
297 if (
x==0) { sing =
true;
return; }
300 d = !d;
Real* ak = a;
Real* ai = store + i * w; j = w;
301 while (j--) {
x = *ak; *ak++ = *ai; *ai++ =
x; }
303 aj = a + w;
Real* m = store2 + m1 * k;
304 for (j=k+1; j<l; j++)
306 *m++ =
x = *aj / *a; i = w;
Real* ak = a;
307 while (--i) {
Real* aj1 = aj++; *aj1 = *aj -
x * *(++ak); }
317 Tracer tr(
"BandLUMatrix::lubksb");
319 int n = nrows;
int l = m1;
int w = m1 + 1 + m2;
321 for (
int k=0; k<
n; k++)
324 if (i!=k) {
Real x=B[k]; B[k]=B[i]; B[i]=
x; }
327 for (i=k+1; i<l; i++) *(++bi) -= *m++ * *b;
331 for (
int i =
n-1; i>=mini; i--)
335 int k = l+m1;
while (k--)
x -= *(++a) * *(++bk);
345 while (i--) *el++ = 0.0;
347 while (i--) *el++ = 0.0;
348 lubksb(el1, mcout.
skip);
359 while (i-- > 0) *elx++ = 0.0;
363 while (j-- > 0) *elx++ = 0.0;
365 Real* Ael = store + (upper+1)*(i-1)+1; j = 0;
368 elx = el;
Real sum = 0.0;
int jx = j;
369 while (jx--) sum += *(--Ael) * *(--elx);
370 elx--; *elx = (*elx - sum) / *(--Ael);
372 if (j<upper) Ael -= upper - (++j);
else el--;
381 while (i-- > 0) *elx++ = 0.0;
383 int nr = mcout.
skip+mcout.
storage;
int j = nr-i; i = nr-nc;
384 while (j-- > 0) *elx++ = 0.0;
386 Real* el = mcin.
data;
Real* Ael = store + (lower+1)*nc + lower; j = 0;
389 elx = el;
Real sum = 0.0;
int jx = j;
390 while (jx--) sum += *Ael++ * *elx++;
391 *elx = (*elx - sum) / *Ael++;
393 if (j<lower) Ael += lower - (++j);
else el++;
407 int i = nrows;
LogAndSign sum;
Real* s = store + lower;
int j = lower + 1;
409 if (i)
for (;;) { sum *= *s;
if (!(--i))
break; s += j; }
416 int i = nrows;
LogAndSign sum;
Real* s = store;
int j = upper + 1;
418 if (i)
for (;;) { sum *= *s;
if (!(--i))
break; s += j; }
438 {
REPORT return Evaluate(mt); }
452 Tracer tr(
"SymmetricBandMatrix::ReSize");
454 lower = (lb<=
n) ? lb :
n-1;
464 Tracer tr(
"SymmetricBandMatrix::ReSize(GM)");
468 if (b != mbw.
Upper())
470 Tracer tr(
"SymmetricBandMatrix::ReSize(GM)");
478 if (Type() !=
A.Type()) {
REPORT return false; }
480 return BandWidth() ==
A.BandWidth();
487 Tracer tr(
"SymmetricBandMatrix::ReSizeForAdd");
492 ReSize(
A.Nrows(), my_max(A_BW.
Lower(), B_BW.
Lower()));
499 Tracer tr(
"SymmetricBandMatrix::ReSizeForSP");
504 ReSize(
A.Nrows(), my_min(A_BW.
Lower(), B_BW.
Lower()));
519 int i = lower;
Real* s = store;
int bw = lower + 1;
524 while (j--) *sj++ = 0.0;
540 Real sum1=0.0;
Real sum2=0.0;
Real* s=store;
int i=nrows;
int l=lower;
542 {
int j = l;
while (j--) sum2 +=
square(*s++); sum1 +=
square(*s++); }
550 Real sum1=0.0;
Real sum2=0.0;
Real* s=store;
int i=nrows;
int l=lower;
552 {
int j = l;
while (j--) sum2 += std::fabs(*s++); sum1 += std::fabs(*s++); }
560 Real sum1=0.0;
Real sum2=0.0;
Real* s=store;
int i=nrows;
int l=lower;
562 {
int j = l;
while (j--) sum2 += *s++; sum1 += *s++; }
Real SumAbsoluteValue() const
void SetParameters(const GeneralMatrix *)
MatrixBandWidth operator*(const MatrixBandWidth &) const
#define MONITOR_INT_DELETE(Operation, Size, Pointer)
LogAndSign LogDeterminant() const
virtual MatrixBandWidth BandWidth() const
void operator=(const BaseMatrix &)
short SimpleAddOK(const GeneralMatrix *gm)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
virtual void ReSize(int, int, int)
void ReSizeForAdd(const GeneralMatrix &A, const GeneralMatrix &B)
#define MONITOR_INT_NEW(Operation, Size, Pointer)
bool SameStorageType(const GeneralMatrix &A) const
void ReSize(int, int, int)
void Solver(MatrixColX &, const MatrixColX &)
void MatrixErrorNoSpace(const void *)
void ReSizeForAdd(const GeneralMatrix &A, const GeneralMatrix &B)
BandLUMatrix(const BaseMatrix &)
LogAndSign LogDeterminant() const
LogAndSign LogDeterminant() const
os2<< "> n<< " > nendobj n
#define MONITOR_REAL_DELETE(Operation, Size, Pointer)
void SetParameters(const GeneralMatrix *)
void ReSize(int, int, int)
GeneralMatrix * Transpose(TransposedMatrix *, MatrixType)
bool SameStorageType(const GeneralMatrix &A) const
void ReSizeForSP(const GeneralMatrix &A, const GeneralMatrix &B)
#define MONITOR_REAL_NEW(Operation, Size, Pointer)
void operator=(const BaseMatrix &)
GeneralMatrix * MakeSolver()
MatrixBandWidth minimum(const MatrixBandWidth &) const
GeneralMatrix * MakeSolver()
void ReSizeForSP(const GeneralMatrix &A, const GeneralMatrix &B)
LogAndSign LogDeterminant() const
LogAndSign LogDeterminant() const
void ReSize(int, int, int)
void lubksb(Real *, int=0)
MatrixBandWidth BandWidth() const
void operator=(const BaseMatrix &)
void Solver(MatrixColX &, const MatrixColX &)
void operator=(const BaseMatrix &)
MatrixBandWidth operator+(const MatrixBandWidth &) const
short SimpleAddOK(const GeneralMatrix *gm)
void Solver(MatrixColX &, const MatrixColX &)