16 #define REPORT { static ExeCounter ExeCount(__LINE__,7); ++ExeCount; } 42 while (i--) *el++ = 0.0;
44 while (i--) *el++ = 0.0;
45 lubksb(el1, mcout.
skip);
56 while (i-- > 0) *elx++ = 0.0;
59 int j = mcout.
skip+mcout.
storage-nr;
int nc = ncols-nr; i = nr-mcout.
skip;
60 while (j-- > 0) *elx++ = 0.0;
61 Real* Ael = store + (nr*(2*ncols-nr+1))/2; j = 0;
64 elx = el;
Real sum = 0.0;
int jx = j++; Ael -= nc;
65 while (jx--) sum += *(--Ael) * *(--elx);
66 elx--; *elx = (*elx - sum) / *(--Ael);
75 while (i-- > 0) *elx++ = 0.0;
77 int nr = mcout.
skip+mcout.
storage;
int j = nr-i; i = nr-nc;
78 while (j-- > 0) *elx++ = 0.0;
79 Real* el = mcin.
data;
Real* Ael = store + (nc*(nc+1))/2; j = 0;
82 elx = el;
Real sum = 0.0;
int jx = j++; Ael += nc;
83 while (jx--) sum += *Ael++ * *elx++;
84 *elx = (*elx - sum) / *Ael++;
103 gm2 = gm2->Evaluate(gm2->Type().MultRHS());
105 return GeneralMult(gm1, gm2,
this, mt);
113 return GeneralSolv(gm1,gm2,
this,mt);
121 return GeneralKP(gm1,gm2,
this,mt);
133 *s++ = *s1++ + *s2++; *s++ = *s1++ + *s2++;
134 *s++ = *s1++ + *s2++; *s++ = *s1++ + *s2++;
136 i=gm->
Storage() & 3;
while (i--) *s++ = *s1++ + *s2++;
144 { *s++ += *s2++; *s++ += *s2++; *s++ += *s2++; *s++ += *s2++; }
145 i=gm->
Storage() & 3;
while (i--) *s++ += *s2++;
163 *s++ = *s1++ - *s2++; *s++ = *s1++ - *s2++;
164 *s++ = *s1++ - *s2++; *s++ = *s1++ - *s2++;
166 i=gm->
Storage() & 3;
while (i--) *s++ = *s1++ - *s2++;
174 { *s++ -= *s2++; *s++ -= *s2++; *s++ -= *s2++; *s++ -= *s2++; }
175 i=gm->
Storage() & 3;
while (i--) *s++ -= *s2++;
183 SubtractFrom(
this, &gm);
192 *s = *s2++ - *s; s++; *s = *s2++ - *s; s++;
193 *s = *s2++ - *s; s++; *s = *s2++ - *s; s++;
195 i=gm->
Storage() & 3;
while (i--) { *s = *s2++ - *s; s++; }
205 *s++ = *s1++ * *s2++; *s++ = *s1++ * *s2++;
206 *s++ = *s1++ * *s2++; *s++ = *s1++ * *s2++;
208 i=gm->
Storage() & 3;
while (i--) *s++ = *s1++ * *s2++;
216 { *s++ *= *s2++; *s++ *= *s2++; *s++ *= *s2++; *s++ *= *s2++; }
217 i=gm->
Storage() & 3;
while (i--) *s++ *= *s2++;
225 int nr = gm->
Nrows();
228 while (nr--) { mr.Add(mr1,mr2); mr1.Next(); mr2.Next(); mr.Next(); }
235 int nr = gm->
Nrows();
238 while (nr--) { mr.Add(mr2); mr.Next(); mr2.Next(); }
241 static void SubtractDS
245 int nr = gm->
Nrows();
248 while (nr--) { mr.Sub(mr1,mr2); mr1.Next(); mr2.Next(); mr.Next(); }
254 int nr = gm->
Nrows();
257 while (nr--) { mr.Sub(mr2); mr.Next(); mr2.Next(); }
263 int nr = gm->
Nrows();
266 while (nr--) { mr.RevSub(mr2); mr2.Next(); mr.Next(); }
272 int nr = gm->
Nrows();
275 while (nr--) { mr.Multiply(mr1,mr2); mr1.Next(); mr2.Next(); mr.Next(); }
282 int nr = gm->
Nrows();
285 while (nr--) { mr.Multiply(mr2); mr.Next(); mr2.Next(); }
292 Tracer tr(
"GeneralMult1");
303 Real* el = mcx.Data();
304 int n = mcx.Storage();
305 while (
n--) { *(el++) =
DotProd(mr1,mc2); mr1.Next(); }
306 mc2.Next(); mcx.Next();
317 Tracer tr(
"GeneralMult2");
328 Real* el = mr1.Data();
329 int n = mr1.Storage();
331 while (
n--) { mrx.AddScaled(mr2, *el++); mr2.Next(); }
332 mr1.Next(); mrx.Next();
354 Real* s2x = s2;
int j = ncr;
355 Real* sx = s;
Real f = *s1++;
int k = nc;
356 while (k--) *sx++ = f * *s2x++;
358 { sx = s; f = *s1++; k = nc;
while (k--) *sx++ += f * *s2x++; }
373 return mmMult(gm1, gm2);
380 if (nc <= 5 && nr > nc)
383 return GeneralMult1(gm1, gm2, mm, mtx);
388 return GeneralMult2(gm1, gm2, mm, mtx);
399 int nr1 = gm1->
Nrows();
int nc1 = gm1->
Ncols();
400 int nr2 = gm2->
Nrows();
int nc2 = gm2->
Ncols();
405 for (
int i = 1; i <= nr1; ++i)
408 for (
int j = 1; j <= nr2; ++j)
409 { mrx.KP(mr1,mr2); mr2.Next(); mrx.Next(); }
421 int nr = gm1->
Nrows();
423 int nc = gm2->
Ncols();
436 while (nc--) { gms->
Solver(mcx, mc2); mcx.Next(); mc2.Next(); }
460 Tracer tr(
"GeneralSolvI");
462 int nr = gm1->
Nrows();
477 while (nc--) { gms->
Solver(mcx, mc2); mcx.Next(); mc2.Next(); }
498 Tracer tr(
"InvertedMatrix::Evaluate");
501 return GeneralSolvI(gm,
this,mtx);
509 Tracer tr(
"AddedMatrix::Evaluate");
522 if (!mtd) {
REPORT mtd = mts; }
530 bool c1 = (mtd == mt1), c2 = (mtd == mt2);
534 else if (gm2->
reuse()) {
REPORT AddTo(gm2,gm1); gmx = gm2; }
539 Try { gmx = mt1.
New(nr,nc,
this); }
552 if (SAO & 1) {
REPORT c1 =
false; }
553 if (SAO & 2) {
REPORT c2 =
false; }
555 if (c1 && gm1->
reuse() )
557 else if (c2 && gm2->
reuse() )
558 {
REPORT AddDS(gm2,gm1);
if (!c1) gm1->
tDelete(); gmx = gm2; }
562 Try { gmx = mtd.
New(nr,nc,
this); }
579 Tracer tr(
"SubtractedMatrix::Evaluate");
592 if (!mtd) {
REPORT mtd = mts; }
599 bool c1 = (mtd == mt1), c2 = (mtd == mt2);
604 else if (gm2->
reuse()) {
REPORT ReverseSubtract(gm2,gm1); gmx = gm2; }
608 Try { gmx = mt1.
New(nr,nc,
this); }
621 if (SAO & 1) {
REPORT c1 =
false; }
622 if (SAO & 2) {
REPORT c2 =
false; }
624 if (c1 && gm1->
reuse() )
626 else if (c2 && gm2->
reuse() )
628 REPORT ReverseSubtractDS(gm2,gm1);
629 if (!c1) gm1->
tDelete(); gmx = gm2;
635 Try { gmx = mtd.
New(nr,nc,
this); }
641 SubtractDS(gmx,gm1,gm2);
652 Tracer tr(
"SPMatrix::Evaluate");
666 if (!mtd) {
REPORT mtd = mts; }
673 bool c1 = (mtd == mt1), c2 = (mtd == mt2);
681 Try { gmx = mt1.
New(nr,nc,
this); }
694 if (SAO & 1) {
REPORT c2 =
false; }
695 if (SAO & 2) {
REPORT c1 =
false; }
697 if (c1 && gm1->
reuse() )
699 else if (c2 && gm2->
reuse() )
700 {
REPORT SPDS(gm2,gm1);
if (!c1) gm1->
tDelete(); gmx = gm2; }
705 Try { gmx = mtd.
New(nr,nc,
this); }
732 gm->tDelete();
return value;
744 gm->tDelete();
return value;
757 if (nr != gm2->
Nrows())
774 int nr1 = gm1->
Nrows();
int nr2 = gm2->
Nrows();
775 if (nc != gm2->
Ncols())
787 static bool RealEqual(
Real* s1,
Real* s2,
int n)
792 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
793 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
795 i =
n & 3;
while (i--)
if (*s1++ != *s2++)
return false;
799 static bool intEqual(
int* s1,
int* s2,
int n)
804 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
805 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
807 i =
n & 3;
while (i--)
if (*s1++ != *s2++)
return false;
814 Tracer tr(
"BaseMatrix ==");
820 {
REPORT gmA->tDelete();
return true; }
822 if ( gmA->Nrows() != gmB->
Nrows() || gmA->Ncols() != gmB->
Ncols() )
831 bool bx = gmA->IsEqual(*gmB);
832 gmA->tDelete(); gmB->
tDelete();
838 if (AType == BType && gmA->BandWidth() == gmB->
BandWidth())
841 bool bx = RealEqual(gmA->Store(),gmB->
Store(),gmA->Storage());
842 gmA->tDelete(); gmB->
tDelete();
852 Tracer tr(
"GeneralMatrix ==");
865 {
REPORT return A.IsEqual(B); }
869 if (AType == BType &&
A.BandWidth() == B.
BandWidth())
870 {
REPORT return RealEqual(
A.Store(),B.
Store(),
A.Storage()); }
879 Real* s=store;
int i = storage >> 2;
882 if (*s++)
return false;
if (*s++)
return false;
883 if (*s++)
return false;
if (*s++)
return false;
885 i = storage & 3;
while (i--)
if (*s++)
return false;
891 Tracer tr(
"BaseMatrix::IsZero");
895 CatchAll {
if (gm1) gm1->tDelete(); ReThrow; }
905 Tracer tr(
"GeneralMatrix IsEqual");
906 if (
A.Type() != Type())
910 if (
A.nrows != nrows ||
A.ncols != ncols)
915 return RealEqual(
A.store,store,storage);
920 Tracer tr(
"CroutMatrix IsEqual");
921 if (
A.Type() != Type())
925 if (
A.nrows != nrows ||
A.ncols != ncols)
930 return RealEqual(
A.store,store,storage)
937 Tracer tr(
"BandLUMatrix IsEqual");
938 if (
A.Type() != Type())
942 if (
A.Nrows() != nrows ||
A.Ncols() != ncols
949 return RealEqual(
A.Store(),store,storage)
959 c[0] = a[1] * b[2] - a[2] * b[1];
960 c[1] = a[2] * b[0] - a[0] * b[2];
961 c[2] = a[0] * b[1] - a[1] * b[0];
967 int ac =
A.Ncols();
int ar =
A.Nrows();
972 if (bc != 3 || ar != 1 || br != 1)
980 if (ac != 1 || bc != 1 || ar != 3 || br != 3)
1002 a += 3; b += 3; c += 3;
1013 if (
A.Nrows() != 3 || B.
Nrows() != 3 ||
n != B.
Ncols())
1024 *c++ = *an * *bn2 - *an2 * *bn;
1025 *cn++ = *an2++ * *b - *a * *bn2++;
1026 *cn2++ = *a++ * *bn++ - *an++ * *b++;
1033 #ifdef use_namespace void Solver(MatrixColX &, const MatrixColX &)
Real DotProd(const MatrixRowCol &mrc1, const MatrixRowCol &mrc2)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
void Copy(const MatrixRowCol &)
Matrix CrossProduct(const Matrix &A, const Matrix &B)
ReturnMatrix ForReturn() const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
GeneralMatrix * MakeSolver()
SPMatrix SP(const BaseMatrix &bm1, const BaseMatrix &bm2)
void ConCat(const MatrixRowCol &, const MatrixRowCol &)
virtual MatrixBandWidth BandWidth() const
virtual bool IsEqual(const GeneralMatrix &) const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
GeneralMatrix * New() const
bool CannotConvert() const
virtual short SimpleAddOK(const GeneralMatrix *)
void PlusEqual(const GeneralMatrix &gm)
bool Compare(const MatrixType &source, MatrixType &destination)
bool IsEqual(const GeneralMatrix &) const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
void MatrixErrorNoSpace(const void *)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
os2<< "> n<< " > nendobj n
#define MONITOR_REAL_DELETE(Operation, Size, Pointer)
bool IsZero(const BaseMatrix &A)
bool Rectangular(MatrixType a, MatrixType b, MatrixType c)
bool operator==(const BaseMatrix &A, const BaseMatrix &B)
#define MONITOR_REAL_NEW(Operation, Size, Pointer)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
void MinusEqual(const GeneralMatrix &gm)
void Solver(MatrixColX &, const MatrixColX &)
virtual GeneralMatrix * MakeSolver()
Real NormInfinity() const
virtual MatrixType Type() const =0
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
MatrixType SP(const MatrixType &) const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
KPMatrix KP(const BaseMatrix &bm1, const BaseMatrix &bm2)
void CrossProductBody(Real *a, Real *b, Real *c)
virtual void Solver(MatrixColX &, const MatrixColX &)
void Solver(MatrixColX &, const MatrixColX &)
ReturnMatrix CrossProductColumns(const Matrix &A, const Matrix &B)
ReturnMatrix CrossProductRows(const Matrix &A, const Matrix &B)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
bool IsEqual(const GeneralMatrix &) const