Skip to content

Commit 7b7c051

Browse files
committed
submodule
1 parent 4cef2ac commit 7b7c051

File tree

2 files changed

+49
-30
lines changed

2 files changed

+49
-30
lines changed

src/stdlib_linalg.fypp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#:include "common.fypp"
2-
#:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES
2+
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
3+
#:set RCI_KINDS_TYPES = RC_KINDS_TYPES + INT_KINDS_TYPES
4+
#:set RHS_SUFFIX = ["one","many"]
5+
#:set RHS_SYMBOL = [ranksuffix(r) for r in [1,2]]
6+
#:set RHS_EMPTY = [emptyranksuffix(r) for r in [1,2]]
7+
#:set ALL_RHS = list(zip(RHS_SYMBOL,RHS_SUFFIX,RHS_EMPTY))
38
module stdlib_linalg
49
!!Provides a support for various linear algebra procedures
510
!! ([Specification](../page/specs/stdlib_linalg.html))
6-
use stdlib_kinds, only: sp, dp, xdp, qp, &
7-
int8, int16, int32, int64
11+
use stdlib_kinds, only: xdp, int8, int16, int32, int64
12+
use stdlib_linalg_constants, only: sp, dp, qp, lk, ilp
813
use stdlib_error, only: error_stop
914
use stdlib_optval, only: optval
15+
use stdlib_linalg_state, only: linalg_state_type, linalg_error_handling
1016
implicit none
1117
private
1218

1319
public :: diag
1420
public :: eye
21+
public :: solve
1522
public :: trace
1623
public :: outer_product
1724
public :: kronecker_product
@@ -214,6 +221,36 @@ module stdlib_linalg
214221
#:endfor
215222
end interface is_hessenberg
216223

224+
! Solve linear system system Ax=b.
225+
interface solve
226+
#:for nd,ndsuf,nde in ALL_RHS
227+
#:for rk,rt,ri in RC_KINDS_TYPES
228+
#:if rk!="xdp"
229+
module function stdlib_linalg_${ri}$_solve_${ndsuf}$(a,b,overwrite_a,err) result(x)
230+
!> Input matrix a[n,n]
231+
${rt}$, intent(inout), target :: a(:,:)
232+
!> Right hand side vector or array, b[n] or b[n,nrhs]
233+
${rt}$, intent(in) :: b${nd}$
234+
!> [optional] Can A data be overwritten and destroyed?
235+
logical(lk), optional, intent(in) :: overwrite_a
236+
!> [optional] state return flag. On error if not requested, the code will stop
237+
type(linalg_state_type), intent(out) :: err
238+
!> Result array/matrix x[n] or x[n,nrhs]
239+
${rt}$, allocatable, target :: x${nd}$
240+
end function stdlib_linalg_${ri}$_solve_${ndsuf}$
241+
pure module function stdlib_linalg_${ri}$_pure_solve_${ndsuf}$(a,b) result(x)
242+
!> Input matrix a[n,n]
243+
${rt}$, intent(in), target :: a(:,:)
244+
!> Right hand side vector or array, b[n] or b[n,nrhs]
245+
${rt}$, intent(in) :: b${nd}$
246+
!> Result array/matrix x[n] or x[n,nrhs]
247+
${rt}$, allocatable, target :: x${nd}$
248+
end function stdlib_linalg_${ri}$_pure_solve_${ndsuf}$
249+
#:endif
250+
#:endfor
251+
#:endfor
252+
end interface solve
253+
217254
contains
218255

219256

