1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 ;;; (c) Copyright 1981 Massachusetts Institute of Technology ;;;
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 (macsyma-module array
)
16 ;;; Macsyma User array utilities originally due to CFFK.
18 ;;; Note that on the lisp level we regard as an array either
19 ;;; (1) a symbol whose ARRAY property is a common lisp array
20 ;;; [i.e., (symbol-array 'symbol)
21 ;;; == (get 'symbol 'array) => some array] or
22 ;;; (2) a common lisp array.
23 ;;; On the maxima level a declared array not of type HASH or FUNCTIONAL
25 ;;; (1m) a symbol whose ARRAY mproperty is of type (1)
26 ;;; [i.e., (symbol-array (mget 'symbol 'array)) => some array] or
27 ;;; (2m) it is of type (2) (and then called a `fast' array).
28 ;;; Such an array is of type (1m) iff it was created with ARRAY
29 ;;; with USE_FAST_ARRAYS being set to FALSE.
31 ;;; Curiously enough, ARRAY(...,TYPE,...) (which currently can only be
32 ;;; used for USE_FAST_ARRAYS:FALSE) results in an array which is
33 ;;; simultaneously of type (1) and (1m).
35 (defmfun $listarray
(ary)
37 (cond ((mget ary
'hashar
)
38 (mapcar #'(lambda (subs) ($arrayapply ary subs
))
39 (cdddr (meval (list '($arrayinfo
) ary
)))))
40 ((mget ary
'array
) (listarray (mget ary
'array
)))
42 (if (eql (array-rank ary
) 1)
44 (coerce (make-array (apply '* (array-dimensions ary
))
46 :element-type
(array-element-type ary
))
50 (maphash #'(lambda (x &rest l
) l
51 (unless (eq x
'dim1
) (push (gethash x tab
) vals
)))
54 ((eq (marray-type ary
) '$functional
)
55 (cdr ($listarray
(mgenarray-content ary
))))
57 (merror (intl:gettext
"listarray: argument must be an array; found: ~M")
60 (defmfun $fillarray
(ary1 ary2
)
62 (or (mget ary1
'array
)
63 (and (arrayp ary1
) ary1
)
64 (merror (intl:gettext
"fillarray: first argument must be a declared array; found: ~M") ary1
))))
66 (cond (($listp ary2
) (cdr ary2
))
67 ((get (mget ary2
'array
) 'array
))
70 (merror (intl:gettext
"fillarray: second argument must be an array or list; found: ~M") ary2
))))
74 (and (symbolp sym
) (boundp sym
) (symbol-value sym
)))
76 (defmspec $rearray
(l)
79 (dims (mapcar #'meval
(cdr l
))))
80 (cond ($use_fast_arrays
81 (setf (symbol-value ar
) (rearray-aux ar
(getvalue ar
) dims
)))
83 (rearray-aux ar
(getvalue ar
) dims
)))))
85 (defun rearray-aux (ar val dims
&aux marray-sym
)
87 (apply 'lispm-rearray val dims
))
88 ((arrayp (get ar
'array
))
89 (setf (get ar
'array
) (apply 'lispm-rearray
(get ar
'array
) dims
)))
90 ((setq marray-sym
(mget ar
'array
))
91 (rearray-aux marray-sym nil dims
)
93 (t (merror (intl:gettext
"rearray: argument is not an array: ~A") ar
))))
95 (defun lispm-rearray (ar &rest dims
)
96 (cond ((eql (array-rank ar
) (length dims
))
97 (adjust-array ar
(mapcar #'1+ (copy-list dims
)) :element-type
(array-element-type ar
) ))
98 (t (merror (intl:gettext
"rearray: arrays must have the same number of subscripts.")))))