newmatrm.cppGo to the documentation of this file.00001
00002
00003
00004
00005 #define WANT_MATH
00006
00007 #include "newmat.h"
00008 #include "newmatrm.h"
00009
00010 #ifdef use_namespace
00011 namespace NEWMAT {
00012 #endif
00013
00014 #ifdef DO_REPORT
00015 #define REPORT { static ExeCounter ExeCount(__LINE__,12); ++ExeCount; }
00016 #else
00017 #define REPORT {}
00018 #endif
00019
00020
00021
00022
00023
00024 void RectMatrixRow::Reset (const Matrix& M, int row, int skip, int length)
00025 {
00026 REPORT
00027 RectMatrixRowCol::Reset
00028 ( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() );
00029 }
00030
00031 void RectMatrixRow::Reset (const Matrix& M, int row)
00032 {
00033 REPORT
00034 RectMatrixRowCol::Reset( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() );
00035 }
00036
00037 void RectMatrixCol::Reset (const Matrix& M, int skip, int col, int length)
00038 {
00039 REPORT
00040 RectMatrixRowCol::Reset
00041 ( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 );
00042 }
00043
00044 void RectMatrixCol::Reset (const Matrix& M, int col)
00045 {
00046 REPORT
00047 RectMatrixRowCol::Reset( M.Store()+col, M.Nrows(), M.Ncols(), 1 );
00048 }
00049
00050
00051 Real RectMatrixRowCol::SumSquare() const
00052 {
00053 REPORT
00054 long_Real sum = 0.0; int i = n; Real* s = store; int d = spacing;
00055
00056 if (i) for(;;)
00057 { sum += (long_Real)*s * *s; if (!(--i)) break; s += d; }
00058 return (Real)sum;
00059 }
00060
00061 Real RectMatrixRowCol::operator*(const RectMatrixRowCol& rmrc) const
00062 {
00063 REPORT
00064 long_Real sum = 0.0; int i = n;
00065 Real* s = store; int d = spacing;
00066 Real* s1 = rmrc.store; int d1 = rmrc.spacing;
00067 if (i!=rmrc.n)
00068 {
00069 Tracer tr("newmatrm");
00070 Throw(InternalException("Dimensions differ in *"));
00071 }
00072
00073 if (i) for(;;)
00074 { sum += (long_Real)*s * *s1; if (!(--i)) break; s += d; s1 += d1; }
00075 return (Real)sum;
00076 }
00077
00078 void RectMatrixRowCol::AddScaled(const RectMatrixRowCol& rmrc, Real r)
00079 {
00080 REPORT
00081 int i = n; Real* s = store; int d = spacing;
00082 Real* s1 = rmrc.store; int d1 = rmrc.spacing;
00083 if (i!=rmrc.n)
00084 {
00085 Tracer tr("newmatrm");
00086 Throw(InternalException("Dimensions differ in AddScaled"));
00087 }
00088
00089 if (i) for (;;)
00090 { *s += *s1 * r; if (!(--i)) break; s += d; s1 += d1; }
00091 }
00092
00093 void RectMatrixRowCol::Divide(const RectMatrixRowCol& rmrc, Real r)
00094 {
00095 REPORT
00096 int i = n; Real* s = store; int d = spacing;
00097 Real* s1 = rmrc.store; int d1 = rmrc.spacing;
00098 if (i!=rmrc.n)
00099 {
00100 Tracer tr("newmatrm");
00101 Throw(InternalException("Dimensions differ in Divide"));
00102 }
00103
00104 if (i) for (;;) { *s = *s1 / r; if (!(--i)) break; s += d; s1 += d1; }
00105 }
00106
00107 void RectMatrixRowCol::Divide(Real r)
00108 {
00109 REPORT
00110 int i = n; Real* s = store; int d = spacing;
00111
00112 if (i) for (;;) { *s /= r; if (!(--i)) break; s += d; }
00113 }
00114
00115 void RectMatrixRowCol::Negate()
00116 {
00117 REPORT
00118 int i = n; Real* s = store; int d = spacing;
00119
00120 if (i) for (;;) { *s = - *s; if (!(--i)) break; s += d; }
00121 }
00122
00123 void RectMatrixRowCol::Zero()
00124 {
00125 REPORT
00126 int i = n; Real* s = store; int d = spacing;
00127
00128 if (i) for (;;) { *s = 0.0; if (!(--i)) break; s += d; }
00129 }
00130
00131 void ComplexScale(RectMatrixCol& U, RectMatrixCol& V, Real x, Real y)
00132 {
00133 REPORT
00134 int n = U.n;
00135 if (n != V.n)
00136 {
00137 Tracer tr("newmatrm");
00138 Throw(InternalException("Dimensions differ in ComplexScale"));
00139 }
00140 Real* u = U.store; Real* v = V.store;
00141 int su = U.spacing; int sv = V.spacing;
00142
00143
00144
00145
00146
00147 if (n) for (;;)
00148 {
00149 Real z = *u * x - *v * y; *v = *u * y + *v * x; *u = z;
00150 if (!(--n)) break;
00151 u += su; v += sv;
00152 }
00153 }
00154
00155 void Rotate(RectMatrixCol& U, RectMatrixCol& V, Real tau, Real s)
00156 {
00157 REPORT
00158
00159 int n = U.n;
00160 if (n != V.n)
00161 {
00162 Tracer tr("newmatrm");
00163 Throw(InternalException("Dimensions differ in Rotate"));
00164 }
00165 Real* u = U.store; Real* v = V.store;
00166 int su = U.spacing; int sv = V.spacing;
00167
00168
00169
00170
00171
00172
00173 if (n) for(;;)
00174 {
00175 Real zu = *u; Real zv = *v;
00176 *u -= s * (zv + zu * tau); *v += s * (zu - zv * tau);
00177 if (!(--n)) break;
00178 u += su; v += sv;
00179 }
00180 }
00181
00182
00183
00184
00185 Real pythag(Real f, Real g, Real& c, Real& s)
00186
00187
00188
00189 {
00190 if (f==0 && g==0) { c=1.0; s=0.0; return 0.0; }
00191 Real af = f>=0 ? f : -f;
00192 Real ag = g>=0 ? g : -g;
00193 if (ag<af)
00194 {
00195 REPORT
00196 Real h = g/f; Real sq = sqrt(1.0+h*h);
00197 if (f<0) sq = -sq;
00198 c = 1.0/sq; s = h/sq; return sq*f;
00199 }
00200 else
00201 {
00202 REPORT
00203 Real h = f/g; Real sq = sqrt(1.0+h*h);
00204 if (g<0) sq = -sq;
00205 s = 1.0/sq; c = h/sq; return sq*g;
00206 }
00207 }
00208
00209
00210
00211
00212 #ifdef use_namespace
00213 }
00214 #endif
00215
00216
|