time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

dcopy.f (3273B)


      1 !>
      2 ! @license Apache-2.0
      3 !
      4 ! Copyright (c) 2018 The Stdlib Authors.
      5 !
      6 ! Licensed under the Apache License, Version 2.0 (the "License");
      7 ! you may not use this file except in compliance with the License.
      8 ! You may obtain a copy of the License at
      9 !
     10 !    http://www.apache.org/licenses/LICENSE-2.0
     11 !
     12 ! Unless required by applicable law or agreed to in writing, software
     13 ! distributed under the License is distributed on an "AS IS" BASIS,
     14 ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 ! See the License for the specific language governing permissions and
     16 ! limitations under the License.
     17 !<
     18 
     19 !> Copies values from one vector to another vector.
     20 !
     21 ! ## Notes
     22 !
     23 ! * Modified version of reference BLAS level1 routine (version 3.7.0). Updated to "free form" Fortran 95.
     24 !
     25 ! ## Authors
     26 !
     27 ! * Univ. of Tennessee
     28 ! * Univ. of California Berkeley
     29 ! * Univ. of Colorado Denver
     30 ! * NAG Ltd.
     31 !
     32 ! ## History
     33 !
     34 ! * Jack Dongarra, linpack, 3/11/78.
     35 !
     36 !   - modified 12/3/93, array(1) declarations changed to array(*)
     37 !
     38 ! ## License
     39 !
     40 ! From <http://netlib.org/blas/faq.html>:
     41 !
     42 ! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors.
     43 ! >
     44 ! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following:
     45 ! >
     46 ! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original.
     47 ! >
     48 ! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support.
     49 !
     50 ! @param {integer} N - number of values to copy
     51 ! @param {Array<double>} dx - input array
     52 ! @param {integer} strideX - `dx` stride length
     53 ! @param {Array<double>} dy - destination array
     54 ! @param {integer} strideY - `dy` stride length
     55 !<
     56 subroutine dcopy( N, dx, strideX, dy, strideY )
     57   implicit none
     58   ! ..
     59   ! Scalar arguments:
     60   integer :: strideX, strideY, N
     61   ! ..
     62   ! Array arguments:
     63   double precision :: dx(*), dy(*)
     64   ! ..
     65   ! Local scalars:
     66   integer :: mp1, ix, iy, i, m
     67   ! ..
     68   ! Intrinsic functions:
     69   intrinsic mod
     70   ! ..
     71   if ( N <= 0 ) then
     72     return
     73   end if
     74   ! ..
     75   ! If both strides are equal to `1`, use unrolled loops...
     76   if ( strideX == 1 .AND. strideY == 1 ) then
     77     m = mod( N, 7 )
     78     ! ..
     79     ! If we have a remainder, do a clean-up loop...
     80     if ( m /= 0 ) then
     81       do i = 1, m
     82         dy( i ) = dx( i )
     83       end do
     84       if ( N < 7 ) then
     85         return
     86       end if
     87     end if
     88     mp1 = m + 1
     89     do i = mp1, N, 7
     90       dy( i ) = dx( i )
     91       dy( i+1 ) = dx( i+1 )
     92       dy( i+2 ) = dx( i+2 )
     93       dy( i+3 ) = dx( i+3 )
     94       dy( i+4 ) = dx( i+4 )
     95       dy( i+5 ) = dx( i+5 )
     96       dy( i+6 ) = dx( i+6 )
     97     end do
     98   else
     99     if ( strideX < 0 ) then
    100       ix = ((1-N)*strideX) + 1
    101     else
    102       ix = 1
    103     end if
    104     if ( strideY < 0 ) then
    105       iy = ((1-N)*strideY) + 1
    106     else
    107       iy = 1
    108     end if
    109     do i = 1, N
    110       dy( iy ) = dx( ix )
    111       ix = ix + strideX
    112       iy = iy + strideY
    113     end do
    114   end if
    115   return
    116 end subroutine dcopy