In MARK+3 (src/db.lisp), quiet warning from SBCL about "Derived type conflicting...
[maxima.git] / share / minpack / lisp / lmdif1.lisp
blob4d2fdba9f34e639a236272a25baf87bc5f0d2f78
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)
11 ;;;
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))
17 (in-package :minpack)
20 (let ((factor 100.0) (zero 0.0))
21 (declare (type (double-float) factor zero))
22 (defun lmdif1 (fcn m n x fvec tol info iwa wa lwa)
23 (declare (type (array f2cl-lib:integer4 (*)) iwa)
24 (type (double-float) tol)
25 (type (array double-float (*)) wa fvec x)
26 (type (f2cl-lib:integer4) lwa info n m))
27 (f2cl-lib:with-multi-array-data
28 ((x double-float x-%data% x-%offset%)
29 (fvec double-float fvec-%data% fvec-%offset%)
30 (wa double-float wa-%data% wa-%offset%)
31 (iwa f2cl-lib:integer4 iwa-%data% iwa-%offset%))
32 (prog ((epsfcn 0.0) (ftol 0.0) (gtol 0.0) (xtol 0.0) (maxfev 0) (mode 0)
33 (mp5n 0) (nfev 0) (nprint 0))
34 (declare (type (f2cl-lib:integer4) nprint nfev mp5n mode maxfev)
35 (type (double-float) xtol gtol ftol epsfcn))
36 '" **********"
37 '""
38 '" subroutine lmdif1"
39 '""
40 '" the purpose of lmdif1 is to minimize the sum of the squares of"
41 '" m nonlinear functions in n variables by a modification of the"
42 '" levenberg-marquardt algorithm. this is done by using the more"
43 '" general least-squares solver lmdif. the user must provide a"
44 '" subroutine which calculates the functions. the jacobian is"
45 '" then calculated by a forward-difference approximation."
46 '""
47 '" the subroutine statement is"
48 '""
49 '" subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa)"
50 '""
51 '" where"
52 '""
53 '" fcn is the name of the user-supplied subroutine which"
54 '" calculates the functions. fcn must be declared"
55 '" in an external statement in the user calling"
56 '" program, and should be written as follows."
57 '""
58 '" subroutine fcn(m,n,x,fvec,iflag)"
59 '" integer m,n,iflag"
60 '" double precision x(n),fvec(m)"
61 '" ----------"
62 '" calculate the functions at x and"
63 '" return this vector in fvec."
64 '" ----------"
65 '" return"
66 '" end"
67 '""
68 '" the value of iflag should not be changed by fcn unless"
69 '" the user wants to terminate execution of lmdif1."
70 '" in this case set iflag to a negative integer."
71 '""
72 '" m is a positive integer input variable set to the number"
73 '" of functions."
74 '""
75 '" n is a positive integer input variable set to the number"
76 '" of variables. n must not exceed m."
77 '""
78 '" x is an array of length n. on input x must contain"
79 '" an initial estimate of the solution vector. on output x"
80 '" contains the final estimate of the solution vector."
81 '""
82 '" fvec is an output array of length m which contains"
83 '" the functions evaluated at the output x."
84 '""
85 '" tol is a nonnegative input variable. termination occurs"
86 '" when the algorithm estimates either that the relative"
87 '" error in the sum of squares is at most tol or that"
88 '" the relative error between x and the solution is at"
89 '" most tol."
90 '""
91 '" info is an integer output variable. if the user has"
92 '" terminated execution, info is set to the (negative)"
93 '" value of iflag. see description of fcn. otherwise,"
94 '" info is set as follows."
95 '""
96 '" info = 0 improper input parameters."
97 '""
98 '" info = 1 algorithm estimates that the relative error"
99 '" in the sum of squares is at most tol."
101 '" info = 2 algorithm estimates that the relative error"
102 '" between x and the solution is at most tol."
104 '" info = 3 conditions for info = 1 and info = 2 both hold."
106 '" info = 4 fvec is orthogonal to the columns of the"
107 '" jacobian to machine precision."
109 '" info = 5 number of calls to fcn has reached or"
110 '" exceeded 200*(n+1)."
112 '" info = 6 tol is too small. no further reduction in"
113 '" the sum of squares is possible."
115 '" info = 7 tol is too small. no further improvement in"
116 '" the approximate solution x is possible."
118 '" iwa is an integer work array of length n."
120 '" wa is a work array of length lwa."
122 '" lwa is a positive integer input variable not less than"
123 '" m*n+5*n+m."
125 '" subprograms called"
127 '" user-supplied ...... fcn"
129 '" minpack-supplied ... lmdif"
131 '" argonne national laboratory. minpack project. march 1980."
132 '" burton s. garbow, kenneth e. hillstrom, jorge j. more"
134 '" **********"
135 (setf info 0)
137 '" check the input parameters for errors."
140 (or (<= n 0)
141 (< m n)
142 (< tol zero)
143 (< lwa
144 (f2cl-lib:int-add (f2cl-lib:int-mul m n)
145 (f2cl-lib:int-mul 5 n)
146 m)))
147 (go label10))
149 '" call lmdif."
151 (setf maxfev (f2cl-lib:int-mul 200 (f2cl-lib:int-add n 1)))
152 (setf ftol tol)
153 (setf xtol tol)
154 (setf gtol zero)
155 (setf epsfcn zero)
156 (setf mode 1)
157 (setf nprint 0)
158 (setf mp5n (f2cl-lib:int-add m (f2cl-lib:int-mul 5 n)))
159 (multiple-value-bind
160 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
161 var-10 var-11 var-12 var-13 var-14 var-15 var-16 var-17 var-18
162 var-19 var-20 var-21 var-22 var-23)
163 (lmdif fcn m n x fvec ftol xtol gtol maxfev epsfcn
164 (f2cl-lib:array-slice wa double-float (1) ((1 lwa))) mode factor
165 nprint info nfev
166 (f2cl-lib:array-slice wa double-float ((+ mp5n 1)) ((1 lwa))) m
167 iwa (f2cl-lib:array-slice wa double-float ((+ n 1)) ((1 lwa)))
168 (f2cl-lib:array-slice wa
169 double-float
170 ((+ (f2cl-lib:int-mul 2 n) 1))
171 ((1 lwa)))
172 (f2cl-lib:array-slice wa
173 double-float
174 ((+ (f2cl-lib:int-mul 3 n) 1))
175 ((1 lwa)))
176 (f2cl-lib:array-slice wa
177 double-float
178 ((+ (f2cl-lib:int-mul 4 n) 1))
179 ((1 lwa)))
180 (f2cl-lib:array-slice wa
181 double-float
182 ((+ (f2cl-lib:int-mul 5 n) 1))
183 ((1 lwa))))
184 (declare (ignore var-0 var-3 var-4 var-5 var-6 var-7 var-8 var-9
185 var-10 var-11 var-12 var-13 var-16 var-17 var-18
186 var-19 var-20 var-21 var-22 var-23))
187 (setf m var-1)
188 (setf n var-2)
189 (setf info var-14)
190 (setf nfev var-15))
191 (if (= info 8) (setf info 4))
192 label10
193 (go end_label)
195 '" last card of subroutine lmdif1."
197 end_label
198 (return (values nil m n nil nil nil info nil nil nil))))))
200 (in-package #:cl-user)
201 #+#.(cl:if (cl:find-package '#:f2cl) '(and) '(or))
202 (eval-when (:load-toplevel :compile-toplevel :execute)
203 (setf (gethash 'fortran-to-lisp::lmdif1
204 fortran-to-lisp::*f2cl-function-info*)
205 (fortran-to-lisp::make-f2cl-finfo
206 :arg-types '(t (fortran-to-lisp::integer4)
207 (fortran-to-lisp::integer4) (array double-float (*))
208 (array double-float (*)) (double-float)
209 (fortran-to-lisp::integer4)
210 (array fortran-to-lisp::integer4 (*))
211 (array double-float (*)) (fortran-to-lisp::integer4))
212 :return-values '(nil fortran-to-lisp::m fortran-to-lisp::n nil nil
213 nil fortran-to-lisp::info nil nil nil)
214 :calls '(fortran-to-lisp::lmdif))))