ddot Function

pure function ddot(N, Dx, Incx, Dy, Incy)

NAME

ddot(3f) - [M_odepack::matrix] Compute the inner product of two vectors.

DESCRIPTION

Returns the dot product of double precision DX and DY. DDOT = sum for I = 0 to N-1 of DX(LX+IINCX) * DY(LY+IINCY), where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is defined in a similar way using INCY.

Description of Parameters

INPUT

N

number of elements in input vector(s)

DX

double precision vector with N elements INCX

storage spacing between elements of DX

DY
double precision vector with N elements
INCY
storage spacing between elements of DY

OUTPUT

DDOT
double precision dot product (zero if N .LE. 0)

REFERENCES

B L A S Subprogram

C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. Krogh, Basic linear algebra subprograms for Fortran usage, Algorithm No. 539, Transactions on Mathematical Software 5, 3 (September 1979), pp. 308-323.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: N
real(kind=dp), intent(in) :: Dx(*)
integer, intent(in) :: Incx
real(kind=dp), intent(in) :: Dy(*)
integer, intent(in) :: Incy

Return Value real(kind=dp)


Variables

Type Visibility Attributes Name Initial
integer, public :: i
integer, public :: ix
integer, public :: iy
integer, public :: m
integer, public :: mp1
integer, public :: ns

Source Code

pure function ddot(N,Dx,Incx,Dy,Incy)
!
real(kind=dp)            :: ddot
integer,intent(in)       :: N
real(kind=dp),intent(in) :: Dx(*)
integer,intent(in)       :: Incx
real(kind=dp),intent(in) :: Dy(*)
integer, intent(in)      :: Incy
!
integer :: i, ix, iy, m, mp1, ns
!
   ddot = 0.0D0
   if ( N<=0 ) return
   if ( Incx==Incy ) then
      if ( Incx<1 ) then
      elseif ( Incx==1 ) then
         !
         !      Code for both increments equal to 1.
         !
         !      Clean-up loop so remaining vector length is a multiple of 5.
         !
         m = mod(N,5)
         if ( m/=0 ) then
            do i = 1 , m
               ddot = ddot + Dx(i)*Dy(i)
            enddo
            if ( N<5 ) return
         endif
         mp1 = m + 1
         do i = mp1 , N , 5
            ddot = ddot + Dx(i)*Dy(i) + Dx(i+1)*Dy(i+1) + Dx(i+2)*Dy(i+2) + Dx(i+3)*Dy(i+3) + Dx(i+4)*Dy(i+4)
         enddo
         return
      else
         !
         !      Code for equal, positive, non-unit increments.
         !
         ns = N*Incx
         do i = 1 , ns , Incx
            ddot = ddot + Dx(i)*Dy(i)
         enddo
         return
      endif
   endif
   !
   !      Code for unequal or nonpositive increments.
   !
   ix = 1
   iy = 1
   if ( Incx<0 ) ix = (-N+1)*Incx + 1
   if ( Incy<0 ) iy = (-N+1)*Incy + 1

   do i = 1 , N
      ddot = ddot + Dx(ix)*Dy(iy)
      ix = ix + Incx
      iy = iy + Incy
   enddo
end function ddot