NULAPACK
NUmerical Linear Algebra PACKage
Loading...
Searching...
No Matches
spoctrf.f
Go to the documentation of this file.
1C ====================================================================
2C N U L A P A C K
3C U U L A P A C K
4C L L L A P A C K
5C A A A A P A C K
6C P P P P P A C K
7C A A A A A A C K
8C C C C C C C C K
9C K K K K K K K K
10C
11C This file is part of NULAPACK - NUmerical Linear Algebra PACKage
12C
13C Copyright (C) 2025 Saud Zahir
14C
15C NULAPACK is free software: you can redistribute it and/or modify
16C it under the terms of the GNU General Public License as published by
17C the Free Software Foundation, either version 3 of the License, or
18C (at your option) any later version.
19C
20C NULAPACK is distributed in the hope that it will be useful,
21C but WITHOUT ANY WARRANTY; without even the implied warranty of
22C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23C GNU General Public License for more details.
24C
25C You should have received a copy of the GNU General Public License
26C along with NULAPACK. If not, see <https://www.gnu.org/licenses/>.
27C
28C ====================================================================
29C SPOCTRF - Cholesky Factorization for A = L * L^T
30C ====================================================================
31C Description:
32C ------------------------------------------------------------------
33C Computes the Cholesky factorization of a real symmetric
34C positive-definite matrix A stored in a flat row-major array.
35C The lower-triangular matrix L overwrites the lower triangle of A.
36C
37C On output: A contains L in the lower triangle, upper triangle is
38C not referenced.
39C
40C ====================================================================
41C Arguments:
42C ------------------------------------------------------------------
43C N : INTEGER -> order of the matrix
44C A(*) : REAL -> flat row-major matrix, size (LDA*N)
45C L(*) : REAL -> flat row-major matrix, size (LDA*N)
46C LDA : INTEGER -> leading dimension of A (usually N)
47C INFO : INTEGER -> return code:
48C 0 = success
49C <0 = illegal argument
50C >0 = matrix not positive definite
51C ====================================================================
52 SUBROUTINE spoctrf(N, A, L, LDA, INFO)
53
54C I m p l i c i t t y p e s
55C ------------------------------------------------------------------
56 IMPLICIT NONE
57
58C D u m m y a r g u m e n t s
59C ------------------------------------------------------------------
60 INTEGER :: N, LDA, INFO
61 REAL :: A(*), L(*)
62
63C L o c a l v a r i a b l e s
64C ------------------------------------------------------------------
65 INTEGER :: I, J, K, INDEX
66 REAL :: SUM
67
68C I n i t i a l i z e
69C ------------------------------------------------------------------
70 info = 0
71
72C M a i n l o o p o v e r r o w s
73C ------------------------------------------------------------------
74 DO i = 1, n
75
76C Compute diagonal element L(I,I)
77 sum = 0.0
78 DO k = 1, i-1
79 index = (i-1)*lda + k
80 sum = sum + l(index)*l(index)
81 END DO
82
83 index = (i-1)*lda + i
84 IF (a(index) - sum .LE. 0.0) THEN
85 info = i
86 RETURN
87 END IF
88 l(index) = sqrt(a(index) - sum)
89
90C Compute off-diagonal elements L(J,I), J = I+1:N
91 DO j = i+1, n
92 sum = 0.0
93 DO k = 1, i-1
94 sum = sum + l((j-1)*lda + k) * l((i-1)*lda + k)
95 END DO
96 index = (j-1)*lda + i
97 l(index) = (a(index) - sum)/l((i-1)*lda + i)
98 END DO
99
100 END DO
101
102C S u c c e s s f u l e x i t
103C ------------------------------------------------------------------
104 RETURN
105 END
subroutine spoctrf(n, a, l, lda, info)
Definition spoctrf.f:53