newmatrm.cc
Go to the documentation of this file.
00001 //$$newmatrm.cpp                         rectangular matrix operations
00002 
00003 // Copyright (C) 1991,2,3,4: R B Davies
00004 
00005 
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 // operations on rectangular matrices
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    // while (i--) { sum += (long_Real)*s * *s; s += d; }
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    // while (i--) { sum += (long_Real)*s * *s1; s += d; s1 += d1; }
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    // while (i--) { *s += *s1 * r; s += d; s1 += d1; }
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    // while (i--) { *s = *s1 / r; s += d; s1 += d1; }
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    // while (i--) { *s /= r; s += d; }
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    // while (i--) { *s = - *s; s += d; }
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    // while (i--) { *s = 0.0; s += d; }
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    //while (n--)
00143    //{
00144    //   Real z = *u * x - *v * y;  *v =  *u * y + *v * x;  *u = z;
00145    //   u += su;  v += sv;
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    //  (U, V) = (U, V) * (c, s)  where  tau = s/(1+c), c^2 + s^2 = 1
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    //while (n--)
00168    //{
00169    //   Real zu = *u; Real zv = *v;
00170    //   *u -= s * (zv + zu * tau); *v += s * (zu - zv * tau);
00171    //   u += su;  v += sv;
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 #ifdef use_namespace
00186 }
00187 #endif
00188 
00189 


rl_agent
Author(s): Todd Hester
autogenerated on Thu Jun 6 2019 22:00:13