1 ;;; Compiled by f2cl version:
2 ;;; ("f2cl1.l,v 1.215 2009/04/07 22:05:21 rtoy Exp $"
3 ;;; "f2cl2.l,v 1.37 2008/02/22 22:19:33 rtoy Exp $"
4 ;;; "f2cl3.l,v 1.6 2008/02/22 22:19:33 rtoy Exp $"
5 ;;; "f2cl4.l,v 1.7 2008/02/22 22:19:34 rtoy Exp $"
6 ;;; "f2cl5.l,v 1.200 2009/01/19 02:38:17 rtoy Exp $"
7 ;;; "f2cl6.l,v 1.48 2008/08/24 00:56:27 rtoy Exp $"
8 ;;; "macros.l,v 1.112 2009/01/08 12:57:19 rtoy Exp $")
10 ;;; Using Lisp CMU Common Lisp 19f (19F)
12 ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls nil)
13 ;;; (:coerce-assigns :as-needed) (:array-type ':array)
14 ;;; (:array-slicing t) (:declare-common nil)
15 ;;; (:float-format double-float))
20 (let ((one 1.0) (p05 0.05) (zero 0.0))
21 (declare (type (double-float) one p05 zero
))
22 (defun qrfac (m n a lda pivot ipvt lipvt rdiag acnorm wa
)
23 (declare (type (array f2cl-lib
:integer4
(*)) ipvt
)
24 (type f2cl-lib
:logical pivot
)
25 (type (array double-float
(*)) wa acnorm rdiag a
)
26 (type (f2cl-lib:integer4
) lipvt lda n m
))
27 (f2cl-lib:with-multi-array-data
28 ((a double-float a-%data% a-%offset%
)
29 (rdiag double-float rdiag-%data% rdiag-%offset%
)
30 (acnorm double-float acnorm-%data% acnorm-%offset%
)
31 (wa double-float wa-%data% wa-%offset%
)
32 (ipvt f2cl-lib
:integer4 ipvt-%data% ipvt-%offset%
))
33 (prog ((ajnorm 0.0) (epsmch 0.0) (sum 0.0) (temp 0.0) (i 0) (j 0) (jp1 0)
34 (k 0) (kmax 0) (minmn 0))
35 (declare (type (f2cl-lib:integer4
) minmn kmax k jp1 j i
)
36 (type (double-float) temp sum epsmch ajnorm
))
41 '" this subroutine uses householder transformations with column"
42 '" pivoting (optional) to compute a qr factorization of the"
43 '" m by n matrix a. that is, qrfac determines an orthogonal"
44 '" matrix q, a permutation matrix p, and an upper trapezoidal"
45 '" matrix r with diagonal elements of nonincreasing magnitude,"
46 '" such that a*p = q*r. the householder transformation for"
47 '" column k, k = 1,2,...,min(m,n), is of the form"
52 '" where u has zeros in the first k-1 positions. the form of"
53 '" this transformation and the method of pivoting first"
54 '" appeared in the corresponding linpack subroutine."
56 '" the subroutine statement is"
58 '" subroutine qrfac(m,n,a,lda,pivot,ipvt,lipvt,rdiag,acnorm,wa)"
62 '" m is a positive integer input variable set to the number"
65 '" n is a positive integer input variable set to the number"
68 '" a is an m by n array. on input a contains the matrix for"
69 '" which the qr factorization is to be computed. on output"
70 '" the strict upper trapezoidal part of a contains the strict"
71 '" upper trapezoidal part of r, and the lower trapezoidal"
72 '" part of a contains a factored form of q (the non-trivial"
73 '" elements of the u vectors described above)."
75 '" lda is a positive integer input variable not less than m"
76 '" which specifies the leading dimension of the array a."
78 '" pivot is a logical input variable. if pivot is set true,"
79 '" then column pivoting is enforced. if pivot is set false,"
80 '" then no column pivoting is done."
82 '" ipvt is an integer output array of length lipvt. ipvt"
83 '" defines the permutation matrix p such that a*p = q*r."
84 '" column j of p is column ipvt(j) of the identity matrix."
85 '" if pivot is false, ipvt is not referenced."
87 '" lipvt is a positive integer input variable. if pivot is false,"
88 '" then lipvt may be as small as 1. if pivot is true, then"
89 '" lipvt must be at least n."
91 '" rdiag is an output array of length n which contains the"
92 '" diagonal elements of r."
94 '" acnorm is an output array of length n which contains the"
95 '" norms of the corresponding columns of the input matrix a."
96 '" if this information is not needed, then acnorm can coincide"
99 '" wa is a work array of length n. if pivot is false, then wa"
100 '" can coincide with rdiag."
102 '" subprograms called"
104 '" minpack-supplied ... dpmpar,enorm"
106 '" fortran-supplied ... dmax1,dsqrt,min0"
108 '" argonne national laboratory. minpack project. march 1980."
109 '" burton s. garbow, kenneth e. hillstrom, jorge j. more"
113 '" epsmch is the machine precision."
115 (setf epsmch
(dpmpar 1))
117 '" compute the initial column norms and initialize several arrays."
119 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
122 (setf (f2cl-lib:fref acnorm-%data%
(j) ((1 n
)) acnorm-%offset%
)
124 (f2cl-lib:array-slice a
128 (setf (f2cl-lib:fref rdiag-%data%
(j) ((1 n
)) rdiag-%offset%
)
129 (f2cl-lib:fref acnorm-%data%
(j) ((1 n
)) acnorm-%offset%
))
130 (setf (f2cl-lib:fref wa-%data%
(j) ((1 n
)) wa-%offset%
)
131 (f2cl-lib:fref rdiag-%data%
(j) ((1 n
)) rdiag-%offset%
))
133 (setf (f2cl-lib:fref ipvt-%data%
(j) ((1 lipvt
)) ipvt-%offset%
)
137 '" reduce a to r with householder transformations."
139 (setf minmn
(f2cl-lib:min0 m n
))
140 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
143 (if (not pivot
) (go label40
))
145 '" bring the column of largest norm into the pivot position."
148 (f2cl-lib:fdo
(k j
(f2cl-lib:int-add k
1))
152 (> (f2cl-lib:fref rdiag-%data%
(k) ((1 n
)) rdiag-%offset%
)
153 (f2cl-lib:fref rdiag-%data%
(kmax) ((1 n
)) rdiag-%offset%
))
156 (if (= kmax j
) (go label40
))
157 (f2cl-lib:fdo
(i 1 (f2cl-lib:int-add i
1))
161 (f2cl-lib:fref a-%data%
165 (setf (f2cl-lib:fref a-%data%
(i j
) ((1 lda
) (1 n
)) a-%offset%
)
166 (f2cl-lib:fref a-%data%
170 (setf (f2cl-lib:fref a-%data%
176 (setf (f2cl-lib:fref rdiag-%data%
(kmax) ((1 n
)) rdiag-%offset%
)
177 (f2cl-lib:fref rdiag-%data%
(j) ((1 n
)) rdiag-%offset%
))
178 (setf (f2cl-lib:fref wa-%data%
(kmax) ((1 n
)) wa-%offset%
)
179 (f2cl-lib:fref wa-%data%
(j) ((1 n
)) wa-%offset%
))
180 (setf k
(f2cl-lib:fref ipvt-%data%
(j) ((1 lipvt
)) ipvt-%offset%
))
181 (setf (f2cl-lib:fref ipvt-%data%
(j) ((1 lipvt
)) ipvt-%offset%
)
182 (f2cl-lib:fref ipvt-%data%
186 (setf (f2cl-lib:fref ipvt-%data%
(kmax) ((1 lipvt
)) ipvt-%offset%
)
190 '" compute the householder transformation to reduce the"
191 '" j-th column of a to a multiple of the j-th unit vector."
194 (enorm (f2cl-lib:int-add
(f2cl-lib:int-sub m j
) 1)
195 (f2cl-lib:array-slice a
199 (if (= ajnorm zero
) (go label100
))
201 (< (f2cl-lib:fref a-%data%
(j j
) ((1 lda
) (1 n
)) a-%offset%
) zero
)
202 (setf ajnorm
(- ajnorm
)))
203 (f2cl-lib:fdo
(i j
(f2cl-lib:int-add i
1))
206 (setf (f2cl-lib:fref a-%data%
(i j
) ((1 lda
) (1 n
)) a-%offset%
)
208 (f2cl-lib:fref a-%data%
214 (setf (f2cl-lib:fref a-%data%
(j j
) ((1 lda
) (1 n
)) a-%offset%
)
216 (f2cl-lib:fref a-%data%
(j j
) ((1 lda
) (1 n
)) a-%offset%
)
219 '" apply the transformation to the remaining columns"
220 '" and update the norms."
222 (setf jp1
(f2cl-lib:int-add j
1))
223 (if (< n jp1
) (go label100
))
224 (f2cl-lib:fdo
(k jp1
(f2cl-lib:int-add k
1))
228 (f2cl-lib:fdo
(i j
(f2cl-lib:int-add i
1))
234 (f2cl-lib:fref a-%data%
238 (f2cl-lib:fref a-%data%
245 (f2cl-lib:fref a-%data%
249 (f2cl-lib:fdo
(i j
(f2cl-lib:int-add i
1))
252 (setf (f2cl-lib:fref a-%data%
257 (f2cl-lib:fref a-%data%
262 (f2cl-lib:fref a-%data%
269 (= (f2cl-lib:fref rdiag-%data%
(k) ((1 n
)) rdiag-%offset%
)
274 (f2cl-lib:fref a-%data%
278 (f2cl-lib:fref rdiag-%data%
282 (setf (f2cl-lib:fref rdiag-%data%
(k) ((1 n
)) rdiag-%offset%
)
284 (f2cl-lib:fref rdiag-%data%
289 (f2cl-lib:dmax1 zero
(- one
(expt temp
2))))))
295 (f2cl-lib:fref rdiag-%data%
(k) ((1 n
)) rdiag-%offset%
)
296 (f2cl-lib:fref wa-%data%
(k) ((1 n
)) wa-%offset%
))
300 (setf (f2cl-lib:fref rdiag-%data%
(k) ((1 n
)) rdiag-%offset%
)
301 (enorm (f2cl-lib:int-sub m j
)
302 (f2cl-lib:array-slice a
306 (setf (f2cl-lib:fref wa-%data%
(k) ((1 n
)) wa-%offset%
)
307 (f2cl-lib:fref rdiag-%data%
314 (setf (f2cl-lib:fref rdiag-%data%
(j) ((1 n
)) rdiag-%offset%
)
319 '" last card of subroutine qrfac."
322 (return (values nil nil nil nil nil nil nil nil nil nil
))))))
324 (in-package #:cl-user
)
325 #+#.
(cl:if
(cl:find-package
'#:f2cl
) '(and) '(or))
326 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
327 (setf (gethash 'fortran-to-lisp
::qrfac fortran-to-lisp
::*f2cl-function-info
*)
328 (fortran-to-lisp::make-f2cl-finfo
329 :arg-types
'((fortran-to-lisp::integer4
) (fortran-to-lisp::integer4
)
330 (array double-float
(*)) (fortran-to-lisp::integer4
)
331 fortran-to-lisp
::logical
332 (array fortran-to-lisp
::integer4
(*))
333 (fortran-to-lisp::integer4
) (array double-float
(*))
334 (array double-float
(*)) (array double-float
(*)))
335 :return-values
'(nil nil nil nil nil nil nil nil nil nil
)
336 :calls
'(fortran-to-lisp::enorm fortran-to-lisp
::dpmpar
))))