10 #define WANT_MATH // include.h will get math fns 26 #define REPORT { static ExeCounter ExeCount(__LINE__,10); ++ExeCount; } 31 static inline int my_min(
int x,
int y) {
return x < y ? x : y; }
32 static inline int my_max(
int x,
int y) {
return x > y ? x : y; }
40 GetMatrix(gmx); CornerClear();
47 lower_val = bw.
lower_val; upper_val = bw.upper_val;
53 Tracer tr(
"BandMatrix::resize");
55 lower_val = (lb<=n) ? lb : n-1; upper_val = (ub<=n) ? ub : n-1;
104 Tracer tr(
"UpperBandMatrix::resize");
116 Tracer tr(
"LowerBandMatrix::resize");
129 Tracer tr(
"BandMatrix::resize(GM)");
183 int i = lower_val;
Real* s = store;
int bw = lower_val + 1 + upper_val;
185 {
int j = i--;
Real* sj = s; s += bw;
while (j--) *sj++ = 0.0; }
186 i = upper_val; s = store + storage;
188 {
int j = i--;
Real* sj = s; s -= bw;
while (j--) *(--sj) = 0.0; }
195 l = (lower_val < 0 || l < 0) ? -1 : (lower_val > l) ? lower_val : l;
196 u = (upper_val < 0 || u < 0) ? -1 : (upper_val > u) ? upper_val : u;
204 l = (lower_val < 0 || l < 0) ? -1 : lower_val+l;
205 u = (upper_val < 0 || u < 0) ? -1 : upper_val+u;
213 if ((lower_val >= 0) && ( (l < 0) || (l > lower_val) )) l = lower_val;
214 if ((upper_val >= 0) && ( (u < 0) || (u > upper_val) )) u = upper_val;
223 GetMatrix(gmx); CornerClear();
238 GetMatrix(gmx); CornerClear();
251 Tracer tr(
"BandLUMatrix");
252 storage2 = 0; store2 = 0; indx = 0;
262 m1 = gm1->
lower_val; m2 = gm1->upper_val;
264 d =
true; sing =
false;
267 storage2 = nrows_val * m1;
278 Tracer et(
"BandLUMatrix::Evaluate");
288 if (tag_val == 0 || tag_val == 1)
291 X.
indx = indx; indx = 0;
292 X.
store2 = store2; store2 = 0;
293 d =
true; sing =
true; storage2 = 0; m1 = 0; m2 = 0;
296 else if (nrows_val == 0)
299 indx = 0; store2 = 0; storage2 = 0;
300 d =
true; sing =
true; m1 = m2 = 0;
306 Tracer tr(
"BandLUMatrix::get_aux");
309 int n = nrows_val;
int* i = ix;
int* j = indx;
310 while(n--) *i++ = *j++;
322 Tracer tr(
"BandLUMatrix(const BandLUMatrix&)");
331 delete []
indx; indx = 0;
358 if (
sing)
return 0.0;
361 if (i)
for (;;) { sum *= *
a;
if (!(--i))
break; a += w; }
379 while (i--) *a++ = 0.0;
385 k = ++j;
while (k--) *a++ = *ai++;
386 k = i--;
while (k--) *a++ = 0.0;
394 for (j=k+1; j<l; j++)
395 { aj += w;
if (fabs(x) < fabs(*aj)) { x = *aj; i = j; } }
397 if (x==0) {
sing =
true;
return; }
401 while (j--) { x = *ak; *ak++ = *ai; *ai++ = x; }
404 for (j=k+1; j<l; j++)
406 *m++ = x = *aj / *
a; i = w;
Real* ak =
a;
407 while (--i) {
Real* aj1 = aj++; *aj1 = *aj - x * *(++ak); }
417 Tracer tr(
"BandLUMatrix::lubksb");
421 for (
int k=0; k<n; k++)
424 if (i!=k) {
Real x=B[k]; B[k]=B[
i]; B[
i]=x; }
427 for (i=k+1; i<l; i++) *(++bi) -= *m++ * *b;
431 for (
int i = n-1;
i>=mini;
i--)
435 int k = l+
m1;
while (k--) x -= *(++
a) * *(++bk);
445 while (i--) *el++ = 0.0;
447 while (i--) *el++ = 0.0;
459 while (i-- > 0) *elx++ = 0.0;
463 while (j-- > 0) *elx++ = 0.0;
465 Real* Ael =
store + (upper_val+1)*(i-1)+1; j = 0;
468 elx = el;
Real sum = 0.0;
int jx = j;
469 while (jx--) sum += *(--Ael) * *(--elx);
470 elx--; *elx = (*elx -
sum) / *(--Ael);
472 if (j<upper_val) Ael -= upper_val - (++j);
else el--;
481 while (i-- > 0) *elx++ = 0.0;
483 int nr = mcout.
skip+mcout.
storage;
int j = nr-
i; i = nr-nc;
484 while (j-- > 0) *elx++ = 0.0;
487 Real* Ael =
store + (lower_val+1)*nc + lower_val;
491 elx = el;
Real sum = 0.0;
int jx = j;
492 while (jx--) sum += *Ael++ * *elx++;
493 *elx = (*elx -
sum) / *Ael++;
495 if (j<lower_val) Ael += lower_val - (++j);
else el++;
510 Real* s =
store + lower_val;
int j = lower_val + 1;
512 if (i)
for (;;) { sum *= *s;
if (!(--i))
break; s += j; }
521 if (i)
for (;;) { sum *= *s;
if (!(--i))
break; s += j; }
555 Tracer tr(
"SymmetricBandMatrix::resize");
557 lower_val = (lb<=n) ? lb : n-1;
567 Tracer tr(
"SymmetricBandMatrix::resize(GM)");
571 if (b != mbw.
Upper())
573 Tracer tr(
"SymmetricBandMatrix::resize(GM)");
622 int i = lower_val;
Real* s =
store;
int bw = lower_val + 1;
627 while (j--) *sj++ = 0.0;
681 {
int j = l;
while (j--) sum2 +=
square(*s++); sum1 +=
square(*s++); }
692 {
int j = l;
while (j--) sum2 += fabs(*s++); sum1 += fabs(*s++); }
703 {
int j = l;
while (j--) sum2 += *s++; sum1 += *s++; }
friend class LowerBandMatrix
void CornerClear() const
set unused parts of BandMatrix to zero
void resize(int, int, int)
resize LowerBandMatrix
void SetParameters(const GeneralMatrix *)
LogAndSign log_determinant() const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
Miscellaneous exception (details in character string).
MatrixBandWidth operator*(const MatrixBandWidth &) const
GeneralMatrix * Image() const
#define MONITOR_INT_DELETE(Operation, Size, Pointer)
virtual void resize(int, int, int)
LogAndSign log_determinant() const
friend class SymmetricBandMatrix
void operator=(const BaseMatrix &)
short SimpleAddOK(const GeneralMatrix *gm)
can we add two symmetric band matrices with simple vector add
GeneralMatrix * Image() const
virtual MatrixType type() const =0
void get_aux(BandLUMatrix &)
void resize(int, int, int)
resize UpperBandMatrix
virtual MatrixBandWidth bandwidth() const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
MatrixBandWidth bandwidth() const
MatrixBandWidth operator+(const MatrixBandWidth &) const
Real sum_absolute_value() const
GeneralMatrix * Image() const
#define MONITOR_INT_NEW(Operation, Size, Pointer)
void Solver(MatrixColX &, const MatrixColX &)
A matrix is not square exception.
void resize(int, int, int)
static int my_max(int x, int y)
LogAndSign log_determinant() const
bool Compare(const MatrixType &, MatrixType &)
#define MONITOR_REAL_DELETE(Operation, Size, Pointer)
void SetParameters(const GeneralMatrix *)
Singular matrix exception.
GeneralMatrix * Transpose(TransposedMatrix *, MatrixType)
friend class UpperBandMatrix
static int my_min(int x, int y)
Base of the matrix classes.
LogAndSign log_determinant() const
void Eq(const BaseMatrix &, MatrixType)
#define MONITOR_REAL_NEW(Operation, Size, Pointer)
void operator=(const BaseMatrix &)
FloatVector FloatVector * a
GeneralMatrix * MakeSolver()
LU decomposition of a band matrix.
GeneralMatrix * MakeSolver()
GeneralMatrix * Image() const
void MatrixErrorNoSpace(const void *)
test for allocation fails
void lubksb(Real *, int=0)
MatrixBandWidth minimum(const MatrixBandWidth &) const
void newmat_block_copy(int n, Real *from, Real *to)
void operator=(const BaseMatrix &)
void Solver(MatrixColX &, const MatrixColX &)
void operator=(const BaseMatrix &)
assignment operator for BandMatrix
The classes for matrices that can contain data are derived from this.
GeneralMatrix * Image() const
void GetMatrix(const GeneralMatrix *)
LogAndSign log_determinant() const
void operator=(const BandLUMatrix &)
short SimpleAddOK(const GeneralMatrix *gm)
can we add two band matrices with simple vector add
void Solver(MatrixColX &, const MatrixColX &)