Skip to content

Commit 0562593

Browse files
committed
automate type conversion routines
1 parent 68b8175 commit 0562593

6 files changed

+80
-26
lines changed

scripts/modularize_blas.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def create_constants_module(module_name,out_folder,stdlib_integration=None):
3636
fid.write(INDENT + "implicit none(type,external)\n")
3737
fid.write(INDENT + "public\n\n\n\n")
3838

39-
#:if WITH_QP
40-
#:set REAL_KINDS = REAL_KINDS + ["qp"]
41-
#:endif
42-
4339
# Temporary: to be replaced with stdlib_kinds
4440
if not stdlib_integration:
4541
fid.write(INDENT + "integer, parameter :: sp = real32\n")
@@ -51,9 +47,6 @@ def create_constants_module(module_name,out_folder,stdlib_integration=None):
5147
fid.write(INDENT + "integer, parameter :: ilp = int32\n")
5248
fid.write(INDENT + "private :: int32, int64\n\n\n")
5349

54-
# Arithmetic constants (private)
55-
# print_lapack_constants(fid,INDENT)
56-
5750
# Close module
5851
fid.write("\n\n\n\n\nend module {}\n".format(module_name))
5952

@@ -109,7 +102,7 @@ def patch_lapack_aux(fid,prefix,indent):
109102
# Read all source files from the source folder, process them, refactor them, and put all
110103
# subroutines/function into a module
111104
def create_fortran_module(module_name,source_folder,out_folder,prefix,ext_functions,used_modules, \
112-
split_by_initial,stdlib_export=False):
105+
split_by_initial=True,stdlib_export=False):
113106

114107
from datetime import date
115108
from platform import os
@@ -487,7 +480,6 @@ def double_to_quad(lines,initial,newinit,prefix,procedure_name=None):
487480
whole = re.sub(prefix[:-1]+r'\_delect',prefix+r'select',whole)
488481
whole = re.sub(prefix[:-1]+r'\_dlag2d',prefix+r'dlag2q',whole)
489482
whole = re.sub(prefix[:-1]+r'\_zlag2z',prefix+r'zlag2w',whole)
490-
whole = re.sub(prefix[:-1]+r'\_zlag2w',prefix+r'clag2z',whole)
491483

492484
whole = re.sub(r'32\-bit',r'64-bit',whole)
493485
whole = re.sub(r'single precision',r'double precision',whole)
@@ -3138,11 +3130,13 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
31383130
double_procedure.new_name = prefix+double_procedure.old_name
31393131

31403132
whole = '\n'.join(double_procedure.body)
3141-
whole = whole.replace(prefix+single_to_double[kk],prefix+single_to_doublen[kk])
3133+
whole = whole.replace(single_to_double[kk],single_to_doublen[kk])
3134+
whole = whole.replace(single_to_double[kk].upper(),single_to_doublen[kk].upper())
31423135
double_procedure.body = whole.splitlines()
31433136

31443137
whole = '\n'.join(double_procedure.header)
3145-
whole = whole.replace(prefix+single_to_double[kk],prefix+single_to_doublen[kk])
3138+
whole = whole.replace(single_to_double[kk],single_to_doublen[kk])
3139+
whole = whole.replace(single_to_double[kk].upper(),single_to_doublen[kk].upper())
31463140
double_procedure.header = whole.splitlines()
31473141

31483142
Procedures.append(double_procedure)
@@ -3253,19 +3247,18 @@ def parse_interfaces(Sources):
32533247

32543248
# Run script
32553249
funs = []
3256-
create_constants_module("stdlib_linalg_constants","../src")
3250+
create_constants_module("stdlib_linalg_constants","../src",False)
32573251
funs = create_fortran_module("stdlib_linalg_blas",\
32583252
"../assets/reference_lapack/BLAS/SRC","../src",\
32593253
"stdlib_",\
32603254
funs,\
3261-
["stdlib_linalg_constants"],True,True)
3262-
#funs = create_fortran_module("stdlib_linalg_lapack",\
3263-
# "../assets/lapack_sources",\
3264-
# "../src",\
3265-
# "stdlib_",\
3266-
# funs,\
3267-
# ["stdlib_linalg_constants","stdlib_linalg_blas"],True)
3268-
#create_fortran_module("stdlib_linalg_blas_test_eig","../assets/reference_lapack/TESTING/EIG","../test","stdlib_test_")
3255+
["stdlib_linalg_constants"],True,False)
3256+
funs = create_fortran_module("stdlib_linalg_lapack",\
3257+
"../assets/lapack_sources",\
3258+
"../src",\
3259+
"stdlib_",\
3260+
funs,\
3261+
["stdlib_linalg_constants","stdlib_linalg_blas"],True)
32693262

32703263

32713264

src/stdlib_linalg_constants.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module stdlib_linalg_constants
2-
use iso_fortran_env,only:int32,int64
2+
use iso_fortran_env,only:real32,real64,real128,int32,int64
33
use,intrinsic :: ieee_arithmetic,only:ieee_is_nan
44
#if defined(_OPENMP)
55
use omp_lib
66
#endif
77
implicit none(type,external)
88
public
99

