You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

snrm2.f 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. *> \brief \b SNRM2
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * REAL FUNCTION SNRM2(N,X,INCX)
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER INCX,N
  15. * ..
  16. * .. Array Arguments ..
  17. * REAL X(*)
  18. * ..
  19. *
  20. *
  21. *> \par Purpose:
  22. * =============
  23. *>
  24. *> \verbatim
  25. *>
  26. *> SNRM2 returns the euclidean norm of a vector via the function
  27. *> name, so that
  28. *>
  29. *> SNRM2 := sqrt( x'*x ).
  30. *> \endverbatim
  31. *
  32. * Arguments:
  33. * ==========
  34. *
  35. *> \param[in] N
  36. *> \verbatim
  37. *> N is INTEGER
  38. *> number of elements in input vector(s)
  39. *> \endverbatim
  40. *>
  41. *> \param[in] X
  42. *> \verbatim
  43. *> X is REAL array, dimension ( 1 + ( N - 1 )*abs( INCX ) )
  44. *> \endverbatim
  45. *>
  46. *> \param[in] INCX
  47. *> \verbatim
  48. *> INCX is INTEGER
  49. *> storage spacing between elements of SX
  50. *> \endverbatim
  51. *
  52. * Authors:
  53. * ========
  54. *
  55. *> \author Univ. of Tennessee
  56. *> \author Univ. of California Berkeley
  57. *> \author Univ. of Colorado Denver
  58. *> \author NAG Ltd.
  59. *
  60. *> \date November 2017
  61. *
  62. *> \ingroup single_blas_level1
  63. *
  64. *> \par Further Details:
  65. * =====================
  66. *>
  67. *> \verbatim
  68. *>
  69. *> -- This version written on 25-October-1982.
  70. *> Modified on 14-October-1993 to inline the call to SLASSQ.
  71. *> Sven Hammarling, Nag Ltd.
  72. *> \endverbatim
  73. *>
  74. * =====================================================================
  75. REAL FUNCTION SNRM2(N,X,INCX)
  76. *
  77. * -- Reference BLAS level1 routine (version 3.8.0) --
  78. * -- Reference BLAS is a software package provided by Univ. of Tennessee, --
  79. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  80. * November 2017
  81. *
  82. * .. Scalar Arguments ..
  83. INTEGER INCX,N
  84. * ..
  85. * .. Array Arguments ..
  86. REAL X(*)
  87. * ..
  88. *
  89. * =====================================================================
  90. *
  91. * .. Parameters ..
  92. REAL ONE,ZERO
  93. PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)
  94. * ..
  95. * .. Local Scalars ..
  96. REAL ABSXI,NORM,SCALE,SSQ
  97. INTEGER IX
  98. * ..
  99. * .. Intrinsic Functions ..
  100. INTRINSIC ABS,SQRT
  101. * ..
  102. IF (N.LT.1 .OR. INCX.LT.1) THEN
  103. NORM = ZERO
  104. ELSE IF (N.EQ.1) THEN
  105. NORM = ABS(X(1))
  106. ELSE
  107. SCALE = ZERO
  108. SSQ = ONE
  109. * The following loop is equivalent to this call to the LAPACK
  110. * auxiliary routine:
  111. * CALL SLASSQ( N, X, INCX, SCALE, SSQ )
  112. *
  113. DO 10 IX = 1,1 + (N-1)*INCX,INCX
  114. IF (X(IX).NE.ZERO) THEN
  115. ABSXI = ABS(X(IX))
  116. IF (SCALE.LT.ABSXI) THEN
  117. SSQ = ONE + SSQ* (SCALE/ABSXI)**2
  118. SCALE = ABSXI
  119. ELSE
  120. SSQ = SSQ + (ABSXI/SCALE)**2
  121. END IF
  122. END IF
  123. 10 CONTINUE
  124. NORM = SCALE*SQRT(SSQ)
  125. END IF
  126. *
  127. SNRM2 = NORM
  128. RETURN
  129. *
  130. * End of SNRM2.
  131. *
  132. END