Skip to content

Commit 1af9ea9

Browse files
committed
blas_aux template
1 parent 65b1ec6 commit 1af9ea9

File tree

2 files changed

+51
-28
lines changed

2 files changed

+51
-28
lines changed

include/common.fypp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ $:"s" if cmplx=="c" else "d" if cmplx=="z" else "x" if cmplx=="y" else "q" if cm
7777
#! BLAS/LAPACK/Linear Algebra Integer Kinds
7878
#:set LINALG_INT_KINDS = ["ilp","ilp64"]
7979
#:set LINALG_INT_TYPES = ["integer({})".format(k) for k in LINALG_INT_KINDS]
80-
#:set LINALG_INT_KINDS_TYPES = list(zip(LINALG_INT_KINDS, LINALG_INT_TYPES))
80+
#:set LINALG_INT_SUFFIX = ["_{}".format(k) for k in LINALG_INT_KINDS]
81+
#:set LINALG_INT_KINDS_TYPES = list(zip(LINALG_INT_KINDS, LINALG_INT_TYPES, LINALG_INT_SUFFIX))
8182

8283
#! Complex types to be considered during templating
8384
#:set CMPLX_TYPES = ["complex({})".format(k) for k in CMPLX_KINDS]

src/stdlib_linalg_blas_aux.fypp

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ module stdlib_linalg_blas_aux
2121
#:endfor
2222
end interface stdlib_cabs1
2323

24+
#:for rk,rt,ri in RC_KINDS_TYPES
25+
interface stdlib_i${ri}$amax
26+
#:for ik,it,ii in LINALG_INT_KINDS_TYPES
27+
module procedure stdlib${ii}$_i${ri}$amax
28+
#:endfor
29+
end interface stdlib_i${ri}$amax
30+
#:endfor
31+
32+
interface stdlib_xerbla
33+
#:for ik,it,ii in LINALG_INT_KINDS_TYPES
34+
module procedure stdlib${ii}$_xerbla
35+
#:endfor
36+
end interface stdlib_xerbla
37+
38+
interface stdlib_xerbla_array
39+
#:for ik,it,ii in LINALG_INT_KINDS_TYPES
40+
module procedure stdlib${ii}$_xerbla_array
41+
#:endfor
42+
end interface stdlib_xerbla_array
43+
44+
2445
contains
2546

2647

@@ -57,13 +78,13 @@ module stdlib_linalg_blas_aux
5778
stdlib_lsame = ca == cb
5879
if (stdlib_lsame) return
5980
! now test for equivalence if both characters are alphabetic.
60-
zcode = ichar('Z')
81+
zcode = ichar('Z',kind=ilp)
6182
! use 'z' rather than 'a' so that ascii can be detected on prime
6283
! machines, on which ichar returns a value with bit 8 set.
6384
! ichar('a') on prime machines returns 193 which is the same as
6485
! ichar('a') on an ebcdic machine.
65-
inta = ichar(ca)
66-
intb = ichar(cb)
86+
inta = ichar(ca,kind=ilp)
87+
intb = ichar(cb,kind=ilp)
6788
if (zcode==90 .or. zcode==122) then
6889
! ascii is assumed - zcode is the ascii code of either lower or
6990
! upper case 'z'.
@@ -86,7 +107,8 @@ module stdlib_linalg_blas_aux
86107
! return
87108
end function stdlib_lsame
88109

89-
pure subroutine stdlib_xerbla( srname, info )
110+
#:for ik,it,ii in LINALG_INT_KINDS_TYPES
111+
pure subroutine stdlib${ii}$_xerbla( srname, info )
90112
!! XERBLA is an error handler for the LAPACK routines.
91113
!! It is called by an LAPACK routine if an input parameter has an
92114
!! invalid value. A message is printed and execution stops.
@@ -97,17 +119,17 @@ module stdlib_linalg_blas_aux
97119
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
98120
! Scalar Arguments
99121
character(len=*), intent(in) :: srname
100-
integer(ilp), intent(in) :: info
122+
integer(${ik}$), intent(in) :: info
101123
! =====================================================================
102124
! Intrinsic Functions
103125
intrinsic :: len_trim
104126
! Executable Statements
105127
9999 format( ' ** ON ENTRY TO ', a, ' PARAMETER NUMBER ', i2, ' HAD ','AN ILLEGAL VALUE' )
106128

107-
end subroutine stdlib_xerbla
129+
end subroutine stdlib${ii}$_xerbla
108130

109131

