fft usage?



Raymond Toy <toy@rtp.ericsson.se> writes:

> I've been unable to create
> an array that is acceptable to the fft routines.  I tried
> array(ar,4), arraymake(ar,[4]), and make_array.  The resulting arrays
> are rejected by fft.

Apparently, different people at different times had different ideas
of what a macsyma array should look like.  I think this is the present
situation (I wrote this up for another patch I haven't sent yet, sorry
for the formal tone of it): 

;;; Note that on the lisp level we regard as an array either
;;;   (1) a symbol whose ARRAY property is a common lisp array
;;;       [i.e., (symbol-array 'symbol)
;;;               == (get 'symbol 'array) == some array] or
;;;   (2) a common lisp array
;;; and (1) takes precedence over (2).
;;; On the maxima level a declared array not of type HASH or FUNCTIONAL 
;;; is either
;;;   (1m) a symbol whose ARRAY mproperty is of type (1)
;;;        [i.e., (symbol-array (mget 'symbol 'array)) == some array] or
;;;   (2m) it is of type (2)  
;;; and (1m) takes precedence over (2m).
;;; Such an array is of type (1m) iff it was created with ARRAY 
;;; with USE_FAST_ARRAYS being set to FALSE.

Now, $fft expects arguments in the form (1) whereas they come in the
form (1m) or (2m).

Here is a rough outline of a possible solution:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(in-package "MAXIMA")

(defun mgetarray (marg) 
"Return the lisp array which is somehow attached to MARG."
  (or (and (symbolp marg) (symbol-array (mget marg 'array)))
      (and (arrayp marg) marg)))

(defun fft-arg-check (ary)
  ;; I don't check here if this is really a floating point array.  For maxima
  ;; arrays which are symbols this would be no problem since the type is on
  ;; the property list.  On the other hand, for "fast" arrays (i.e. lisp
  ;; arrays), using ARRAY-ELEMENT-TYPE might not be too useful.
  (or (mgetarray ary)
      (merror
       "arg ~M to fft//ift//recttopolar//polartorect must be floating point array" ary)))

;; I assume that the aguments of $fft are maxima arrays to be modified,
;; whereas the arguments of fft are lisp arrays to be modified.
(defun $fft (rary iary)
  (let ((fast_rary (fft-arg-check rary))
	(fast_iary (fft-arg-check iary)))
    ;; fast_rary and fast_iary are lisp arrays (which is the same thing
    ;; as "fast" maxima arrays) and fft is supposed to modify them.
    (fft fast_rary fast_iary)
    ;; return the modified arrays in their original form (i.e. either "fast"
    ;; or not, depending) 
    (list '(mlist) rary iary)))

;; Just a dummy definition for testing.
(defun fft (x y)
  (setf (aref x 0) (aref y 0))
  (format t "~a~%~a" x y))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that different types of arrays can be mixed, like:

(C1) array(xxx,7);
(D1) 				      xxx
(C2) yyy:make_array('any,5);
(D2) 		       {Array:  #(NIL NIL NIL NIL NIL)}
(C3) xxx[0]:0;
(D3) 				       0
(C4) yyy[0]:1;
(D4) 				       1
(C5) fft(xxx,yyy);
#(1 ##### ##### ##### ##### ##### ##### #####)
#(1 NIL NIL NIL NIL)
(D5) 		     [xxx, {Array:  #(1 NIL NIL NIL NIL)}]
(C6) xxx[0];
(D6) 				       1
(C7) 

Wolfgang

-- 
wjenkner@inode.at