Debian Codegraph @

src/mbd_linalg.F90

raw
1 ! This Source Code Form is subject to the terms of the Mozilla Public
2 ! License, v. 2.0. If a copy of the MPL was not distributed with this
3 ! file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 module mbd_linalg
5
6 use mbd_constants
7
8 implicit none
9
10 private
11 public :: outer, eye, diag
12
13 interface diag
14 module procedure get_diag_real
15 module procedure get_diag_complex
16 module procedure make_diag_real
17 end interface
18
19 contains
20
21 function outer(a, b) result(c)
22 real(dp), intent(in) :: a(:), b(:)
23 real(dp) :: c(size(a), size(b))
24
25 integer :: i, j
26
27 do i = 1, size(a)
28 do j = 1, size(b)
29 c(i, j) = a(i) * b(j)
30 end do
31 end do
32 end function
33
34 function eye(n) result(A)
35 integer, intent(in) :: n
36 real(dp) :: A(n, n)
37
38 integer :: i
39
40 A(:, :) = 0.d0
41 do concurrent(i=1:n)
42 A(i, i) = 1.d0
43 end do
44 end function
45
46 function get_diag_real(A) result(d)
47 real(dp), intent(in) :: A(:, :)
48 real(dp) :: d(size(A, 1))
49
50 integer :: i
51
52 do concurrent(i=1:size(A, 1))
53 d(i) = A(i, i)
54 end do
55 end function
56
57 function get_diag_complex(A) result(d)
58 complex(dp), intent(in) :: A(:, :)
59 complex(dp) :: d(size(A, 1))
60
61 integer :: i
62
63 do concurrent(i=1:size(A, 1))
64 d(i) = A(i, i)
65 end do
66 end function
67
68 function make_diag_real(d) result(A)
69 real(dp), intent(in) :: d(:)
70 real(dp) :: A(size(d), size(d))
71
72 integer :: i
73
74 A(:, :) = 0.d0
75 do concurrent(i=1:size(d))
76 A(i, i) = d(i)
77 end do
78 end function
79
80 end module