src/stdlib_linalg_solve.fypp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,13 @@
44
#:set RHS_SYMBOL = [ranksuffix(r) for r in [1,2]]
55
#:set RHS_EMPTY = [emptyranksuffix(r) for r in [1,2]]
66
#:set ALL_RHS = list(zip(RHS_SYMBOL,RHS_SUFFIX,RHS_EMPTY))
7-
module stdlib_linalg_solve
7+
submodule (stdlib_linalg) stdlib_linalg_solve
8+
!! Solve linear system Ax=b
89
use stdlib_linalg_constants
910
use stdlib_linalg_lapack, only: gesv
1011
use stdlib_linalg_state, only: linalg_state_type, linalg_error_handling, LINALG_ERROR, &
1112
LINALG_INTERNAL_ERROR, LINALG_VALUE_ERROR
1213
implicit none(type,external)
13-
14-
!> Solve a linear system
15-
public :: solve
16-
17-
! NumPy: solve(a, b)
18-
! Scipy: solve(a, b, lower=False, overwrite_a=False, overwrite_b=False, check_finite=True, assume_a='gen', transposed=False)[source]#
19-
! IMSL: lu_solve(a, b, transpose=False)
20-
21-
interface solve
22-
#:for nd,ndsuf,nde in ALL_RHS
23-
#:for rk,rt,ri in RC_KINDS_TYPES
24-
#:if rk!="xdp"
25-
module procedure stdlib_linalg_${ri}$_solve_${ndsuf}$
26-
module procedure stdlib_linalg_${ri}$_pure_solve_${ndsuf}$
27-
#:endif
28-
#:endfor
29-
#:endfor
30-
end interface solve
31-
3214

3315
character(*), parameter :: this = 'solve'
3416

@@ -62,7 +44,7 @@ module stdlib_linalg_solve
6244
#:for rk,rt,ri in RC_KINDS_TYPES
6345
#:if rk!="xdp"
6446
! Compute the solution to a real system of linear equations A * X = B
65-
function stdlib_linalg_${ri}$_solve_${ndsuf}$(a,b,overwrite_a,err) result(x)
47+
module function stdlib_linalg_${ri}$_solve_${ndsuf}$(a,b,overwrite_a,err) result(x)
6648
!> Input matrix a[n,n]
6749
${rt}$, intent(inout), target :: a(:,:)
6850
!> Right hand side vector or array, b[n] or b[n,nrhs]
@@ -74,14 +56,14 @@ module stdlib_linalg_solve
7456
!> Result array/matrix x[n] or x[n,nrhs]
7557
${rt}$, allocatable, target :: x${nd}$
7658

77-
!> Local variables
59+
! Local variables
7860
type(linalg_state_type) :: err0
7961
integer(ilp) :: lda,n,ldb,nrhs,info
8062
integer(ilp), allocatable :: ipiv(:)
8163
logical(lk) :: copy_a
8264
${rt}$, pointer :: xmat(:,:),amat(:,:)
8365

84-
!> Problem sizes
66+
! Problem sizes
8567
lda = size(a,1,kind=ilp)
8668
n = size(a,2,kind=ilp)
8769
ldb = size(b,1,kind=ilp)
@@ -130,22 +112,22 @@ module stdlib_linalg_solve
130112
end function stdlib_linalg_${ri}$_solve_${ndsuf}$
131113

132114
! Compute the solution to a real system of linear equations A * X = B (pure interface)
133-
pure function stdlib_linalg_${ri}$_pure_solve_${ndsuf}$(a,b) result(x)
115+
pure module function stdlib_linalg_${ri}$_pure_solve_${ndsuf}$(a,b) result(x)
134116
!> Input matrix a[n,n]
135117
${rt}$, intent(in), target :: a(:,:)
136118
!> Right hand side vector or array, b[n] or b[n,nrhs]
137119
${rt}$, intent(in) :: b${nd}$
138120
!> Result array/matrix x[n] or x[n,nrhs]
139121
${rt}$, allocatable, target :: x${nd}$
140122

141-
!> Local variables
123+
! Local variables
142124
type(linalg_state_type) :: err0
143125
integer(ilp) :: lda,n,ldb,nrhs,info
144126
integer(ilp), allocatable :: ipiv(:)
145127
${rt}$, pointer :: xmat(:,:)
146128
${rt}$, allocatable :: amat(:,:)
147129

148-
!> Problem sizes
130+
! Problem sizes
149131
lda = size(a,1,kind=ilp)
150132
n = size(a,2,kind=ilp)
151133
ldb = size(b,1,kind=ilp)
@@ -185,4 +167,4 @@ module stdlib_linalg_solve
185167
#:endfor
186168
#:endfor
187169

188-
end module stdlib_linalg_solve
170+
end submodule stdlib_linalg_solve

0 commit comments

Comments
 (0)