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) (p5 0.5) (p25 0.25) (zero 0.0))
21 (declare (type (double-float) one p5 p25 zero
))
22 (defun r1updt (m n s ls u v w sing
)
23 (declare (type f2cl-lib
:logical sing
)
24 (type (array double-float
(*)) w v u s
)
25 (type (f2cl-lib:integer4
) ls n m
))
26 (f2cl-lib:with-multi-array-data
27 ((s double-float s-%data% s-%offset%
)
28 (u double-float u-%data% u-%offset%
)
29 (v double-float v-%data% v-%offset%
)
30 (w double-float w-%data% w-%offset%
))
31 (prog ((cos 0.0) (cotan 0.0) (giant 0.0) (sin 0.0) (tan 0.0) (tau 0.0)
32 (temp 0.0) (i 0) (j 0) (jj 0) (l 0) (nmj 0) (nm1 0))
33 (declare (type (f2cl-lib:integer4
) nm1 nmj l jj j i
)
34 (type (double-float) temp tau tan sin giant cotan cos
))
39 '" given an m by n lower trapezoidal matrix s, an m-vector u,"
40 '" and an n-vector v, the problem is to determine an"
41 '" orthogonal matrix q such that"
46 '" is again lower trapezoidal."
48 '" this subroutine determines q as the product of 2*(n - 1)"
51 '" gv(n-1)*...*gv(1)*gw(1)*...*gw(n-1)"
53 '" where gv(i), gw(i) are givens rotations in the (i,n) plane"
54 '" which eliminate elements in the i-th and n-th planes,"
55 '" respectively. q itself is not accumulated, rather the"
56 '" information to recover the gv, gw rotations is returned."
58 '" the subroutine statement is"
60 '" subroutine r1updt(m,n,s,ls,u,v,w,sing)"
64 '" m is a positive integer input variable set to the number"
67 '" n is a positive integer input variable set to the number"
68 '" of columns of s. n must not exceed m."
70 '" s is an array of length ls. on input s must contain the lower"
71 '" trapezoidal matrix s stored by columns. on output s contains"
72 '" the lower trapezoidal matrix produced as described above."
74 '" ls is a positive integer input variable not less than"
77 '" u is an input array of length m which must contain the"
80 '" v is an array of length n. on input v must contain the vector"
81 '" v. on output v(i) contains the information necessary to"
82 '" recover the givens rotation gv(i) described above."
84 '" w is an output array of length m. w(i) contains information"
85 '" necessary to recover the givens rotation gw(i) described"
88 '" sing is a logical output variable. sing is set true if any"
89 '" of the diagonal elements of the output s are zero. otherwise"
90 '" sing is set false."
92 '" subprograms called"
94 '" minpack-supplied ... dpmpar"
96 '" fortran-supplied ... dabs,dsqrt"
98 '" argonne national laboratory. minpack project. march 1980."
99 '" burton s. garbow, kenneth e. hillstrom, jorge j. more,"
104 '" giant is the largest magnitude."
106 (setf giant
(dpmpar 3))
108 '" initialize the diagonal element pointer."
112 (the f2cl-lib
:integer4
(truncate (* n
(+ (- (* 2 m
) n
) 1)) 2))
113 (f2cl-lib:int-sub m n
)))
115 '" move the nontrivial part of the last column of s into w."
118 (f2cl-lib:fdo
(i n
(f2cl-lib:int-add i
1))
121 (setf (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
)
122 (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
))
123 (setf l
(f2cl-lib:int-add l
1))
126 '" rotate the vector v into a multiple of the n-th unit vector"
127 '" in such a way that a spike is introduced into w."
129 (setf nm1
(f2cl-lib:int-sub n
1))
130 (if (< nm1
1) (go label70
))
131 (f2cl-lib:fdo
(nmj 1 (f2cl-lib:int-add nmj
1))
134 (setf j
(f2cl-lib:int-sub n nmj
))
137 (f2cl-lib:int-add
(f2cl-lib:int-sub m j
)
139 (setf (f2cl-lib:fref w-%data%
(j) ((1 m
)) w-%offset%
) zero
)
140 (if (= (f2cl-lib:fref v-%data%
(j) ((1 n
)) v-%offset%
) zero
)
143 '" determine a givens rotation which eliminates the"
144 '" j-th element of v."
148 (f2cl-lib:dabs
(f2cl-lib:fref v-%data%
(n) ((1 n
)) v-%offset%
))
149 (f2cl-lib:dabs
(f2cl-lib:fref v-%data%
(j) ((1 n
)) v-%offset%
)))
152 (/ (f2cl-lib:fref v-%data%
(n) ((1 n
)) v-%offset%
)
153 (f2cl-lib:fref v-%data%
(j) ((1 n
)) v-%offset%
)))
154 (setf sin
(/ p5
(f2cl-lib:dsqrt
(+ p25
(* p25
(expt cotan
2))))))
155 (setf cos
(* sin cotan
))
157 (if (> (* (f2cl-lib:dabs cos
) giant
) one
) (setf tau
(/ one cos
)))
161 (/ (f2cl-lib:fref v-%data%
(j) ((1 n
)) v-%offset%
)
162 (f2cl-lib:fref v-%data%
(n) ((1 n
)) v-%offset%
)))
163 (setf cos
(/ p5
(f2cl-lib:dsqrt
(+ p25
(* p25
(expt tan
2))))))
164 (setf sin
(* cos tan
))
168 '" apply the transformation to v and store the information"
169 '" necessary to recover the givens rotation."
171 (setf (f2cl-lib:fref v-%data%
(n) ((1 n
)) v-%offset%
)
172 (+ (* sin
(f2cl-lib:fref v-%data%
(j) ((1 n
)) v-%offset%
))
174 (f2cl-lib:fref v-%data%
(n) ((1 n
)) v-%offset%
))))
175 (setf (f2cl-lib:fref v-%data%
(j) ((1 n
)) v-%offset%
) tau
)
177 '" apply the transformation to s and extend the spike in w."
180 (f2cl-lib:fdo
(i j
(f2cl-lib:int-add i
1))
186 (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
))
188 (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
))))
189 (setf (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
)
192 (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
))
194 (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
))))
195 (setf (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
) temp
)
196 (setf l
(f2cl-lib:int-add l
1))
202 '" add the spike from the rank 1 update to w."
204 (f2cl-lib:fdo
(i 1 (f2cl-lib:int-add i
1))
207 (setf (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
)
208 (+ (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
)
209 (* (f2cl-lib:fref v-%data%
(n) ((1 n
)) v-%offset%
)
210 (f2cl-lib:fref u-%data%
(i) ((1 m
)) u-%offset%
))))
213 '" eliminate the spike."
215 (setf sing f2cl-lib
:%false%
)
216 (if (< nm1
1) (go label140
))
217 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
220 (if (= (f2cl-lib:fref w-%data%
(j) ((1 m
)) w-%offset%
) zero
)
223 '" determine a givens rotation which eliminates the"
224 '" j-th element of the spike."
228 (f2cl-lib:dabs
(f2cl-lib:fref s-%data%
(jj) ((1 ls
)) s-%offset%
))
229 (f2cl-lib:dabs
(f2cl-lib:fref w-%data%
(j) ((1 m
)) w-%offset%
)))
232 (/ (f2cl-lib:fref s-%data%
(jj) ((1 ls
)) s-%offset%
)
233 (f2cl-lib:fref w-%data%
(j) ((1 m
)) w-%offset%
)))
234 (setf sin
(/ p5
(f2cl-lib:dsqrt
(+ p25
(* p25
(expt cotan
2))))))
235 (setf cos
(* sin cotan
))
237 (if (> (* (f2cl-lib:dabs cos
) giant
) one
) (setf tau
(/ one cos
)))
241 (/ (f2cl-lib:fref w-%data%
(j) ((1 m
)) w-%offset%
)
242 (f2cl-lib:fref s-%data%
(jj) ((1 ls
)) s-%offset%
)))
243 (setf cos
(/ p5
(f2cl-lib:dsqrt
(+ p25
(* p25
(expt tan
2))))))
244 (setf sin
(* cos tan
))
248 '" apply the transformation to s and reduce the spike in w."
251 (f2cl-lib:fdo
(i j
(f2cl-lib:int-add i
1))
257 (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
))
259 (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
))))
260 (setf (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
)
263 (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
))
265 (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
))))
266 (setf (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
) temp
)
267 (setf l
(f2cl-lib:int-add l
1))
270 '" store the information necessary to recover the"
273 (setf (f2cl-lib:fref w-%data%
(j) ((1 m
)) w-%offset%
) tau
)
276 '" test for zero diagonal elements in the output s."
278 (if (= (f2cl-lib:fref s-%data%
(jj) ((1 ls
)) s-%offset%
) zero
)
279 (setf sing f2cl-lib
:%true%
))
282 (f2cl-lib:int-add
(f2cl-lib:int-sub m j
)
287 '" move w back into the last column of the output s."
290 (f2cl-lib:fdo
(i n
(f2cl-lib:int-add i
1))
293 (setf (f2cl-lib:fref s-%data%
(l) ((1 ls
)) s-%offset%
)
294 (f2cl-lib:fref w-%data%
(i) ((1 m
)) w-%offset%
))
295 (setf l
(f2cl-lib:int-add l
1))
297 (if (= (f2cl-lib:fref s-%data%
(jj) ((1 ls
)) s-%offset%
) zero
)
298 (setf sing f2cl-lib
:%true%
))
301 '" last card of subroutine r1updt."
304 (return (values nil nil nil nil nil nil nil sing
))))))
306 (in-package #:cl-user
)
307 #+#.
(cl:if
(cl:find-package
'#:f2cl
) '(and) '(or))
308 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
309 (setf (gethash 'fortran-to-lisp
::r1updt
310 fortran-to-lisp
::*f2cl-function-info
*)
311 (fortran-to-lisp::make-f2cl-finfo
312 :arg-types
'((fortran-to-lisp::integer4
) (fortran-to-lisp::integer4
)
313 (array double-float
(*)) (fortran-to-lisp::integer4
)
314 (array double-float
(*)) (array double-float
(*))
315 (array double-float
(*)) fortran-to-lisp
::logical
)
316 :return-values
'(nil nil nil nil nil nil nil fortran-to-lisp
::sing
)
317 :calls
'(fortran-to-lisp::dpmpar
))))