110-
pure subroutine stdlib_xerbla_array(srname_array, srname_len, info)
132+
pure subroutine stdlib${ii}$_xerbla_array(srname_array, srname_len, info)
111133
!! XERBLA_ARRAY assists other languages in calling XERBLA, the LAPACK
112134
!! and BLAS error handler. Rather than taking a Fortran string argument
113135
!! as the function's name, XERBLA_ARRAY takes an array of single
@@ -128,12 +150,12 @@ module stdlib_linalg_blas_aux
128150
! -- reference blas is a software package provided by univ. of tennessee, --
129151
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
130152
! Scalar Arguments
131-
integer(ilp), intent(in) :: srname_len, info
153+
integer(${ik}$), intent(in) :: srname_len, info
132154
! Array Arguments
133155
character(1), intent(in) :: srname_array(srname_len)
134156
! =====================================================================
135157
! Local Scalars
136-
integer(ilp) :: i
158+
integer(${ik}$) :: i
137159
! Local Arrays
138160
character*32 srname
139161
! Intrinsic Functions
@@ -145,34 +167,34 @@ module stdlib_linalg_blas_aux
145167
end do
146168
call stdlib_xerbla( srname, info )
147169
return
148-
end subroutine stdlib_xerbla_array
170+
end subroutine stdlib${ii}$_xerbla_array
149171

150172
#:for rk,rt,ri in REAL_KINDS_TYPES
151-
pure integer(ilp) function stdlib_i${ri}$amax(n,dx,incx)
173+
pure integer(${ik}$) function stdlib${ii}$_i${ri}$amax(n,dx,incx) result(iamax)
152174
!! IDAMAX: finds the index of the first element having maximum absolute value.
153175
! -- reference blas level1 routine --
154176
! -- reference blas is a software package provided by univ. of tennessee, --
155177
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
156178
! Scalar Arguments
157-
integer(ilp), intent(in) :: incx, n
179+
integer(${ik}$), intent(in) :: incx, n
158180
! Array Arguments
159181
real(${rk}$), intent(in) :: dx(*)
160182
! =====================================================================
161183
! Local Scalars
162184
real(${rk}$) :: dmax
163-
integer(ilp) :: i, ix
185+
integer(${ik}$) :: i, ix
164186
! Intrinsic Functions
165187
intrinsic :: abs
166-
stdlib_i${ri}$amax = 0
188+
iamax = 0
167189
if (n<1 .or. incx<=0) return
168-
stdlib_i${ri}$amax = 1
190+
iamax = 1
169191
if (n==1) return
170192
if (incx==1) then
171193
! code for increment equal to 1
172194
dmax = abs(dx(1))
173195
do i = 2,n
174196
if (abs(dx(i))>dmax) then
175-
stdlib_i${ri}$amax = i
197+
iamax = i
176198
dmax = abs(dx(i))
177199
end if
178200
end do
@@ -183,41 +205,40 @@ module stdlib_linalg_blas_aux
183205
ix = ix + incx
184206
do i = 2,n
185207
if (abs(dx(ix))>dmax) then
186-
stdlib_i${ri}$amax = i
208+
iamax = i
187209
dmax = abs(dx(ix))
188210
end if
189211
ix = ix + incx
190212
end do
191213
end if
192214
return
193-
end function stdlib_i${ri}$amax
215+
end function stdlib${ii}$_i${ri}$amax
194216

195217
#:endfor
196-
197218
#:for ck,ct,ci in CMPLX_KINDS_TYPES
198-
pure integer(ilp) function stdlib_i${ci}$amax(n,zx,incx)
219+
pure integer(${ik}$) function stdlib${ii}$_i${ci}$amax(n,zx,incx) result(iamax)
199220
!! IZAMAX: finds the index of the first element having maximum |Re(.)| + |Im(.)|
200221
! -- reference blas level1 routine --
201222
! -- reference blas is a software package provided by univ. of tennessee, --
202223
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
203224
! Scalar Arguments
204-
integer(ilp), intent(in) :: incx, n
225+
integer(${ik}$), intent(in) :: incx, n
205226
! Array Arguments
206227
complex(${ck}$), intent(in) :: zx(*)
207228
! =====================================================================
208229
! Local Scalars
209230
real(${ck}$) :: dmax
210-
integer(ilp) :: i, ix
211-
stdlib_i${ci}$amax = 0
231+
integer(${ik}$) :: i, ix
232+
iamax = 0
212233
if (n<1 .or. incx<=0) return
213-
stdlib_i${ci}$amax = 1
234+
iamax = 1
214235
if (n==1) return
215236
if (incx==1) then
216237
! code for increment equal to 1
217238
dmax = stdlib_cabs1(zx(1))
218239
do i = 2,n
219240
if (stdlib_cabs1(zx(i))>dmax) then
220-
stdlib_i${ci}$amax = i
241+
iamax = i
221242
dmax = stdlib_cabs1(zx(i))
222243
end if
223244
end do
@@ -228,15 +249,16 @@ module stdlib_linalg_blas_aux
228249
ix = ix + incx
229250
do i = 2,n
230251
if (stdlib_cabs1(zx(ix))>dmax) then
231-
stdlib_i${ci}$amax = i
252+
iamax = i
232253
dmax = stdlib_cabs1(zx(ix))
233254
end if
234255
ix = ix + incx
235256
end do
236257
end if
237258
return
238-
end function stdlib_i${ci}$amax
259+
end function stdlib${ii}$_i${ci}$amax
239260

240261
#:endfor
262+
#:endfor
241263

242264
end module stdlib_linalg_blas_aux

0 commit comments

Comments
 (0)