source: ntrip/trunk/BNC/newmat/bandmat.cpp@ 10802

Last change on this file since 10802 was 10791, checked in by mervart, 6 months ago

BNC Multifrequency and PPPAR Client (initial version)

File size: 19.0 KB
RevLine 
[9434]1/// \ingroup newmat
2///@{
3
4/// \file bandmat.cpp
5/// Band-matrix member functions.
6
7
8// Copyright (C) 1991,2,3,4,9: R B Davies
9
10#define WANT_MATH // include.h will get math fns
11
12//#define WANT_STREAM
13
14#include "include.h"
15
16#include "newmat.h"
17#include "newmatrc.h"
18
19#ifdef use_namespace
20namespace NEWMAT {
21#endif
22
23
24
25#ifdef DO_REPORT
26#define REPORT { static ExeCounter ExeCount(__LINE__,10); ++ExeCount; }
27#else
28#define REPORT {}
29#endif
30
[10791]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; }
[9434]33
34
35BandMatrix::BandMatrix(const BaseMatrix& M)
36{
37 REPORT // CheckConversion(M);
38 // MatrixConversionCheck mcc;
39 GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::BM);
40 GetMatrix(gmx); CornerClear();
41}
42
43void BandMatrix::SetParameters(const GeneralMatrix* gmx)
44{
45 REPORT
46 MatrixBandWidth bw = gmx->bandwidth();
47 lower_val = bw.lower_val; upper_val = bw.upper_val;
48}
49
50void BandMatrix::resize(int n, int lb, int ub)
51{
52 REPORT
53 Tracer tr("BandMatrix::resize");
54 if (lb<0 || ub<0) Throw(ProgramException("Undefined bandwidth"));
55 lower_val = (lb<=n) ? lb : n-1; upper_val = (ub<=n) ? ub : n-1;
56 GeneralMatrix::resize(n,n,n*(lower_val+1+upper_val)); CornerClear();
57}
58
59// SimpleAddOK shows when we can add etc two matrices by a simple vector add
60// and when we can add one matrix into another
61//
62// *gm must be the same type as *this
63// - return 0 if simple add is OK
64// - return 1 if we can add into *gm only
65// - return 2 if we can add into *this only
66// - return 3 if we can't add either way
67//
68// For SP this will still be valid if we swap 1 and 2
69
70/// \brief can we add two band matrices with simple vector add
71///
72/// For band matrices the bandwidths must agree
73
74short BandMatrix::SimpleAddOK(const GeneralMatrix* gm)
75{
76 const BandMatrix* bm = (const BandMatrix*)gm;
77 if (bm->lower_val == lower_val && bm->upper_val == upper_val)
78 { REPORT return 0; }
79 else if (bm->lower_val >= lower_val && bm->upper_val >= upper_val)
80 { REPORT return 1; }
81 else if (bm->lower_val <= lower_val && bm->upper_val <= upper_val)
82 { REPORT return 2; }
83 else { REPORT return 3; }
84}
85
86/// \brief can we add two symmetric band matrices with simple vector add
87///
88/// Sufficient to check lower bandwidths agree
89
90short SymmetricBandMatrix::SimpleAddOK(const GeneralMatrix* gm)
91{
92 const SymmetricBandMatrix* bm = (const SymmetricBandMatrix*)gm;
93 if (bm->lower_val == lower_val) { REPORT return 0; }
94 else if (bm->lower_val > lower_val) { REPORT return 1; }
95 else { REPORT return 2; }
96}
97
98/// \brief resize UpperBandMatrix
99void UpperBandMatrix::resize(int n, int lb, int ub)
100{
101 REPORT
102 if (lb != 0)
103 {
104 Tracer tr("UpperBandMatrix::resize");
105 Throw(ProgramException("UpperBandMatrix with non-zero lower band" ));
106 }
107 BandMatrix::resize(n, lb, ub);
108}
109
110/// \brief resize LowerBandMatrix
111void LowerBandMatrix::resize(int n, int lb, int ub)
112{
113 REPORT
114 if (ub != 0)
115 {
116 Tracer tr("LowerBandMatrix::resize");
117 Throw(ProgramException("LowerBandMatrix with non-zero upper band" ));
118 }
119 BandMatrix::resize(n, lb, ub);
120}
121
122/// \brief resize BandMatrix
123void BandMatrix::resize(const GeneralMatrix& A)
124{
125 REPORT
126 int n = A.Nrows();
127 if (n != A.Ncols())
128 {
129 Tracer tr("BandMatrix::resize(GM)");
130 Throw(NotSquareException(*this));
131 }
132 MatrixBandWidth mbw = A.bandwidth();
133 resize(n, mbw.Lower(), mbw.Upper());
134}
135
136/*
137bool BandMatrix::SameStorageType(const GeneralMatrix& A) const
138{
139 if (type() != A.type()) { REPORT return false; }
140 REPORT
141 return bandwidth() == A.bandwidth();
142}
143
144void BandMatrix::resizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B)
145{
146 REPORT
147 Tracer tr("BandMatrix::resizeForAdd");
148 MatrixBandWidth A_BW = A.bandwidth(); MatrixBandWidth B_BW = B.bandwidth();
149 if ((A_BW.Lower() < 0) | (A_BW.Upper() < 0) | (B_BW.Lower() < 0)
150 | (A_BW.Upper() < 0))
151 Throw(ProgramException("Can't resize to BandMatrix" ));
152 // already know A and B are square
153 resize(A.Nrows(), my_max(A_BW.Lower(), B_BW.Lower()),
154 my_max(A_BW.Upper(), B_BW.Upper()));
155}
156
157void BandMatrix::resizeForSP(const GeneralMatrix& A, const GeneralMatrix& B)
158{
159 REPORT
160 Tracer tr("BandMatrix::resizeForSP");
161 MatrixBandWidth A_BW = A.bandwidth(); MatrixBandWidth B_BW = B.bandwidth();
162 if ((A_BW.Lower() < 0) | (A_BW.Upper() < 0) | (B_BW.Lower() < 0)
163 | (A_BW.Upper() < 0))
164 Throw(ProgramException("Can't resize to BandMatrix" ));
165 // already know A and B are square
166 resize(A.Nrows(), my_min(A_BW.Lower(), B_BW.Lower()),
167 my_min(A_BW.Upper(), B_BW.Upper()));
168}
169*/
170
171/// \brief assignment operator for BandMatrix
172void BandMatrix::operator=(const BaseMatrix& X)
173{
174 REPORT // CheckConversion(X);
175 // MatrixConversionCheck mcc;
176 Eq(X,MatrixType::BM); CornerClear();
177}
178
179/// \brief set unused parts of BandMatrix to zero
180void BandMatrix::CornerClear() const
181{
182 REPORT
183 int i = lower_val; Real* s = store; int bw = lower_val + 1 + upper_val;
184 while (i)
185 { int j = i--; Real* sj = s; s += bw; while (j--) *sj++ = 0.0; }
186 i = upper_val; s = store + storage;
187 while (i)
188 { int j = i--; Real* sj = s; s -= bw; while (j--) *(--sj) = 0.0; }
189}
190
191MatrixBandWidth MatrixBandWidth::operator+(const MatrixBandWidth& bw) const
192{
193 REPORT
194 int l = bw.lower_val; int u = bw.upper_val;
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;
197 return MatrixBandWidth(l,u);
198}
199
200MatrixBandWidth MatrixBandWidth::operator*(const MatrixBandWidth& bw) const
201{
202 REPORT
203 int l = bw.lower_val; int u = bw.upper_val;
204 l = (lower_val < 0 || l < 0) ? -1 : lower_val+l;
205 u = (upper_val < 0 || u < 0) ? -1 : upper_val+u;
206 return MatrixBandWidth(l,u);
207}
208
209MatrixBandWidth MatrixBandWidth::minimum(const MatrixBandWidth& bw) const
210{
211 REPORT
212 int l = bw.lower_val; int u = bw.upper_val;
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;
215 return MatrixBandWidth(l,u);
216}
217
218UpperBandMatrix::UpperBandMatrix(const BaseMatrix& M)
219{
220 REPORT // CheckConversion(M);
221 // MatrixConversionCheck mcc;
222 GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::UB);
223 GetMatrix(gmx); CornerClear();
224}
225
226void UpperBandMatrix::operator=(const BaseMatrix& X)
227{
228 REPORT // CheckConversion(X);
229 // MatrixConversionCheck mcc;
230 Eq(X,MatrixType::UB); CornerClear();
231}
232
233LowerBandMatrix::LowerBandMatrix(const BaseMatrix& M)
234{
235 REPORT // CheckConversion(M);
236 // MatrixConversionCheck mcc;
237 GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::LB);
238 GetMatrix(gmx); CornerClear();
239}
240
241void LowerBandMatrix::operator=(const BaseMatrix& X)
242{
243 REPORT // CheckConversion(X);
244 // MatrixConversionCheck mcc;
245 Eq(X,MatrixType::LB); CornerClear();
246}
247
248BandLUMatrix::BandLUMatrix(const BaseMatrix& m)
249{
250 REPORT
251 Tracer tr("BandLUMatrix");
252 storage2 = 0; store2 = 0; indx = 0; // in event of exception during build
253 GeneralMatrix* gm = ((BaseMatrix&)m).Evaluate();
254 if (gm->nrows() != gm->ncols())
255 { gm->tDelete(); Throw(NotSquareException(*this)); }
256 if (gm->type() == MatrixType::BC)
257 { REPORT ((BandLUMatrix*)gm)->get_aux(*this); GetMatrix(gm); }
258 else
259 {
260 REPORT
261 BandMatrix* gm1 = (BandMatrix*)(gm->Evaluate(MatrixType::BM));
262 m1 = gm1->lower_val; m2 = gm1->upper_val;
263 GetMatrix(gm1);
264 d = true; sing = false;
265 indx = new int [nrows_val]; MatrixErrorNoSpace(indx);
266 MONITOR_INT_NEW("Index (BndLUMat)",nrows_val,indx)
267 storage2 = nrows_val * m1;
268 store2 = new Real [storage2]; MatrixErrorNoSpace(store2);
269 MONITOR_REAL_NEW("Make (BandLUMat)",storage2,store2)
270 ludcmp();
271 }
272}
273
274GeneralMatrix* BandLUMatrix::Evaluate(MatrixType mt)
275{
276 if (Compare(this->Type(),mt)) { REPORT return this; }
277 REPORT
278 Tracer et("BandLUMatrix::Evaluate");
279 bool dummy = true;
280 if (dummy) Throw(ProgramException("Illegal use of BandLUMatrix", *this));
281 return this;
282}
283
284// could we use SetParameters instead of this
285void BandLUMatrix::get_aux(BandLUMatrix& X)
286{
287 X.d = d; X.sing = sing; X.storage2 = storage2; X.m1 = m1; X.m2 = m2;
288 if (tag_val == 0 || tag_val == 1) // reuse the array
289 {
290 REPORT
291 X.indx = indx; indx = 0;
292 X.store2 = store2; store2 = 0;
293 d = true; sing = true; storage2 = 0; m1 = 0; m2 = 0;
294 return;
295 }
296 else if (nrows_val == 0)
297 {
298 REPORT
299 indx = 0; store2 = 0; storage2 = 0;
300 d = true; sing = true; m1 = m2 = 0;
301 return;
302 }
303 else // copy the array
304 {
305 REPORT
306 Tracer tr("BandLUMatrix::get_aux");
307 int *ix = new int [nrows_val]; MatrixErrorNoSpace(ix);
308 MONITOR_INT_NEW("Index (BLUM::get_aux)", nrows_val, ix)
309 int n = nrows_val; int* i = ix; int* j = indx;
310 while(n--) *i++ = *j++;
311 X.indx = ix;
312 Real *rx = new Real [storage2]; MatrixErrorNoSpace(indx);
313 MONITOR_REAL_NEW("Index (BLUM::get_aux)", storage2, rx)
314 newmat_block_copy(storage2, store2, rx);
315 X.store2 = rx;
316 }
317}
318
319BandLUMatrix::BandLUMatrix(const BandLUMatrix& gm) : GeneralMatrix()
320{
321 REPORT
322 Tracer tr("BandLUMatrix(const BandLUMatrix&)");
323 ((BandLUMatrix&)gm).get_aux(*this);
324 GetMatrix(&gm);
325}
326
327void BandLUMatrix::operator=(const BandLUMatrix& gm)
328{
329 if (&gm == this) { REPORT tag_val = -1; return; }
330 REPORT
331 delete [] indx; indx = 0;
332 delete [] store2; store2 = 0; storage2 = 0;
333 ((BandLUMatrix&)gm).get_aux(*this);
334 Eq(gm);
335}
336
337
338
339
340
341
342
343
344BandLUMatrix::~BandLUMatrix()
345{
346 REPORT
347 MONITOR_INT_DELETE("Index (BndLUMat)",nrows_val,indx)
348 MONITOR_REAL_DELETE("Delete (BndLUMt)",storage2,store2)
349 delete [] indx; delete [] store2;
350}
351
352MatrixType BandLUMatrix::type() const { REPORT return MatrixType::BC; }
353
354
355LogAndSign BandLUMatrix::log_determinant() const
356{
357 REPORT
358 if (sing) return 0.0;
359 Real* a = store; int w = m1+1+m2; LogAndSign sum; int i = nrows_val;
360 // while (i--) { sum *= *a; a += w; }
361 if (i) for (;;) { sum *= *a; if (!(--i)) break; a += w; }
[10791]362 if (!d) sum.ChangeSign();
363 return sum;
[9434]364}
365
366GeneralMatrix* BandMatrix::MakeSolver()
367{
368 REPORT
369 GeneralMatrix* gm = new BandLUMatrix(*this);
370 MatrixErrorNoSpace(gm); gm->ReleaseAndDelete(); return gm;
371}
372
373
374void BandLUMatrix::ludcmp()
375{
376 REPORT
377 Real* a = store2; int i = storage2;
378 // clear store2 - so unused locations are always zero -
379 // required by operator==
380 while (i--) *a++ = 0.0;
381 a = store;
382 i = m1; int j = m2; int k; int n = nrows_val; int w = m1 + 1 + m2;
383 while (i)
384 {
385 Real* ai = a + i;
386 k = ++j; while (k--) *a++ = *ai++;
387 k = i--; while (k--) *a++ = 0.0;
388 }
389
390 a = store; int l = m1;
391 for (k=0; k<n; k++)
392 {
393 Real x = *a; i = k; Real* aj = a;
394 if (l < n) l++;
395 for (j=k+1; j<l; j++)
396 { aj += w; if (fabs(x) < fabs(*aj)) { x = *aj; i = j; } }
397 indx[k] = i;
398 if (x==0) { sing = true; return; }
399 if (i!=k)
400 {
401 d = !d; Real* ak = a; Real* ai = store + i * w; j = w;
402 while (j--) { x = *ak; *ak++ = *ai; *ai++ = x; }
403 }
404 aj = a + w; Real* m = store2 + m1 * k;
405 for (j=k+1; j<l; j++)
406 {
407 *m++ = x = *aj / *a; i = w; Real* ak = a;
408 while (--i) { Real* aj1 = aj++; *aj1 = *aj - x * *(++ak); }
409 *aj++ = 0.0;
410 }
411 a += w;
412 }
413}
414
415void BandLUMatrix::lubksb(Real* B, int mini)
416{
417 REPORT
418 Tracer tr("BandLUMatrix::lubksb");
419 if (sing) Throw(SingularException(*this));
420 int n = nrows_val; int l = m1; int w = m1 + 1 + m2;
421
422 for (int k=0; k<n; k++)
423 {
424 int i = indx[k];
425 if (i!=k) { Real x=B[k]; B[k]=B[i]; B[i]=x; }
426 if (l<n) l++;
427 Real* m = store2 + k*m1; Real* b = B+k; Real* bi = b;
428 for (i=k+1; i<l; i++) *(++bi) -= *m++ * *b;
429 }
430
431 l = -m1;
432 for (int i = n-1; i>=mini; i--)
433 {
434 Real* b = B + i; Real* bk = b; Real x = *bk;
435 Real* a = store + w*i; Real y = *a;
436 int k = l+m1; while (k--) x -= *(++a) * *(++bk);
437 *b = x / y;
438 if (l < m2) l++;
439 }
440}
441
442void BandLUMatrix::Solver(MatrixColX& mcout, const MatrixColX& mcin)
443{
444 REPORT
445 int i = mcin.skip; Real* el = mcin.data-i; Real* el1=el;
446 while (i--) *el++ = 0.0;
447 el += mcin.storage; i = nrows_val - mcin.skip - mcin.storage;
448 while (i--) *el++ = 0.0;
449 lubksb(el1, mcout.skip);
450}
451
452// Do we need check for entirely zero output?
453
454
455void UpperBandMatrix::Solver(MatrixColX& mcout,
456 const MatrixColX& mcin)
457{
458 REPORT
459 int i = mcin.skip-mcout.skip; Real* elx = mcin.data-i;
460 while (i-- > 0) *elx++ = 0.0;
461 int nr = mcin.skip+mcin.storage;
462 elx = mcin.data+mcin.storage; Real* el = elx;
463 int j = mcout.skip+mcout.storage-nr; i = nr-mcout.skip;
464 while (j-- > 0) *elx++ = 0.0;
465
466 Real* Ael = store + (upper_val+1)*(i-1)+1; j = 0;
467 if (i > 0) for(;;)
468 {
469 elx = el; Real sum = 0.0; int jx = j;
470 while (jx--) sum += *(--Ael) * *(--elx);
471 elx--; *elx = (*elx - sum) / *(--Ael);
472 if (--i <= 0) break;
473 if (j<upper_val) Ael -= upper_val - (++j); else el--;
474 }
475}
476
477void LowerBandMatrix::Solver(MatrixColX& mcout,
478 const MatrixColX& mcin)
479{
480 REPORT
481 int i = mcin.skip-mcout.skip; Real* elx = mcin.data-i;
482 while (i-- > 0) *elx++ = 0.0;
483 int nc = mcin.skip; i = nc+mcin.storage; elx = mcin.data+mcin.storage;
484 int nr = mcout.skip+mcout.storage; int j = nr-i; i = nr-nc;
485 while (j-- > 0) *elx++ = 0.0;
486
487 Real* el = mcin.data;
488 Real* Ael = store + (lower_val+1)*nc + lower_val;
489 j = 0;
490 if (i > 0) for(;;)
491 {
492 elx = el; Real sum = 0.0; int jx = j;
493 while (jx--) sum += *Ael++ * *elx++;
494 *elx = (*elx - sum) / *Ael++;
495 if (--i <= 0) break;
496 if (j<lower_val) Ael += lower_val - (++j); else el++;
497 }
498}
499
500
501LogAndSign BandMatrix::log_determinant() const
502{
503 REPORT
504 BandLUMatrix C(*this); return C.log_determinant();
505}
506
507LogAndSign LowerBandMatrix::log_determinant() const
508{
509 REPORT
510 int i = nrows_val; LogAndSign sum;
511 Real* s = store + lower_val; int j = lower_val + 1;
512// while (i--) { sum *= *s; s += j; }
513 if (i) for (;;) { sum *= *s; if (!(--i)) break; s += j; }
514 ((GeneralMatrix&)*this).tDelete(); return sum;
515}
516
517LogAndSign UpperBandMatrix::log_determinant() const
518{
519 REPORT
520 int i = nrows_val; LogAndSign sum; Real* s = store; int j = upper_val + 1;
521// while (i--) { sum *= *s; s += j; }
522 if (i) for (;;) { sum *= *s; if (!(--i)) break; s += j; }
523 ((GeneralMatrix&)*this).tDelete(); return sum;
524}
525
526GeneralMatrix* SymmetricBandMatrix::MakeSolver()
527{
528 REPORT
529 GeneralMatrix* gm = new BandLUMatrix(*this);
530 MatrixErrorNoSpace(gm); gm->ReleaseAndDelete(); return gm;
531}
532
533SymmetricBandMatrix::SymmetricBandMatrix(const BaseMatrix& M)
534{
535 REPORT // CheckConversion(M);
536 // MatrixConversionCheck mcc;
537 GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::SB);
538 GetMatrix(gmx);
539}
540
541GeneralMatrix* SymmetricBandMatrix::Transpose(TransposedMatrix*, MatrixType mt)
542{ REPORT return Evaluate(mt); }
543
544LogAndSign SymmetricBandMatrix::log_determinant() const
545{
546 REPORT
547 BandLUMatrix C(*this); return C.log_determinant();
548}
549
550void SymmetricBandMatrix::SetParameters(const GeneralMatrix* gmx)
551{ REPORT lower_val = gmx->bandwidth().lower_val; }
552
553void SymmetricBandMatrix::resize(int n, int lb)
554{
555 REPORT
556 Tracer tr("SymmetricBandMatrix::resize");
557 if (lb<0) Throw(ProgramException("Undefined bandwidth"));
558 lower_val = (lb<=n) ? lb : n-1;
559 GeneralMatrix::resize(n,n,n*(lower_val+1));
560}
561
562void SymmetricBandMatrix::resize(const GeneralMatrix& A)
563{
564 REPORT
565 int n = A.Nrows();
566 if (n != A.Ncols())
567 {
568 Tracer tr("SymmetricBandMatrix::resize(GM)");
569 Throw(NotSquareException(*this));
570 }
571 MatrixBandWidth mbw = A.bandwidth(); int b = mbw.Lower();
572 if (b != mbw.Upper())
573 {
574 Tracer tr("SymmetricBandMatrix::resize(GM)");
575 Throw(ProgramException("Upper and lower band-widths not equal"));
576 }
577 resize(n, b);
578}
579/*
580bool SymmetricBandMatrix::SameStorageType(const GeneralMatrix& A) const
581{
582 if (type() != A.type()) { REPORT return false; }
583 REPORT
584 return bandwidth() == A.bandwidth();
585}
586
587void SymmetricBandMatrix::resizeForAdd(const GeneralMatrix& A,
588 const GeneralMatrix& B)
589{
590 REPORT
591 Tracer tr("SymmetricBandMatrix::resizeForAdd");
592 MatrixBandWidth A_BW = A.bandwidth(); MatrixBandWidth B_BW = B.bandwidth();
593 if ((A_BW.Lower() < 0) | (B_BW.Lower() < 0))
594 Throw(ProgramException("Can't resize to SymmetricBandMatrix" ));
595 // already know A and B are square
596 resize(A.Nrows(), my_max(A_BW.Lower(), B_BW.Lower()));
597}
598
599void SymmetricBandMatrix::resizeForSP(const GeneralMatrix& A,
600 const GeneralMatrix& B)
601{
602 REPORT
603 Tracer tr("SymmetricBandMatrix::resizeForSP");
604 MatrixBandWidth A_BW = A.bandwidth(); MatrixBandWidth B_BW = B.bandwidth();
605 if ((A_BW.Lower() < 0) | (B_BW.Lower() < 0))
606 Throw(ProgramException("Can't resize to SymmetricBandMatrix" ));
607 // already know A and B are square
608 resize(A.Nrows(), my_min(A_BW.Lower(), B_BW.Lower()));
609}
610*/
611
612void SymmetricBandMatrix::operator=(const BaseMatrix& X)
613{
614 REPORT // CheckConversion(X);
615 // MatrixConversionCheck mcc;
616 Eq(X,MatrixType::SB);
617}
618
619void SymmetricBandMatrix::CornerClear() const
620{
621 // set unused parts of BandMatrix to zero
622 REPORT
623 int i = lower_val; Real* s = store; int bw = lower_val + 1;
624 if (i) for(;;)
625 {
626 int j = i;
627 Real* sj = s;
628 while (j--) *sj++ = 0.0;
629 if (!(--i)) break;
630 s += bw;
631 }
632}
633
634MatrixBandWidth SymmetricBandMatrix::bandwidth() const
635 { REPORT return MatrixBandWidth(lower_val,lower_val); }
636
637GeneralMatrix* BandMatrix::Image() const
638{
639 REPORT
640 GeneralMatrix* gm = new BandMatrix(*this); MatrixErrorNoSpace(gm);
641 return gm;
642}
643
644GeneralMatrix* UpperBandMatrix::Image() const
645{
646 REPORT
647 GeneralMatrix* gm = new UpperBandMatrix(*this); MatrixErrorNoSpace(gm);
648 return gm;
649}
650
651GeneralMatrix* LowerBandMatrix::Image() const
652{
653 REPORT
654 GeneralMatrix* gm = new LowerBandMatrix(*this); MatrixErrorNoSpace(gm);
655 return gm;
656}
657
658GeneralMatrix* SymmetricBandMatrix::Image() const
659{
660 REPORT
661 GeneralMatrix* gm = new SymmetricBandMatrix(*this); MatrixErrorNoSpace(gm);
662 return gm;
663}
664
665GeneralMatrix* BandLUMatrix::Image() const
666{
667 REPORT
668 GeneralMatrix* gm = new BandLUMatrix(*this); MatrixErrorNoSpace(gm);
669 return gm;
670}
671
672
673inline Real square(Real x) { return x*x; }
674
675Real SymmetricBandMatrix::sum_square() const
676{
677 REPORT
678 CornerClear();
679 Real sum1=0.0; Real sum2=0.0; Real* s=store; int i=nrows_val;
680 int l=lower_val;
681 while (i--)
682 { int j = l; while (j--) sum2 += square(*s++); sum1 += square(*s++); }
683 ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
684}
685
686Real SymmetricBandMatrix::sum_absolute_value() const
687{
688 REPORT
689 CornerClear();
690 Real sum1=0.0; Real sum2=0.0; Real* s=store; int i=nrows_val;
691 int l=lower_val;
692 while (i--)
693 { int j = l; while (j--) sum2 += fabs(*s++); sum1 += fabs(*s++); }
694 ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
695}
696
697Real SymmetricBandMatrix::sum() const
698{
699 REPORT
700 CornerClear();
701 Real sum1=0.0; Real sum2=0.0; Real* s=store; int i=nrows_val;
702 int l=lower_val;
703 while (i--)
704 { int j = l; while (j--) sum2 += *s++; sum1 += *s++; }
705 ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
706}
707
708
709
710
711
712#ifdef use_namespace
713}
714#endif
715
716///@}
717
718
Note: See TracBrowser for help on using the repository browser.