dsdot.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* dsdot.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. doublereal dsdot_(integer *n, real *sx, integer *incx, real *sy, integer *
  14. incy)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2;
  18. doublereal ret_val;
  19. /* Local variables */
  20. integer i__, ns, kx, ky;
  21. /* .. Scalar Arguments .. */
  22. /* .. */
  23. /* .. Array Arguments .. */
  24. /* .. */
  25. /* AUTHORS */
  26. /* ======= */
  27. /* Lawson, C. L., (JPL), Hanson, R. J., (SNLA), */
  28. /* Kincaid, D. R., (U. of Texas), Krogh, F. T., (JPL) */
  29. /* Purpose */
  30. /* ======= */
  31. /* Compute the inner product of two vectors with extended */
  32. /* precision accumulation and result. */
  33. /* Returns D.P. dot product accumulated in D.P., for S.P. SX and SY */
  34. /* DSDOT = sum for I = 0 to N-1 of SX(LX+I*INCX) * SY(LY+I*INCY), */
  35. /* where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is */
  36. /* defined in a similar way using INCY. */
  37. /* Arguments */
  38. /* ========= */
  39. /* N (input) INTEGER */
  40. /* number of elements in input vector(s) */
  41. /* SX (input) REAL array, dimension(N) */
  42. /* single precision vector with N elements */
  43. /* INCX (input) INTEGER */
  44. /* storage spacing between elements of SX */
  45. /* SY (input) REAL array, dimension(N) */
  46. /* single precision vector with N elements */
  47. /* INCY (input) INTEGER */
  48. /* storage spacing between elements of SY */
  49. /* DSDOT (output) DOUBLE PRECISION */
  50. /* DSDOT double precision dot product (zero if N.LE.0) */
  51. /* REFERENCES */
  52. /* ========== */
  53. /* C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. */
  54. /* Krogh, Basic linear algebra subprograms for Fortran */
  55. /* usage, Algorithm No. 539, Transactions on Mathematical */
  56. /* Software 5, 3 (September 1979), pp. 308-323. */
  57. /* REVISION HISTORY (YYMMDD) */
  58. /* ========================== */
  59. /* 791001 DATE WRITTEN */
  60. /* 890831 Modified array declarations. (WRB) */
  61. /* 890831 REVISION DATE from Version 3.2 */
  62. /* 891214 Prologue converted to Version 4.0 format. (BAB) */
  63. /* 920310 Corrected definition of LX in DESCRIPTION. (WRB) */
  64. /* 920501 Reformatted the REFERENCES section. (WRB) */
  65. /* 070118 Reformat to LAPACK style (JL) */
  66. /* ===================================================================== */
  67. /* .. Local Scalars .. */
  68. /* .. */
  69. /* .. Intrinsic Functions .. */
  70. /* .. */
  71. /* Parameter adjustments */
  72. --sy;
  73. --sx;
  74. /* Function Body */
  75. ret_val = 0.;
  76. if (*n <= 0) {
  77. return ret_val;
  78. }
  79. if (*incx == *incy && *incx > 0) {
  80. goto L20;
  81. }
  82. /* Code for unequal or nonpositive increments. */
  83. kx = 1;
  84. ky = 1;
  85. if (*incx < 0) {
  86. kx = (1 - *n) * *incx + 1;
  87. }
  88. if (*incy < 0) {
  89. ky = (1 - *n) * *incy + 1;
  90. }
  91. i__1 = *n;
  92. for (i__ = 1; i__ <= i__1; ++i__) {
  93. ret_val += (doublereal) sx[kx] * (doublereal) sy[ky];
  94. kx += *incx;
  95. ky += *incy;
  96. /* L10: */
  97. }
  98. return ret_val;
  99. /* Code for equal, positive, non-unit increments. */
  100. L20:
  101. ns = *n * *incx;
  102. i__1 = ns;
  103. i__2 = *incx;
  104. for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
  105. ret_val += (doublereal) sx[i__] * (doublereal) sy[i__];
  106. /* L30: */
  107. }
  108. return ret_val;
  109. } /* dsdot_ */