Skip Navigation Links
Numerical Libraries
Linear Algebra
Differential Equations
Optimization
Samples
Skip Navigation Links
Linear Algebra
CSLapack
CSBlas
   1:  #region Translated by Jose Antonio De Santiago-Castillo.
   2:   
   3:  //Translated by Jose Antonio De Santiago-Castillo. 
   4:  //E-mail:JAntonioDeSantiago@gmail.com
   5:  //Web: www.DotNumerics.com
   6:  //
   7:  //Fortran to C# Translation.
   8:  //Translated by:
   9:  //F2CSharp Version 0.71 (November 10, 2009)
  10:  //Code Optimizations: None
  11:  //
  12:  #endregion
  13:   
  14:  using System;
  15:  using DotNumerics.FortranLibrary;
  16:   
  17:  namespace DotNumerics.CSLapack
  18:  {
  19:      /// <summary>
  20:      /// Purpose
  21:      /// =======
  22:      /// 
  23:      /// DGER   performs the rank 1 operation
  24:      /// 
  25:      /// A := alpha*x*y' + A,
  26:      /// 
  27:      /// where alpha is a scalar, x is an m element vector, y is an n element
  28:      /// vector and A is an m by n matrix.
  29:      /// 
  30:      ///</summary>
  31:      public class DGER
  32:      {
  33:      
  34:   
  35:          #region Dependencies
  36:          
  37:          XERBLA _xerbla; 
  38:   
  39:          #endregion
  40:   
  41:   
  42:          #region Fields
  43:          
  44:          const double ZERO = 0.0E+0; double TEMP = 0; int I = 0; int INFO = 0; int IX = 0; int J = 0; int JY = 0; int KX = 0; 
  45:   
  46:          #endregion
  47:   
  48:          public DGER(XERBLA xerbla)
  49:          {
  50:      
  51:   
  52:              #region Set Dependencies
  53:              
  54:              this._xerbla = xerbla; 
  55:   
  56:              #endregion
  57:   
  58:          }
  59:      
  60:          public DGER()
  61:          {
  62:      
  63:   
  64:              #region Dependencies (Initialization)
  65:              
  66:              XERBLA xerbla = new XERBLA();
  67:   
  68:              #endregion
  69:   
  70:   
  71:              #region Set Dependencies
  72:              
  73:              this._xerbla = xerbla; 
  74:   
  75:              #endregion
  76:   
  77:          }
  78:          /// <summary>
  79:          /// Purpose
  80:          /// =======
  81:          /// 
  82:          /// DGER   performs the rank 1 operation
  83:          /// 
  84:          /// A := alpha*x*y' + A,
  85:          /// 
  86:          /// where alpha is a scalar, x is an m element vector, y is an n element
  87:          /// vector and A is an m by n matrix.
  88:          /// 
  89:          ///</summary>
  90:          /// <param name="M">
  91:          /// - INTEGER.
  92:          /// On entry, M specifies the number of rows of the matrix A.
  93:          /// M must be at least zero.
  94:          /// Unchanged on exit.
  95:          ///</param>
  96:          /// <param name="N">
  97:          /// - INTEGER.
  98:          /// On entry, N specifies the number of columns of the matrix A.
  99:          /// N must be at least zero.
 100:          /// Unchanged on exit.
 101:          ///</param>
 102:          /// <param name="ALPHA">
 103:          /// - DOUBLE PRECISION.
 104:          /// On entry, ALPHA specifies the scalar alpha.
 105:          /// Unchanged on exit.
 106:          ///</param>
 107:          /// <param name="X">
 108:          /// - DOUBLE PRECISION array of dimension at least
 109:          /// ( 1 + ( m - 1 )*abs( INCX ) ).
 110:          /// Before entry, the incremented array X must contain the m
 111:          /// element vector x.
 112:          /// Unchanged on exit.
 113:          ///</param>
 114:          /// <param name="INCX">
 115:          /// - INTEGER.
 116:          /// On entry, INCX specifies the increment for the elements of
 117:          /// X. INCX must not be zero.
 118:          /// Unchanged on exit.
 119:          ///</param>
 120:          /// <param name="Y">
 121:          /// - DOUBLE PRECISION array of dimension at least
 122:          /// ( 1 + ( n - 1 )*abs( INCY ) ).
 123:          /// Before entry, the incremented array Y must contain the n
 124:          /// element vector y.
 125:          /// Unchanged on exit.
 126:          ///</param>
 127:          /// <param name="INCY">
 128:          /// - INTEGER.
 129:          /// On entry, INCY specifies the increment for the elements of
 130:          /// Y. INCY must not be zero.
 131:          /// Unchanged on exit.
 132:          ///</param>
 133:          /// <param name="A">
 134:          /// := alpha*x*y' + A,
 135:          ///</param>
 136:          /// <param name="LDA">
 137:          /// - INTEGER.
 138:          /// On entry, LDA specifies the first dimension of A as declared
 139:          /// in the calling (sub) program. LDA must be at least
 140:          /// max( 1, m ).
 141:          /// Unchanged on exit.
 142:          /// 
 143:          ///</param>
 144:          public void Run(int M, int N, double ALPHA, double[] X, int offset_x, int INCX, double[] Y, int offset_y
 145:                           , int INCY, ref double[] A, int offset_a, int LDA)
 146:          {
 147:   
 148:              #region Array Index Correction
 149:              
 150:               int o_x = -1 + offset_x;  int o_y = -1 + offset_y;  int o_a = -1 - LDA + offset_a; 
 151:   
 152:              #endregion
 153:   
 154:   
 155:              #region Prolog
 156:              
 157:              // *     .. Scalar Arguments ..
 158:              // *     ..
 159:              // *     .. Array Arguments ..
 160:              // *     ..
 161:              // *
 162:              // *  Purpose
 163:              // *  =======
 164:              // *
 165:              // *  DGER   performs the rank 1 operation
 166:              // *
 167:              // *     A := alpha*x*y' + A,
 168:              // *
 169:              // *  where alpha is a scalar, x is an m element vector, y is an n element
 170:              // *  vector and A is an m by n matrix.
 171:              // *
 172:              // *  Arguments
 173:              // *  ==========
 174:              // *
 175:              // *  M      - INTEGER.
 176:              // *           On entry, M specifies the number of rows of the matrix A.
 177:              // *           M must be at least zero.
 178:              // *           Unchanged on exit.
 179:              // *
 180:              // *  N      - INTEGER.
 181:              // *           On entry, N specifies the number of columns of the matrix A.
 182:              // *           N must be at least zero.
 183:              // *           Unchanged on exit.
 184:              // *
 185:              // *  ALPHA  - DOUBLE PRECISION.
 186:              // *           On entry, ALPHA specifies the scalar alpha.
 187:              // *           Unchanged on exit.
 188:              // *
 189:              // *  X      - DOUBLE PRECISION array of dimension at least
 190:              // *           ( 1 + ( m - 1 )*abs( INCX ) ).
 191:              // *           Before entry, the incremented array X must contain the m
 192:              // *           element vector x.
 193:              // *           Unchanged on exit.
 194:              // *
 195:              // *  INCX   - INTEGER.
 196:              // *           On entry, INCX specifies the increment for the elements of
 197:              // *           X. INCX must not be zero.
 198:              // *           Unchanged on exit.
 199:              // *
 200:              // *  Y      - DOUBLE PRECISION array of dimension at least
 201:              // *           ( 1 + ( n - 1 )*abs( INCY ) ).
 202:              // *           Before entry, the incremented array Y must contain the n
 203:              // *           element vector y.
 204:              // *           Unchanged on exit.
 205:              // *
 206:              // *  INCY   - INTEGER.
 207:              // *           On entry, INCY specifies the increment for the elements of
 208:              // *           Y. INCY must not be zero.
 209:              // *           Unchanged on exit.
 210:              // *
 211:              // *  A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
 212:              // *           Before entry, the leading m by n part of the array A must
 213:              // *           contain the matrix of coefficients. On exit, A is
 214:              // *           overwritten by the updated matrix.
 215:              // *
 216:              // *  LDA    - INTEGER.
 217:              // *           On entry, LDA specifies the first dimension of A as declared
 218:              // *           in the calling (sub) program. LDA must be at least
 219:              // *           max( 1, m ).
 220:              // *           Unchanged on exit.
 221:              // *
 222:              // *
 223:              // *  Level 2 Blas routine.
 224:              // *
 225:              // *  -- Written on 22-October-1986.
 226:              // *     Jack Dongarra, Argonne National Lab.
 227:              // *     Jeremy Du Croz, Nag Central Office.
 228:              // *     Sven Hammarling, Nag Central Office.
 229:              // *     Richard Hanson, Sandia National Labs.
 230:              // *
 231:              // *
 232:              // *     .. Parameters ..
 233:              // *     ..
 234:              // *     .. Local Scalars ..
 235:              // *     ..
 236:              // *     .. External Subroutines ..
 237:              // *     ..
 238:              // *     .. Intrinsic Functions ..
 239:              //      INTRINSIC MAX;
 240:              // *     ..
 241:              // *
 242:              // *     Test the input parameters.
 243:              // *
 244:   
 245:              #endregion
 246:   
 247:   
 248:              #region Body
 249:              
 250:              INFO = 0;
 251:              if (M < 0)
 252:              {
 253:                  INFO = 1;
 254:              }
 255:              else
 256:              {
 257:                  if (N < 0)
 258:                  {
 259:                      INFO = 2;
 260:                  }
 261:                  else
 262:                  {
 263:                      if (INCX == 0)
 264:                      {
 265:                          INFO = 5;
 266:                      }
 267:                      else
 268:                      {
 269:                          if (INCY == 0)
 270:                          {
 271:                              INFO = 7;
 272:                          }
 273:                          else
 274:                          {
 275:                              if (LDA < Math.Max(1, M))
 276:                              {
 277:                                  INFO = 9;
 278:                              }
 279:                          }
 280:                      }
 281:                  }
 282:              }
 283:              if (INFO != 0)
 284:              {
 285:                  this._xerbla.Run("DGER  ", INFO);
 286:                  return;
 287:              }
 288:              // *
 289:              // *     Quick return if possible.
 290:              // *
 291:              if ((M == 0) || (N == 0) || (ALPHA == ZERO)) return;
 292:              // *
 293:              // *     Start the operations. In this version the elements of A are
 294:              // *     accessed sequentially with one pass through A.
 295:              // *
 296:              if (INCY > 0)
 297:              {
 298:                  JY = 1;
 299:              }
 300:              else
 301:              {
 302:                  JY = 1 - (N - 1) * INCY;
 303:              }
 304:              if (INCX == 1)
 305:              {
 306:                  for (J = 1; J <= N; J++)
 307:                  {
 308:                      if (Y[JY + o_y] != ZERO)
 309:                      {
 310:                          TEMP = ALPHA * Y[JY + o_y];
 311:                          for (I = 1; I <= M; I++)
 312:                          {
 313:                              A[I+J * LDA + o_a] = A[I+J * LDA + o_a] + X[I + o_x] * TEMP;
 314:                          }
 315:                      }
 316:                      JY = JY + INCY;
 317:                  }
 318:              }
 319:              else
 320:              {
 321:                  if (INCX > 0)
 322:                  {
 323:                      KX = 1;
 324:                  }
 325:                  else
 326:                  {
 327:                      KX = 1 - (M - 1) * INCX;
 328:                  }
 329:                  for (J = 1; J <= N; J++)
 330:                  {
 331:                      if (Y[JY + o_y] != ZERO)
 332:                      {
 333:                          TEMP = ALPHA * Y[JY + o_y];
 334:                          IX = KX;
 335:                          for (I = 1; I <= M; I++)
 336:                          {
 337:                              A[I+J * LDA + o_a] = A[I+J * LDA + o_a] + X[IX + o_x] * TEMP;
 338:                              IX = IX + INCX;
 339:                          }
 340:                      }
 341:                      JY = JY + INCY;
 342:                  }
 343:              }
 344:              // *
 345:              return;
 346:              // *
 347:              // *     End of DGER  .
 348:              // *
 349:   
 350:              #endregion
 351:   
 352:          }
 353:      }
 354:  }