10-
integer,parameter :: sp = selected_real_kind(6)
11-
integer,parameter :: dp = selected_real_kind(15)
12-
integer,parameter :: qp = selected_real_kind(33)
10+
integer,parameter :: sp = real32
11+
integer,parameter :: dp = real64
12+
integer,parameter :: qp = real128
1313
integer,parameter :: lk = kind(.true.)
1414
! Integer size support for ILP64 builds should be done here
1515
integer,parameter :: ilp = int32

src/stdlib_linalg_lapack_d.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24107,7 +24107,7 @@ pure real(dp) function stdlib_dzsum1(n,cx,incx)
2410724107
return
2410824108
end function stdlib_dzsum1
2410924109

24110-
!> DLAG2Q: converts a DOUBLE PRECISION matrix, SA, to a QUAD
24110+
!> DLAG2Q: converts a SINGLE PRECISION matrix, SA, to a DOUBLE
2411124111
!> PRECISION matrix, A.
2411224112
!> Note that while it is possible to overflow while converting
2411324113
!> from double to single, it is not possible to overflow when

src/stdlib_linalg_lapack_q.f90

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ module stdlib_linalg_lapack_q
478478
public :: stdlib_qtrttp
479479
public :: stdlib_qtzrzf
480480
public :: stdlib_qzsum1
481+
public :: stdlib_qlag2q
481482

482483
! 128-bit real constants
483484
real(qp),parameter,private :: negone = -1.00_qp
@@ -85112,4 +85113,34 @@ pure real(qp) function stdlib_qzsum1(n,cx,incx)
8511285113
return
8511385114
end function stdlib_qzsum1
8511485115

85116+
!> DLAG2Q: converts a SINGLE PRECISION matrix, SA, to a DOUBLE
85117+
!> PRECISION matrix, A.
85118+
!> Note that while it is possible to overflow while converting
85119+
!> from double to single, it is not possible to overflow when
85120+
!> converting from single to double.
85121+
!> This is an auxiliary routine so there is no argument checking.
85122+
85123+
pure subroutine stdlib_qlag2q(m,n,sa,ldsa,a,lda,info)
85124+
! -- lapack auxiliary routine --
85125+
! -- lapack is a software package provided by univ. of tennessee, --
85126+
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
85127+
! Scalar Arguments
85128+
integer(ilp),intent(out) :: info
85129+
integer(ilp),intent(in) :: lda,ldsa,m,n
85130+
! Array Arguments
85131+
real(qp),intent(in) :: sa(ldsa,*)
85132+
real(qp),intent(out) :: a(lda,*)
85133+
! =====================================================================
85134+
! Local Scalars
85135+
integer(ilp) :: i,j
85136+
! Executable Statements
85137+
info = 0
85138+
do j = 1,n
85139+
do i = 1,m
85140+
a(i,j) = sa(i,j)
85141+
end do
85142+
end do
85143+
return
85144+
end subroutine stdlib_qlag2q
85145+
8511585146
end module stdlib_linalg_lapack_q

src/stdlib_linalg_lapack_w.f90

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module stdlib_linalg_lapack_w
1111
private
1212

1313
public :: sp,dp,qp,lk,ilp
14+
public :: stdlib_wlag2w
1415
public :: stdlib_wbbcsd
1516
public :: stdlib_wbdsqr
1617
public :: stdlib_wcgesv
@@ -501,6 +502,35 @@ module stdlib_linalg_lapack_w
501502

502503
contains
503504

505+
!> ZLAG2W: converts a COMPLEX matrix, SA, to a COMPLEX*16 matrix, A.
506+
!> Note that while it is possible to overflow while converting
507+
!> from double to single, it is not possible to overflow when
508+
!> converting from single to double.
509+
!> This is an auxiliary routine so there is no argument checking.
510+
511+
pure subroutine stdlib_wlag2w(m,n,sa,ldsa,a,lda,info)
512+
! -- lapack auxiliary routine --
513+
! -- lapack is a software package provided by univ. of tennessee, --
514+
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
515+
! Scalar Arguments
516+
integer(ilp),intent(out) :: info
517+
integer(ilp),intent(in) :: lda,ldsa,m,n
518+
! Array Arguments
519+
complex(qp),intent(in) :: sa(ldsa,*)
520+
complex(qp),intent(out) :: a(lda,*)
521+
! =====================================================================
522+
! Local Scalars
523+
integer(ilp) :: i,j
524+
! Executable Statements
525+
info = 0
526+
do j = 1,n
527+
do i = 1,m
528+
a(i,j) = sa(i,j)
529+
end do
530+
end do
531+
return
532+
end subroutine stdlib_wlag2w
533+
504534
!> ZBBCSD: computes the CS decomposition of a unitary matrix in
505535
!> bidiagonal-block form,
506536
!> [ B11 | B12 0 0 ]

src/stdlib_linalg_lapack_z.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ module stdlib_linalg_lapack_z
500500

501501
contains
502502

503-
!> ZLAG2W: converts a COMPLEX*16 matrix, SA, to a QUAD-COMPLEX matrix, A.
503+
!> ZLAG2W: converts a COMPLEX matrix, SA, to a COMPLEX*16 matrix, A.
504504
!> Note that while it is possible to overflow while converting
505505
!> from double to single, it is not possible to overflow when
506506
!> converting from single to double.

0 commit comments

Comments
 (0)