Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / dpotrf.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6 static integer c_n1 = -1;
7 static doublereal c_b13 = -1.;
8 static doublereal c_b14 = 1.;
9
10 /* Subroutine */ int dpotrf_(char *uplo, integer *n, doublereal *a, integer *
11         lda, integer *info)
12 {
13     /* System generated locals */
14     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
15
16     /* Local variables */
17     integer j, jb, nb;
18     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, 
19             integer *, doublereal *, doublereal *, integer *, doublereal *, 
20             integer *, doublereal *, doublereal *, integer *);
21     extern logical lsame_(char *, char *);
22     extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *, 
23             integer *, integer *, doublereal *, doublereal *, integer *, 
24             doublereal *, integer *);
25     logical upper;
26     extern /* Subroutine */ int dsyrk_(char *, char *, integer *, integer *, 
27             doublereal *, doublereal *, integer *, doublereal *, doublereal *, 
28              integer *), dpotf2_(char *, integer *, 
29             doublereal *, integer *, integer *), xerbla_(char *, 
30             integer *);
31     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
32             integer *, integer *);
33
34
35 /*  -- LAPACK routine (version 3.1) -- */
36 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
37 /*     November 2006 */
38
39 /*     .. Scalar Arguments .. */
40 /*     .. */
41 /*     .. Array Arguments .. */
42 /*     .. */
43
44 /*  Purpose */
45 /*  ======= */
46
47 /*  DPOTRF computes the Cholesky factorization of a real symmetric */
48 /*  positive definite matrix A. */
49
50 /*  The factorization has the form */
51 /*     A = U**T * U,  if UPLO = 'U', or */
52 /*     A = L  * L**T,  if UPLO = 'L', */
53 /*  where U is an upper triangular matrix and L is lower triangular. */
54
55 /*  This is the block version of the algorithm, calling Level 3 BLAS. */
56
57 /*  Arguments */
58 /*  ========= */
59
60 /*  UPLO    (input) CHARACTER*1 */
61 /*          = 'U':  Upper triangle of A is stored; */
62 /*          = 'L':  Lower triangle of A is stored. */
63
64 /*  N       (input) INTEGER */
65 /*          The order of the matrix A.  N >= 0. */
66
67 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
68 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
69 /*          N-by-N upper triangular part of A contains the upper */
70 /*          triangular part of the matrix A, and the strictly lower */
71 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
72 /*          leading N-by-N lower triangular part of A contains the lower */
73 /*          triangular part of the matrix A, and the strictly upper */
74 /*          triangular part of A is not referenced. */
75
76 /*          On exit, if INFO = 0, the factor U or L from the Cholesky */
77 /*          factorization A = U**T*U or A = L*L**T. */
78
79 /*  LDA     (input) INTEGER */
80 /*          The leading dimension of the array A.  LDA >= max(1,N). */
81
82 /*  INFO    (output) INTEGER */
83 /*          = 0:  successful exit */
84 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
85 /*          > 0:  if INFO = i, the leading minor of order i is not */
86 /*                positive definite, and the factorization could not be */
87 /*                completed. */
88
89 /*  ===================================================================== */
90
91 /*     .. Parameters .. */
92 /*     .. */
93 /*     .. Local Scalars .. */
94 /*     .. */
95 /*     .. External Functions .. */
96 /*     .. */
97 /*     .. External Subroutines .. */
98 /*     .. */
99 /*     .. Intrinsic Functions .. */
100 /*     .. */
101 /*     .. Executable Statements .. */
102
103 /*     Test the input parameters. */
104
105     /* Parameter adjustments */
106     a_dim1 = *lda;
107     a_offset = 1 + a_dim1;
108     a -= a_offset;
109
110     /* Function Body */
111     *info = 0;
112     upper = lsame_(uplo, "U");
113     if (! upper && ! lsame_(uplo, "L")) {
114         *info = -1;
115     } else if (*n < 0) {
116         *info = -2;
117     } else if (*lda < max(1,*n)) {
118         *info = -4;
119     }
120     if (*info != 0) {
121         i__1 = -(*info);
122         xerbla_("DPOTRF", &i__1);
123         return 0;
124     }
125
126 /*     Quick return if possible */
127
128     if (*n == 0) {
129         return 0;
130     }
131
132 /*     Determine the block size for this environment. */
133
134     nb = ilaenv_(&c__1, "DPOTRF", uplo, n, &c_n1, &c_n1, &c_n1);
135     if (nb <= 1 || nb >= *n) {
136
137 /*        Use unblocked code. */
138
139         dpotf2_(uplo, n, &a[a_offset], lda, info);
140     } else {
141
142 /*        Use blocked code. */
143
144         if (upper) {
145
146 /*           Compute the Cholesky factorization A = U'*U. */
147
148             i__1 = *n;
149             i__2 = nb;
150             for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
151
152 /*              Update and factorize the current diagonal block and test */
153 /*              for non-positive-definiteness. */
154
155 /* Computing MIN */
156                 i__3 = nb, i__4 = *n - j + 1;
157                 jb = min(i__3,i__4);
158                 i__3 = j - 1;
159                 dsyrk_("Upper", "Transpose", &jb, &i__3, &c_b13, &a[j * 
160                         a_dim1 + 1], lda, &c_b14, &a[j + j * a_dim1], lda);
161                 dpotf2_("Upper", &jb, &a[j + j * a_dim1], lda, info);
162                 if (*info != 0) {
163                     goto L30;
164                 }
165                 if (j + jb <= *n) {
166
167 /*                 Compute the current block row. */
168
169                     i__3 = *n - j - jb + 1;
170                     i__4 = j - 1;
171                     dgemm_("Transpose", "No transpose", &jb, &i__3, &i__4, &
172                             c_b13, &a[j * a_dim1 + 1], lda, &a[(j + jb) * 
173                             a_dim1 + 1], lda, &c_b14, &a[j + (j + jb) * 
174                             a_dim1], lda);
175                     i__3 = *n - j - jb + 1;
176                     dtrsm_("Left", "Upper", "Transpose", "Non-unit", &jb, &
177                             i__3, &c_b14, &a[j + j * a_dim1], lda, &a[j + (j 
178                             + jb) * a_dim1], lda);
179                 }
180 /* L10: */
181             }
182
183         } else {
184
185 /*           Compute the Cholesky factorization A = L*L'. */
186
187             i__2 = *n;
188             i__1 = nb;
189             for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
190
191 /*              Update and factorize the current diagonal block and test */
192 /*              for non-positive-definiteness. */
193
194 /* Computing MIN */
195                 i__3 = nb, i__4 = *n - j + 1;
196                 jb = min(i__3,i__4);
197                 i__3 = j - 1;
198                 dsyrk_("Lower", "No transpose", &jb, &i__3, &c_b13, &a[j + 
199                         a_dim1], lda, &c_b14, &a[j + j * a_dim1], lda);
200                 dpotf2_("Lower", &jb, &a[j + j * a_dim1], lda, info);
201                 if (*info != 0) {
202                     goto L30;
203                 }
204                 if (j + jb <= *n) {
205
206 /*                 Compute the current block column. */
207
208                     i__3 = *n - j - jb + 1;
209                     i__4 = j - 1;
210                     dgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &
211                             c_b13, &a[j + jb + a_dim1], lda, &a[j + a_dim1], 
212                             lda, &c_b14, &a[j + jb + j * a_dim1], lda);
213                     i__3 = *n - j - jb + 1;
214                     dtrsm_("Right", "Lower", "Transpose", "Non-unit", &i__3, &
215                             jb, &c_b14, &a[j + j * a_dim1], lda, &a[j + jb + 
216                             j * a_dim1], lda);
217                 }
218 /* L20: */
219             }
220         }
221     }
222     goto L40;
223
224 L30:
225     *info = *info + j - 1;
226
227 L40:
228     return 0;
229
230 /*     End of DPOTRF */
231
232 } /* dpotrf_ */