20 #define REPORT { static ExeCounter ExeCount(__LINE__,7); ++ExeCount; } 46 while (i--) *el++ = 0.0;
48 while (i--) *el++ = 0.0;
49 lubksb(el1, mcout.
skip);
60 while (i-- > 0) *elx++ = 0.0;
64 int nc = ncols_val-nr; i = nr-mcout.
skip;
65 while (j-- > 0) *elx++ = 0.0;
66 Real* Ael = store + (nr*(2*ncols_val-nr+1))/2; j = 0;
69 elx = el;
Real sum = 0.0;
int jx = j++; Ael -= nc;
70 while (jx--) sum += *(--Ael) * *(--elx);
71 elx--; *elx = (*elx -
sum) / *(--Ael);
80 while (i-- > 0) *elx++ = 0.0;
82 int nr = mcout.
skip+mcout.
storage;
int j = nr-i; i = nr-nc;
83 while (j-- > 0) *elx++ = 0.0;
84 Real* el = mcin.
data;
Real* Ael = store + (nc*(nc+1))/2; j = 0;
87 elx = el;
Real sum = 0.0;
int jx = j++; Ael += nc;
88 while (jx--) sum += *Ael++ * *elx++;
89 *elx = (*elx -
sum) / *Ael++;
108 gm2 = gm2->Evaluate(gm2->type().MultRHS());
138 *s++ = *s1++ + *s2++; *s++ = *s1++ + *s2++;
139 *s++ = *s1++ + *s2++; *s++ = *s1++ + *s2++;
141 i=gm->
Storage() & 3;
while (i--) *s++ = *s1++ + *s2++;
149 { *s++ += *s2++; *s++ += *s2++; *s++ += *s2++; *s++ += *s2++; }
150 i=gm->
Storage() & 3;
while (i--) *s++ += *s2++;
168 *s++ = *s1++ - *s2++; *s++ = *s1++ - *s2++;
169 *s++ = *s1++ - *s2++; *s++ = *s1++ - *s2++;
171 i=gm->
Storage() & 3;
while (i--) *s++ = *s1++ - *s2++;
179 { *s++ -= *s2++; *s++ -= *s2++; *s++ -= *s2++; *s++ -= *s2++; }
180 i=gm->
Storage() & 3;
while (i--) *s++ -= *s2++;
197 *s = *s2++ - *s; s++; *s = *s2++ - *s; s++;
198 *s = *s2++ - *s; s++; *s = *s2++ - *s; s++;
200 i=gm->
Storage() & 3;
while (i--) { *s = *s2++ - *s; s++; }
210 *s++ = *s1++ * *s2++; *s++ = *s1++ * *s2++;
211 *s++ = *s1++ * *s2++; *s++ = *s1++ * *s2++;
213 i=gm->
Storage() & 3;
while (i--) *s++ = *s1++ * *s2++;
221 { *s++ *= *s2++; *s++ *= *s2++; *s++ *= *s2++; *s++ *= *s2++; }
222 i=gm->
Storage() & 3;
while (i--) *s++ *= *s2++;
230 int nr = gm->
Nrows();
240 int nr = gm->
Nrows();
243 while (nr--) { mr.
Add(mr2); mr.
Next(); mr2.
Next(); }
250 int nr = gm->
Nrows();
259 int nr = gm->
Nrows();
262 while (nr--) { mr.
Sub(mr2); mr.
Next(); mr2.
Next(); }
268 int nr = gm->
Nrows();
277 int nr = gm->
Nrows();
287 int nr = gm->
Nrows();
297 Tracer tr(
"GeneralMult1");
310 while (n--) { *(el++) =
DotProd(mr1,mc2); mr1.Next(); }
322 Tracer tr(
"GeneralMult2");
336 while (n--) { mrx.
AddScaled(mr2, *el++); mr2.Next(); }
359 Real* s2x = s2;
int j = ncr;
360 Real* sx = s;
Real f = *s1++;
int k = nc;
361 while (k--) *sx++ = f * *s2x++;
363 { sx = s; f = *s1++; k = nc;
while (k--) *sx++ += f * *s2x++; }
388 int nr1 = gm1->
Nrows();
int nc1 = gm1->
Ncols();
389 int nr2 = gm2->
Nrows();
int nc2 = gm2->
Ncols();
394 for (
int i = 1; i <= nr1; ++i)
397 for (
int j = 1; j <= nr2; ++j)
410 int nr = gm1->
Nrows();
412 int nc = gm2->
Ncols();
449 Tracer tr(
"GeneralSolvI");
451 int nr = gm1->
Nrows();
487 Tracer tr(
"InvertedMatrix::Evaluate");
498 Tracer tr(
"AddedMatrix::Evaluate");
511 if (!mtd) {
REPORT mtd = mts; }
519 bool c1 = (mtd == mt1), c2 = (mtd == mt2);
528 Try { gmx = mt1.
New(nr,nc,
this); }
541 if (SAO & 1) {
REPORT c1 =
false; }
542 if (SAO & 2) {
REPORT c2 =
false; }
544 if (c1 && gm1->
reuse() )
546 else if (c2 && gm2->
reuse() )
551 Try { gmx = mtd.
New(nr,nc,
this); }
568 Tracer tr(
"SubtractedMatrix::Evaluate");
581 if (!mtd) {
REPORT mtd = mts; }
588 bool c1 = (mtd == mt1), c2 = (mtd == mt2);
597 Try { gmx = mt1.
New(nr,nc,
this); }
610 if (SAO & 1) {
REPORT c1 =
false; }
611 if (SAO & 2) {
REPORT c2 =
false; }
613 if (c1 && gm1->
reuse() )
615 else if (c2 && gm2->
reuse() )
618 if (!c1) gm1->
tDelete(); gmx = gm2;
624 Try { gmx = mtd.
New(nr,nc,
this); }
641 Tracer tr(
"SPMatrix::Evaluate");
655 if (!mtd) {
REPORT mtd = mts; }
662 bool c1 = (mtd == mt1), c2 = (mtd == mt2);
670 Try { gmx = mt1.
New(nr,nc,
this); }
683 if (SAO & 1) {
REPORT c2 =
false; }
684 if (SAO & 2) {
REPORT c1 =
false; }
686 if (c1 && gm1->
reuse() )
688 else if (c2 && gm2->
reuse() )
694 Try { gmx = mtd.
New(nr,nc,
this); }
721 gm->tDelete();
return value;
733 gm->tDelete();
return value;
746 if (nr != gm2->
Nrows())
763 int nr1 = gm1->
Nrows();
int nr2 = gm2->
Nrows();
764 if (nc != gm2->
Ncols())
781 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
782 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
784 i = n & 3;
while (i--)
if (*s1++ != *s2++)
return false;
793 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
794 if (*s1++ != *s2++)
return false;
if (*s1++ != *s2++)
return false;
796 i = n & 3;
while (i--)
if (*s1++ != *s2++)
return false;
803 Tracer tr(
"BaseMatrix ==");
809 {
REPORT gmA->tDelete();
return true; }
811 if ( gmA->Nrows() != gmB->
Nrows() || gmA->Ncols() != gmB->
Ncols() )
820 bool bx = gmA->IsEqual(*gmB);
821 gmA->tDelete(); gmB->
tDelete();
827 if (AType == BType && gmA->bandwidth() == gmB->
bandwidth())
831 gmA->tDelete(); gmB->
tDelete();
841 Tracer tr(
"GeneralMatrix ==");
868 Real* s=store;
int i = storage >> 2;
871 if (*s++)
return false;
if (*s++)
return false;
872 if (*s++)
return false;
if (*s++)
return false;
874 i = storage & 3;
while (i--)
if (*s++)
return false;
880 Tracer tr(
"BaseMatrix::is_zero");
883 Try { gm1=((
BaseMatrix&)A).Evaluate(); bx = gm1->is_zero(); }
894 Tracer tr(
"GeneralMatrix IsEqual");
895 if (A.
type() != type())
909 Tracer tr(
"CroutMatrix IsEqual");
910 if (A.
type() != type())
926 Tracer tr(
"BandLUMatrix IsEqual");
927 if (A.
type() != type())
931 if ( A.
Nrows() != nrows_val || A.
Ncols() != ncols_val
948 c[0] = a[1] * b[2] - a[2] * b[1];
949 c[1] = a[2] * b[0] - a[0] * b[2];
950 c[2] = a[0] * b[1] - a[1] * b[0];
961 if (bc != 3 || ar != 1 || br != 1)
969 if (ac != 1 || bc != 1 || ar != 3 || br != 3)
993 a += 3; b += 3; c += 3;
1006 Tracer et(
"crossproduct_columns");
1018 *c++ = *an * *bn2 - *an2 * *bn;
1019 *cn++ = *an2++ * *b - *a * *bn2++;
1020 *cn2++ = *a++ * *bn++ - *an++ * *b++;
1027 #ifdef use_namespace
void Solver(MatrixColX &, const MatrixColX &)
virtual short SimpleAddOK(const GeneralMatrix *)
Real DotProd(const MatrixRowCol &mrc1, const MatrixRowCol &mrc2)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
void Copy(const MatrixRowCol &)
GeneralMatrix * New() const
new matrix of given type
ReturnMatrix crossproduct_rows(const Matrix &A, const Matrix &B)
Miscellaneous exception (details in character string).
MatrixType i() const
type of inverse
static GeneralMatrix * GeneralMult2(GeneralMatrix *gm1, GeneralMatrix *gm2, MultipliedMatrix *mm, MatrixType mtx)
void KP(const MatrixRowCol &, const MatrixRowCol &)
bool IsEqual(const GeneralMatrix &) const
static void SPDS(GeneralMatrix *gm, GeneralMatrix *gm1, GeneralMatrix *gm2)
static bool intEqual(int *s1, int *s2, int n)
Matrix crossproduct(const Matrix &A, const Matrix &B)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
void RevSub(const MatrixRowCol &)
void Add(const MatrixRowCol &)
GeneralMatrix * MakeSolver()
void ConCat(const MatrixRowCol &, const MatrixRowCol &)
static GeneralMatrix * mmMult(GeneralMatrix *gm1, GeneralMatrix *gm2)
static void ReverseSubtractDS(GeneralMatrix *gm, GeneralMatrix *gm2)
void AddScaled(const MatrixRowCol &, Real)
static GeneralMatrix * GeneralSolvI(GeneralMatrix *, BaseMatrix *, MatrixType)
virtual MatrixType type() const =0
virtual MatrixBandWidth bandwidth() const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
static void Add(GeneralMatrix *gm, GeneralMatrix *gm1, GeneralMatrix *gm2)
static void ReverseSubtract(GeneralMatrix *gm, const GeneralMatrix *gm2)
KPMatrix KP(const BaseMatrix &, const BaseMatrix &)
void PlusEqual(const GeneralMatrix &gm)
bool CannotConvert() const
A matrix is not square exception.
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
bool is_zero(const BaseMatrix &A)
void crossproduct_body(Real *a, Real *b, Real *c)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
static void SubtractFrom(GeneralMatrix *gm, const GeneralMatrix *gm2)
MatrixType SP(const MatrixType &) const
void Multiply(const MatrixRowCol &)
static GeneralMatrix * GeneralMult(GeneralMatrix *, GeneralMatrix *, MultipliedMatrix *, MatrixType)
bool Compare(const MatrixType &, MatrixType &)
void Sub(const MatrixRowCol &)
#define MONITOR_REAL_DELETE(Operation, Size, Pointer)
bool IsEqual(const GeneralMatrix &) const
static bool RealEqual(Real *s1, Real *s2, int n)
ReturnMatrix crossproduct_columns(const Matrix &A, const Matrix &B)
static void SP(GeneralMatrix *gm, GeneralMatrix *gm1, GeneralMatrix *gm2)
Base of the matrix classes.
virtual bool IsEqual(const GeneralMatrix &) const
Real norm_infinity() const
The usual rectangular matrix.
static void SubtractDS(GeneralMatrix *gm, GeneralMatrix *gm1, GeneralMatrix *gm2)
#define MONITOR_REAL_NEW(Operation, Size, Pointer)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
static GeneralMatrix * GeneralSolv(GeneralMatrix *, GeneralMatrix *, BaseMatrix *, MatrixType)
void MinusEqual(const GeneralMatrix &gm)
void Solver(MatrixColX &, const MatrixColX &)
static void Subtract(GeneralMatrix *gm, GeneralMatrix *gm1, GeneralMatrix *gm2)
Incompatible dimensions exception.
FloatVector FloatVector * a
bool Rectangular(MatrixType a, MatrixType b, MatrixType c)
virtual GeneralMatrix * MakeSolver()
LU decomposition of a band matrix.
void MatrixErrorNoSpace(const void *)
test for allocation fails
static GeneralMatrix * GeneralMult1(GeneralMatrix *gm1, GeneralMatrix *gm2, MultipliedMatrix *mm, MatrixType mtx)
ReturnMatrix ForReturn() const
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
Real sum(const BaseMatrix &B)
static GeneralMatrix * GeneralKP(GeneralMatrix *, GeneralMatrix *, KPMatrix *, MatrixType)
bool operator==(const BaseMatrix &A, const BaseMatrix &B)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
virtual void Solver(MatrixColX &, const MatrixColX &)
The classes for matrices that can contain data are derived from this.
static void AddDS(GeneralMatrix *gm, GeneralMatrix *gm1, GeneralMatrix *gm2)
void Solver(MatrixColX &, const MatrixColX &)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
static void AddTo(GeneralMatrix *gm, const GeneralMatrix *gm2)
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)