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 t)
13 ;;; (:coerce-assigns :as-needed) (:array-type ':array)
14 ;;; (:array-slicing t) (:declare-common nil)
15 ;;; (:float-format double-float))
17 (in-package :common-lisp-user
)
49 (declare (type (double-float) dg dgm dginit dgtest dgx dgxm dgy dgym finit
50 ftest1 fm fx fxm fy fym p5 p66 stx sty stmin
51 stmax width width1 xtrapf zero
)
52 (type f2cl-lib
:logical brackt stage1
)
53 (type (f2cl-lib:integer4
) infoc j
))
54 (defun mcsrch (n x f g s stp ftol xtol maxfev info nfev wa
)
55 (declare (type (double-float) xtol ftol stp f
)
56 (type (array double-float
(*)) wa s g x
)
57 (type (f2cl-lib:integer4
) nfev info maxfev n
))
59 (symbol-macrolet ((stpmax (lb3-stpmax *lb3-common-block
*))
60 (stpmin (lb3-stpmin *lb3-common-block
*))
61 (gtol (lb3-gtol *lb3-common-block
*))
62 (lp (lb3-lp *lb3-common-block
*)))
63 (f2cl-lib:with-multi-array-data
64 ((x double-float x-%data% x-%offset%
)
65 (g double-float g-%data% g-%offset%
)
66 (s double-float s-%data% s-%offset%
)
67 (wa double-float wa-%data% wa-%offset%
))
70 (if (= info -
1) (go label45
))
83 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
88 (* (f2cl-lib:fref g-%data%
(j) ((1 n
)) g-%offset%
)
89 (f2cl-lib:fref s-%data%
98 " THE SEARCH DIRECTION IS NOT A DESCENT DIRECTION"
101 (setf brackt f2cl-lib
:%false%
)
102 (setf stage1 f2cl-lib
:%true%
)
105 (setf dgtest
(* ftol dginit
))
106 (setf width
(- stpmax stpmin
))
107 (setf width1
(/ width p5
))
108 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
111 (setf (f2cl-lib:fref wa-%data%
(j) ((1 n
)) wa-%offset%
)
112 (f2cl-lib:fref x-%data%
(j) ((1 n
)) x-%offset%
))
123 (setf stmin
(min stx sty
))
124 (setf stmax
(max stx sty
)))
127 (setf stmax
(+ stp
(* xtrapf
(- stp stx
))))))
128 (setf stp
(max stp stpmin
))
129 (setf stp
(min stp stpmax
))
131 (or (and brackt
(or (<= stp stmin
) (>= stp stmax
)))
132 (>= nfev
(f2cl-lib:int-sub maxfev
1))
134 (and brackt
(<= (- stmax stmin
) (* xtol stmax
))))
136 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
139 (setf (f2cl-lib:fref x-%data%
(j) ((1 n
)) x-%offset%
)
140 (+ (f2cl-lib:fref wa-%data%
(j) ((1 n
)) wa-%offset%
)
142 (f2cl-lib:fref s-%data%
151 (setf nfev
(f2cl-lib:int-add nfev
1))
153 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
158 (* (f2cl-lib:fref g-%data%
(j) ((1 n
)) g-%offset%
)
159 (f2cl-lib:fref s-%data%
164 (setf ftest1
(+ finit
(* stp dgtest
)))
166 (or (and brackt
(or (<= stp stmin
) (>= stp stmax
))) (= infoc
0))
168 (if (and (= stp stpmax
) (<= f ftest1
) (<= dg dgtest
))
170 (if (and (= stp stpmin
) (or (> f ftest1
) (>= dg dgtest
)))
172 (if (>= nfev maxfev
) (setf info
3))
173 (if (and brackt
(<= (- stmax stmin
) (* xtol stmax
))) (setf info
2))
174 (if (and (<= f ftest1
) (<= (f2cl-lib:dabs dg
) (* gtol
(- dginit
))))
176 (if (/= info
0) (go end_label
))
177 (if (and stage1
(<= f ftest1
) (>= dg
(* (min ftol gtol
) dginit
)))
178 (setf stage1 f2cl-lib
:%false%
))
180 ((and stage1
(<= f fx
) (> f ftest1
))
181 (setf fm
(- f
(* stp dgtest
)))
182 (setf fxm
(- fx
(* stx dgtest
)))
183 (setf fym
(- fy
(* sty dgtest
)))
184 (setf dgm
(- dg dgtest
))
185 (setf dgxm
(- dgx dgtest
))
186 (setf dgym
(- dgy dgtest
))
188 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8
189 var-9 var-10 var-11 var-12
)
190 (mcstep stx fxm dgxm sty fym dgym stp fm dgm brackt stmin
192 (declare (ignore var-7 var-8 var-10 var-11
))
202 (setf fx
(+ fxm
(* stx dgtest
)))
203 (setf fy
(+ fym
(* sty dgtest
)))
204 (setf dgx
(+ dgxm dgtest
))
205 (setf dgy
(+ dgym dgtest
)))
208 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8
209 var-9 var-10 var-11 var-12
)
210 (mcstep stx fx dgx sty fy dgy stp f dg brackt stmin stmax
212 (declare (ignore var-7 var-8 var-10 var-11
))
221 (setf infoc var-12
))))
224 (if (>= (f2cl-lib:dabs
(- sty stx
)) (* p66 width1
))
225 (setf stp
(+ stx
(* p5
(- sty stx
)))))
227 (setf width
(f2cl-lib:dabs
(- sty stx
)))))
231 (values nil nil nil nil nil stp nil nil nil info nfev nil
))))))))
233 (in-package #:cl-user
)
234 #+#.
(cl:if
(cl:find-package
'#:f2cl
) '(and) '(or))
235 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
236 (setf (gethash 'fortran-to-lisp
::mcsrch
237 fortran-to-lisp
::*f2cl-function-info
*)
238 (fortran-to-lisp::make-f2cl-finfo
239 :arg-types
'((fortran-to-lisp::integer4
) (array double-float
(*))
240 (double-float) (array double-float
(*))
241 (array double-float
(*)) (double-float) (double-float)
242 (double-float) (fortran-to-lisp::integer4
)
243 (fortran-to-lisp::integer4
) (fortran-to-lisp::integer4
)
244 (array double-float
(*)))
245 :return-values
'(nil nil nil nil nil fortran-to-lisp
::stp nil nil
246 nil fortran-to-lisp
::info fortran-to-lisp
::nfev
248 :calls
'(fortran-to-lisp::mcstep
))))