1 ;;; -*- Mode: lisp; Package: CL-USER -*-
5 ;; Raw interface to colnew where essentially all of the parameters for
6 ;; colnew are exposed. The f, df, g, dg, and init-guess parameters
8 (defun $colnew_expert
(ncomp m aleft aright zeta ipar ltol tol fixpnt ispace fspace
9 iflag f df g dg init-guess
)
10 (flet ((convert-to-array (mlist atype
)
11 ;; Convert the Maxima lists to arrays
12 (make-array (length (cdr mlist
)) :element-type atype
13 :initial-contents
(cdr mlist
)))
15 (list* '(mlist) (coerce v
'list
))))
16 (let ((a-m (convert-to-array m
'f2cl-lib
:integer4
))
17 (a-zeta (convert-to-array zeta
'double-float
))
18 (a-ipar (convert-to-array ipar
'f2cl-lib
:integer4
))
19 (a-ltol (convert-to-array ltol
'f2cl-lib
:integer4
))
20 (a-tol (convert-to-array tol
'double-float
))
21 (a-fixpnt (convert-to-array fixpnt
'double-float
))
22 (a-ispace (convert-to-array ispace
'f2cl-lib
:integer4
))
23 (a-fspace (convert-to-array fspace
'double-float
))
24 (f (coerce-float-fun f
))
25 (df (coerce-float-fun df
))
26 (g (coerce-float-fun g
))
27 (dg (coerce-float-fun dg
))
28 (nz (reduce #'+ (cdr m
))))
29 (flet ((fsub (x z f-array
)
30 (declare (type (cl:array double-float
(*)) z f-array
)
32 (let ((res (apply f x
(coerce (subseq z
0 nz
) 'list
))))
37 (setf (aref f-array k
) ($float ff
)))))
38 (values nil nil f-array
))
40 (declare (type (cl:array double-float
(*)) z df-array
)
42 (let ((res (apply df x
(coerce (subseq z
0 nz
) 'list
))))
43 ;; res is a Maxima matrix.
46 for row-list in
(cdr res
)
49 for element in
(cdr row-list
)
51 (setf (f2cl-lib::fref df-array
(row col
) ((1 ncomp
) (1 *))) ($float element
))))))
52 (values nil nil df-array
))
54 (declare (type (cl:array double-float
(*)) z
)
55 (type f2cl-lib
:integer4 i
))
56 (declare (ignore dummy
))
57 (let ((res (apply g i
(coerce (subseq z
0 nz
) 'list
))))
58 (values nil nil res
)))
60 (declare (type (cl:array double-float
(*)) z dg-array
)
61 (type f2cl-lib
:integer4 i
))
62 (let ((res (apply dg i
(coerce (subseq z
0 nz
) 'list
))))
66 (setf (aref dg-array k
) ($float ff
))))
67 (values nil nil dg-array
))
69 (declare (double-float x
)
70 (type (cl:array double-float
(*)) z dmval
))
71 (let* ((res ($float
(mcall init-guess x
)))
76 do
(setf (aref dmval k
) ($float ff
)))
79 do
(setf (aref z k
) ($float ff
))))
80 (values nil z dmval
)))
81 (multiple-value-bind (z-ncomp z-m z-aleft z-aright z-zeta z-ipar z-ltol z-tol
82 z-fixpnt z-ispace z-fspace o-iflag
)
100 (declare (ignore z-ncomp z-m z-aleft z-aright z-zeta z-ipar z-ltol z-tol
101 z-fixpnt z-ispace z-fspace
))
104 (convert-to-mlist a-fspace
)
105 (convert-to-mlist a-ispace
)))))))
107 ;; This is a slight extension of the actual APPSLN function. The X
108 ;; must be a list. The output is then a list of the z values for each
109 ;; x. The z values themselves are lists.
110 (defun $colnew_appsln
(x zlen fspace ispace
)
111 (flet ((convert-to-array (mlist atype
)
112 (make-array (length (cdr mlist
)) :element-type atype
113 :initial-contents
(cdr mlist
)))
114 (convert-to-mlist (v)
115 (list* '(mlist) (coerce v
'list
))))
116 (let ((a-fspace (convert-to-array fspace
'double-float
))
117 (a-ispace (convert-to-array ispace
'f2cl-lib
:integer4
))
118 (z (make-array zlen
:element-type
'double-float
))
120 (dolist (pnt (cdr x
))
121 (colnew:appsln
($float pnt
) z a-fspace a-ispace
)
122 (push (convert-to-mlist z
) result
))
123 (list* '(mlist) (nreverse result
)))))