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