Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / strti2.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6
7 /* Subroutine */ int strti2_(char *uplo, char *diag, integer *n, real *a, 
8         integer *lda, integer *info)
9 {
10     /* System generated locals */
11     integer a_dim1, a_offset, i__1, i__2;
12
13     /* Local variables */
14     integer j;
15     real ajj;
16     extern logical lsame_(char *, char *);
17     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
18     logical upper;
19     extern /* Subroutine */ int strmv_(char *, char *, char *, integer *, 
20             real *, integer *, real *, integer *), 
21             xerbla_(char *, integer *);
22     logical nounit;
23
24
25 /*  -- LAPACK routine (version 3.1) -- */
26 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
27 /*     November 2006 */
28
29 /*     .. Scalar Arguments .. */
30 /*     .. */
31 /*     .. Array Arguments .. */
32 /*     .. */
33
34 /*  Purpose */
35 /*  ======= */
36
37 /*  STRTI2 computes the inverse of a real upper or lower triangular */
38 /*  matrix. */
39
40 /*  This is the Level 2 BLAS version of the algorithm. */
41
42 /*  Arguments */
43 /*  ========= */
44
45 /*  UPLO    (input) CHARACTER*1 */
46 /*          Specifies whether the matrix A is upper or lower triangular. */
47 /*          = 'U':  Upper triangular */
48 /*          = 'L':  Lower triangular */
49
50 /*  DIAG    (input) CHARACTER*1 */
51 /*          Specifies whether or not the matrix A is unit triangular. */
52 /*          = 'N':  Non-unit triangular */
53 /*          = 'U':  Unit triangular */
54
55 /*  N       (input) INTEGER */
56 /*          The order of the matrix A.  N >= 0. */
57
58 /*  A       (input/output) REAL array, dimension (LDA,N) */
59 /*          On entry, the triangular matrix A.  If UPLO = 'U', the */
60 /*          leading n by n upper triangular part of the array A contains */
61 /*          the upper triangular matrix, and the strictly lower */
62 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
63 /*          leading n by n lower triangular part of the array A contains */
64 /*          the lower triangular matrix, and the strictly upper */
65 /*          triangular part of A is not referenced.  If DIAG = 'U', the */
66 /*          diagonal elements of A are also not referenced and are */
67 /*          assumed to be 1. */
68
69 /*          On exit, the (triangular) inverse of the original matrix, in */
70 /*          the same storage format. */
71
72 /*  LDA     (input) INTEGER */
73 /*          The leading dimension of the array A.  LDA >= max(1,N). */
74
75 /*  INFO    (output) INTEGER */
76 /*          = 0: successful exit */
77 /*          < 0: if INFO = -k, the k-th argument had an illegal value */
78
79 /*  ===================================================================== */
80
81 /*     .. Parameters .. */
82 /*     .. */
83 /*     .. Local Scalars .. */
84 /*     .. */
85 /*     .. External Functions .. */
86 /*     .. */
87 /*     .. External Subroutines .. */
88 /*     .. */
89 /*     .. Intrinsic Functions .. */
90 /*     .. */
91 /*     .. Executable Statements .. */
92
93 /*     Test the input parameters. */
94
95     /* Parameter adjustments */
96     a_dim1 = *lda;
97     a_offset = 1 + a_dim1;
98     a -= a_offset;
99
100     /* Function Body */
101     *info = 0;
102     upper = lsame_(uplo, "U");
103     nounit = lsame_(diag, "N");
104     if (! upper && ! lsame_(uplo, "L")) {
105         *info = -1;
106     } else if (! nounit && ! lsame_(diag, "U")) {
107         *info = -2;
108     } else if (*n < 0) {
109         *info = -3;
110     } else if (*lda < max(1,*n)) {
111         *info = -5;
112     }
113     if (*info != 0) {
114         i__1 = -(*info);
115         xerbla_("STRTI2", &i__1);
116         return 0;
117     }
118
119     if (upper) {
120
121 /*        Compute inverse of upper triangular matrix. */
122
123         i__1 = *n;
124         for (j = 1; j <= i__1; ++j) {
125             if (nounit) {
126                 a[j + j * a_dim1] = 1.f / a[j + j * a_dim1];
127                 ajj = -a[j + j * a_dim1];
128             } else {
129                 ajj = -1.f;
130             }
131
132 /*           Compute elements 1:j-1 of j-th column. */
133
134             i__2 = j - 1;
135             strmv_("Upper", "No transpose", diag, &i__2, &a[a_offset], lda, &
136                     a[j * a_dim1 + 1], &c__1);
137             i__2 = j - 1;
138             sscal_(&i__2, &ajj, &a[j * a_dim1 + 1], &c__1);
139 /* L10: */
140         }
141     } else {
142
143 /*        Compute inverse of lower triangular matrix. */
144
145         for (j = *n; j >= 1; --j) {
146             if (nounit) {
147                 a[j + j * a_dim1] = 1.f / a[j + j * a_dim1];
148                 ajj = -a[j + j * a_dim1];
149             } else {
150                 ajj = -1.f;
151             }
152             if (j < *n) {
153
154 /*              Compute elements j+1:n of j-th column. */
155
156                 i__1 = *n - j;
157                 strmv_("Lower", "No transpose", diag, &i__1, &a[j + 1 + (j + 
158                         1) * a_dim1], lda, &a[j + 1 + j * a_dim1], &c__1);
159                 i__1 = *n - j;
160                 sscal_(&i__1, &ajj, &a[j + 1 + j * a_dim1], &c__1);
161             }
162 /* L20: */
163         }
164     }
165
166     return 0;
167
168 /*     End of STRTI2 */
169
170 } /* strti2_ */