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:      #region Interface
  20:   
  21:      public interface IDNRM2
  22:      {
  23:          double Run(int N, double[] X, int offset_x, int INCX);
  24:      }
  25:   
  26:      #endregion
  27:   
  28:      public class DNRM2 : IDNRM2
  29:      {
  30:      
  31:   
  32:          #region Fields
  33:          
  34:          const double ONE = 1.0E+0; const double ZERO = 0.0E+0; int IX = 0; double ABSXI = 0; double NORM = 0; double SCALE = 0; 
  35:          double SSQ = 0;
  36:   
  37:          #endregion
  38:   
  39:          public DNRM2()
  40:          {
  41:      
  42:          }
  43:      
  44:          public double Run(int N, double[] X, int offset_x, int INCX)
  45:          {
  46:          double dnrm2 = 0;
  47:   
  48:              #region Array Index Correction
  49:              
  50:               int o_x = -1 + offset_x; 
  51:   
  52:              #endregion
  53:   
  54:   
  55:              #region Prolog
  56:              
  57:              // *     .. Scalar Arguments ..
  58:              // *     .. Array Arguments ..
  59:              // *     ..
  60:              // *
  61:              // *  DNRM2 returns the euclidean norm of a vector via the function
  62:              // *  name, so that
  63:              // *
  64:              // *     DNRM2 := sqrt( x'*x )
  65:              // *
  66:              // *
  67:              // *
  68:              // *  -- This version written on 25-October-1982.
  69:              // *     Modified on 14-October-1993 to inline the call to DLASSQ.
  70:              // *     Sven Hammarling, Nag Ltd.
  71:              // *
  72:              // *
  73:              // *     .. Parameters ..
  74:              // *     .. Local Scalars ..
  75:              // *     .. Intrinsic Functions ..
  76:              //      INTRINSIC             ABS, SQRT;
  77:              // *     ..
  78:              // *     .. Executable Statements ..
  79:   
  80:              #endregion
  81:   
  82:   
  83:              #region Body
  84:              
  85:              if (N < 1 || INCX < 1)
  86:              {
  87:                  NORM = ZERO;
  88:              }
  89:              else
  90:              {
  91:                  if (N == 1)
  92:                  {
  93:                      NORM = Math.Abs(X[1 + o_x]);
  94:                  }
  95:                  else
  96:                  {
  97:                      SCALE = ZERO;
  98:                      SSQ = ONE;
  99:                      // *        The following loop is equivalent to this call to the LAPACK
 100:                      // *        auxiliary routine:
 101:                      // *        CALL DLASSQ( N, X, INCX, SCALE, SSQ )
 102:                      // *
 103:                      for (IX = 1; (INCX >= 0) ? (IX <= 1 + (N - 1) * INCX) : (IX >= 1 + (N - 1) * INCX); IX += INCX)
 104:                      {
 105:                          if (X[IX + o_x] != ZERO)
 106:                          {
 107:                              ABSXI = Math.Abs(X[IX + o_x]);
 108:                              if (SCALE < ABSXI)
 109:                              {
 110:                                  SSQ = ONE + SSQ * Math.Pow(SCALE / ABSXI,2);
 111:                                  SCALE = ABSXI;
 112:                              }
 113:                              else
 114:                              {
 115:                                  SSQ = SSQ + Math.Pow(ABSXI / SCALE,2);
 116:                              }
 117:                          }
 118:                      }
 119:                      NORM = SCALE * Math.Sqrt(SSQ);
 120:                  }
 121:              }
 122:              // *
 123:              dnrm2 = NORM;
 124:              return dnrm2;
 125:              // *
 126:              // *     End of DNRM2.
 127:              // *
 128:   
 129:              #endregion
 130:   
 131:          }
 132:      }
 133:  }