id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
33,016
iter-general.lsp
rwoldford_Quail/examples/arrays/iter-general.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Iteration Introduction ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Iteration can be done in many different ways in Common Lisp. ;;; ;;; There are a variety of iteration special forms and macros ;;; in common lisp. ;;; These can be very roughly grouped into ;;; ;;; General iteration macros like loop, do, do* ;;; Simple iteration macros like dolist, and dotimes ;;; Mapping functions like map, mapcar, reduce, ... ;;; specialized for ``mapping over'' sequences or more often just lists ;;; ;;; And finally, some program ``features'' like go and tagbody that while ;;; they allow you a great deal of freedom are really too fortranesque ;;; to be recommended for the general user. ;;; ;;; In Quail, we have introduced some functions that allow one to use ;;; ;;; General iteration macros with arrays ;;; ... column-major-eref ;;; column-major-list-elements ;;; column-major-set-elements ;;; column-major-ref-slice ;;; row-major-eref ;;; row-major-list-elements ;;; row-major-set-elements ;;; row-major-ref-slice ;;; ;;; Simple iteration macros ;;; ... doslices ;;; collect-slices ;;; ;;; Mapping functions: ;;; ... map-element ;;; map-slices ;;; reduce-slices ;;; collapse ;;; sweep ;;; ;;; Searching functions: ;;; ... find-slices, find-slices-if ;;; count-slices, count-slices-if ;;; slice-positions, slice-positions-if ;;; ;;; Modification functions: ;;; ... remove-slices, remove-slices-if ;;; substitute-slices, substitute-slices-if ;;; replace-slices ;;; ;;; ;;; ;;; We will give examples of the uses of these functions over the next few files. ;;; In this file, we will just illustrate some of the Common Lisp iteration ;;; constructs with Quail arrays. ;;; ;;; If your application program involves arrays of only fixed dimension, ;;; say 2 (i.e. matrices) the code will often be more efficient (at less ;;; general) by sticking to the iteration control described in this file. (in-package :quail-user) (setf a (array '((1.2 3 4.5) (6.7 8.9 0.1)) :dimensions '(2 3))) (setf b (seq 10 -10 -1)) (setf small-b (ref b '(:c 0 1 2))) ;; all but the first three elements of b (setf c (array (random-uniform :n 4) :dimensions '(2 2))) (setf d (sel a)) ;; a copy of a (setf e (array (seq 1 24) :dimensions '(2 3 4))) ;; 2 rows, 3 cols, 4 faces ;------------------------------------------------------------------------------ ;;; ;;; Here's a function that will print the (i,j)'th element of matrix ;;; ;;; (defun print-elt (matrix i j) "Prints element i j of matrix." (format *quail-terminal-io* "~&Element (~s,~s) = ~s" i j (eref matrix i j))) ;;; ;;; The most natural looping construct is the loop macro. ;;; It has lots of nice keywords like: for from to by do collect sum .... ;;; that make it relatively natural to write and easy to read. ;;; ;;; Here's a function that prints out all elements of a matrix (defun print-matrix (a) "Print the contents of the matrix a in row-major-order" (let ((m (first (dimensions-of a))) (n (second (dimensions-of a)))) (loop for i from 0 to (- m 1) do (loop for j from 0 to (- n 1) do (print-elt a i j)) ) ) ) (print-matrix a) ;;; Note that it will not work for b as b has no second dimension ;;; ;; (print-matrix b) ;; error ;;; Nor will it work for e ; too many dimensions ;;; ;; (print-matrix e) ;; error ;;; ;;; Writing functions for arrays of arbitrary dimensions can be a pain. ;;; That's why we have included several functions in Quail that allow ;;; one to access elements of an array of any shape or size. (defun print-elements (a) "This prints out all the elements of the array a in row major order" (let ((n (number-of-elements a))) (format *quail-terminal-io* "~&In row-major order,") (loop for i from 0 to (- n 1) do (format *quail-terminal-io* "~&Element ~s = ~s" i (row-major-eref a i))))) ;;; ;;; All of the following will work ;;; (print-elements a) (print-elements b) (print-elements e) ;;; ;;; But more on that later (in files after this one). ;;; First we illustrate a few more common lisp iteration constructs. ;;; ;;; Here's an example of do (do ((i 0 (+ i 1))) ((= i (first (dimensions-of b))) (list i)) (format *quail-terminal-io* "~&------") (print (eref b i))) ;;; ;;; Not quite as obvious what's going on is it? ;;; Still, the control structure is straightforward and general ;;; do is often preferred for this reason. Here it is dissected. (do ( ;(do ( (i 0 (+ i 1)) ; (iteration-var initial-value step-form) ; .... as many as you want ) ; ) ( ; ( (= i (first (dimensions-of b))) ; end-test-form ... loop ends when this ; evaluates to non-NIL (list i) ; result-form ) ; ) (format *quail-terminal-io* "~&------") ; form1 (print (eref b i)) ; form2 ; ... as many as you want ) ; ) and the loop ends returning ; the value of result-form ;;; ;;; The do* macro is exactly the same except that the binding of the iteration ;;; variables occurs in parallel with do and in top-down sequence with do* ;;; Same as the distinction between let and let* ;;; ;;; ;;; dolist is pretty straightforward ;;; (<- bdbd (dolist (i (list "How" "now" "brown" "cow") "That's all folks!") (print i) (print "?"))) bdbd ;;; ;;; as is dotimes ;;; (<- fu (dotimes (i 5 'bar) (print i) (print (- i)))) FU ;;; ;;; Then there is mapping. ;;; Lots of mapping functions for lists, some for more general things ;;; called sequences (including lists and strings) ;;; We'll only illustrate a few here. ;;; ;;; ;;; For, a list there is the age-old mapcar ;;; which maps a specified function over the elements ;;; of a list and returns a list of those values ;;; (mapcar (function abs) '(-3 -2 -1 0 1 2 3)) ;;; ;;; or in the preferred short hand for functions ;;; (mapcar #'abs '(-3 -2 -1 0 1 2 3)) (mapcar #'+ '(-3 -2 -1 0 1 2 3) '(3 3 3 3 3 3 3)) ;;; ;;; the function being mapped over the elements of the list must ;;; be able to handle as many arguments are there are lists. ;;; ;;; ;;; The general sequence version of this is map. ;;; Because there are so many different types of sequence, ;;; You need to specify the type of the return sequence ;;; when you call map ;;; (map 'list #'abs '(-3 -2 -1 0 1 2 3)) (map 'list #'+ '(-3 -2 -1 0 1 2 3) '(3 3 3 3 3 3 3)) (map 'string #'(lambda (x y) (if (char= x y) x (eref "-" 0))) ; An anonymous function "Now is the time for all good women to aid!" "Never have so few sacrificed so little !") ;;; ;;; And also for sequences ;;; (reduce #'+ '(1 2 3 4)) (reduce #'* '(1 2 3 4)) (reduce #'+ '(1 2 3 4) :initial-value 100) ;;; ;;; And many others! ;;; Including subseq copy-seq elt concatenate position position-if ;;; find find-if sort remove remove-if ;;; substitute substitute-if count count-if delete .... ;;; ;;; ;;; Unfortunately none of these work on arrays with the Quail exception of ;;; sort. ;;; ;;; Hence the functions in the remaining iteration files.
8,577
Common Lisp
.l
233
31.995708
89
0.540485
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a9f2d52c7e28053d21226e504c95e516779744c05d2bc2abd8c82d3f49ddcb3c
33,016
[ -1 ]
33,017
ref.lsp
rwoldford_Quail/examples/arrays/ref.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ref.lsp ;;; ;;; ;;; Authors: ;;; D.G. Anglin 1994. ;;; R.W. Oldford 1994. (in-package q-user) (setf a (array '((100 101 102) (110 111 112) (120 121 122)))) (setf b (array '(28 7 32))) (setf c (array '((10) (20) (30)))) (setf d (array '(9 8 7 6 5) :dimensions '(1 5))) (setf e (array 7 :dimensions '(4 5 6))) (setf days (array '("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun") :class 'ref-array)) (setf f (array 5 :dimensions '())) ;; ie. :dimensions NIL (setf g (array '(((1.1 2.2 3.3 4.4) (5.5 6.6 7.7 8.8) (9.9 11.0 12.1 13.2)) ((10 20 30 40) (50 60 70 80) (90 100 110 120))) :dimensions '(2 3 4))) ;---------------------------------------------------------------------------------- ;;; ref: referencing blocks within arrays ... "ref by margin" ;;; the block of a where columns 0 and 2 intersect with rows 1 and 2 (setf ar1 (ref a '(1 2) '(0 2))) ar1 (dimensions-of ar1) ;;; a VERY IMPORTANT property of objects created by ref is that they ;;; refer back to the original instance ;;; note that the (1 1) element of ar1 is the (2 2) element of a (setf (eref ar1 1 1) 333) ar1 a ;;; This is true even for individual elements. Note the important ;;; distinction between ref of a single element and eref of the same. ;;; ;;; The 0 0 element of a (eref a 0 0) ;;; A reference to the 0 0 element of a (ref a 0 0) ;;; the block of a where all rows intersect column 2. ;;; ;;; Note three things: ;;; ;;; 1. "all rows" can be specified by T or ;;; by listing them all, the latter in this case by (iseq 3) ;;; ;;; 2. if only one row, column, etc is of interest, this may be ;;; specified by its number rather than a list containing its number ;;; ... here we use 2 instead of '(2) ;;; ;;; 3. axes which are of length one 1 masked from the resulting ;;; object .. here the result has dimensions '(3) rather than '(3 1) ;; (setf ac2 (ref a T 2)) ;;; all rows in column 2 ;;; ;;; Note that unprovided trailing arguments default to T ;;; We sometimes call ac2 a ``slice'' because it is a complete slice through ;;; a down its second column and along its first dimension. ;;; More generally, if the reference indices are *all* either a single number ;;; or the letter T as in ac2 or (ref g 1 1 T) ;;; the result is a sometimes called a slice. ;;; ;;; Note also that despite ;;; the fact that ar3 is conceptually a row ie 1x3, matrix-dimensions-of ;;; provides '(3 1), consistent with the convention that all 1d objects ;;; default to being columns. ;;; (setf ar3 (ref a 1)) ;; ;;; All columns in row 1 (dimensions-of ar3) (matrix-dimensions-of ar3) ;;; However, we can still access ar3 like it's a row (setf (eref ar3 0 1) 17) ;;; ... a reminder ... a ;;; nothing forces us to keep rows, columns, etc in the same order ;;; also, a list with :c can be used to take a complement ... here ;;; we want all elements on the third axis except those along 0. ;;; ie '(:c 0) == '(1 2 3) in this case. (ref g '(1 0) '(1 2 0) '(:c 0)) ;;; if we want a reference to retain its original matrix dimensions, we can ;;; use the :shape keyword (setf ar4 (ref a 2 :shape t)) (dimensions-of ar4) ;;; can ref things which were themselves produced by ref, and result still ;;; refers to original object (setf ar5 (ref ac2 '(1 2))) (setf (eref ar5 0) 38) ar5 ac2 a ;;; although eref is flexible about treating 1d objects as rows or columns, ;;; ref is not as forgiving (eref ac2 0 2) (eref ac2 2 0) (ref ac2 '(1 2) 0) ;;; ie 1 & 2 row of a single column --> OK ;; (ref ac2 0 '(1 2)) ;;; ie 1 & 2 column of a single row --> error !! ;;; Note the consequences of this with T (ref ac2 t 0) ;; all rows of a column (ref ac2 0 t) ;; the columns of a single row of a column .. a 0d object ;---------------------------------------------------------------------------------- ;;; ref: referencing groups of elements within arrays by index ;;; ... "ref by indices" ;;; ref by indices is distinguished from ref by margin in that there is only ;;; one argument taken after the object to be referenced, and this argument ;;; is an array or ref-array structure (expressly NOT a list) containing ;;; as elements lists specifying an index into the object. ;;; the result has the same dimensions as the argument array, ;;; with elements of the referenced object corresponding to the indices ;;; eg. an matrix with dimensions '(3) containing elements (0 0 1), (0 1 0), ;;; and (1 0 0) of g (ref g (vector '(0 0 1) '(0 1 0) '(1 0 0))) ;;; a matrix with dimensions '(2 3) containing corresponding elements of a ;;; we use the Quail function ind to build the indices array ;;; a 2x3 array with elements (0 0), etc. (ind '(((0 0) (2 2) (1 1)) ((1 0) (2 1) (0 2)))) (setf ar6 (ref a (ind '(((0 0) (2 2) (1 1)) ((1 0) (2 1) (0 2)))))) ;;; can cheat when the object is 1d and use the index rather than a list ;;; note also that ref-arrays are legitimate indices-ref specifiers (ref '(100 101 102 103 104) (array '((0 1) (2 3)))) ;;; is the same as .. (ref '(100 101 102 103 104) (array '(((0) (1)) ((2) (3))) :dimensions '(2 2))) ;;; we can still do ref-by-margin on an indices-ref (ref ar6 1 '(2 0)) ;---------------------------------------------------------------------------------- ;;;; sel: Copying groups of elements ;;; sel has identical syntax to ref, but the returned instance is a copy of ;;; the original elements a (setf as1 (sel a t '(2 0))) (setf (eref as1 0 1) 567) as1 a ;---------------------------------------------------------------------------------- ;;;; (setf ref): Setting groups of elements ;;; you can set an group of elements you can reference with ref to a set ;;; of new values by providing a new-value object with the same dimensions (setf (ref a t 1) '(987 654 321)) ;;; (setf sel) is identical to (setf ref) ... NO difference in functionality
6,231
Common Lisp
.l
143
39.916084
84
0.597668
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
77b664917508cc06d19f080ad5f8ce032d3d10d2cc12af8f89f0aed88c18ffbe
33,017
[ -1 ]
33,019
search.lsp
rwoldford_Quail/examples/arrays/search.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Searching refable objects ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;; ;;; In this file, we illustrate the use of the following map functions ;;; macros for refable objects: ;;; ;;; ... find-slices ... Finds all slices in ref-object which ;;; match item when the function test ;;; is applied to item and the slice of ref-object. ;;; It returns a list of the slices found. ;;; ... find-slices-if ... Finds every slice in ref-object which returns ;;; non-NIL when the function pred is applied ;;; to it. ;;; It returns a list of the slices found. ;;; ... count-slices ... Counts all slices in ref-object which match ;;; item when the function test is applied to ;;; item and the slice of ref-object. ;;; It returns the number of slices found. ;;; ... count-slices-if ... Counts every slice in ref-object which ;;; returns non-NIL when a function pred is ;;; applied to it. ;;; It returns the number of slices found. ;;; ... slice-positions ... Finds all slices in ref-object which match ;;; item when the function test is applied to ;;; item and the slice of ref-object. ;;; It returns a list of the positions of the ;;; slices found. ;;; ... slice-positions-if ... Finds the position of every slice in ;;; ref-object which returns non-NIL when the ;;; function pred is applied to it. ;;; It returns a list of the positions of the ;;; slices found. ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :quail-user) ;;; ;;; Some arrays to work with. ;;; (setf a (array (iseq 6) :dimensions '(2 3))) (setf b (array (iseq 1 24) :dimensions '(2 3 4))) ;; 2 rows, 3 cols, 4 layers (setf c (ref a 0)) (setf d (sel a)) (setf (eref d 0 0) NaN) (setf e (sel b)) (setf (eref e 0 0 0) NaN) ;;; ;;; And the following print function may be helpful to see what the ;;; pieces. ;;; (defun print-slices (obj &key (slices :elements) (order :row)) (let ((i 0)) (format *quail-terminal-io* "~&~% Order is ~s~%" order) (doslices (slice obj slices 'done order) (format *quail-terminal-io* "~& Slice ~s is ~s" i slice) (incf i)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; find-slices ;;; ;;; (find-slices item ref-object ;;; :order :row ;;; :slices :elements ;;; :test #'ref-eq) ;;; ;;; Finds all slices in ref-object which ;;; match item when the function test ;;; is applied to item and the slice of ref-object. ;;; It returns a list of the slices found. ;;; ;;; Look for elements (find-slices 3 a) (find-slices 9999 a) (find-slices NaN d) (find-slices 7 a :test #'>) (find-slices 7 a :test #'> :order :column) ;;; Look for larger slices (find-slices c a :slices 0) ;;; which is there because c is a ref of the first row of a ;;; and so satisfies the test ref-eq. ;;; But it is NOT the identical structure ;;; and so fails on the eq test. (find-slices c a :slices 0 :test #'eq) ;;; Note that numbers are eq so (find-slices 3 a :test #'eq) ;;; works. ;;; ;;; Neither is c a column of a. (find-slices c a :slices 1) ;;; ;;; And more general structures can be searched ;;; (find-slices (ref e 0 0 t) e :slices '(0 1)) ;;; will find a slice ;;; but a copy of that slice will not be found! (find-slices (sel e 0 0 t) e :slices '(0 1)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; find-slices-if ;;; ;;; (find-slices-if pred ref-object ;;; :order :row ;;; :slices :elements) ;;; ;;; Finds every slices in ref-object which ;;; returns non-NIL when the predicate function pred is called on it. ;;; It returns a list of the slices found. ;;; ;;; Look for elements (find-slices-if #'(lambda (x) (< x 3)) a) (find-slices-if #'(lambda (x) (< x 7)) e) (find-slices-if #'(lambda (x) (< x 7)) e :order :column) (find-slices-if #'(lambda (x) (eq x NaN)) a) (find-slices-if #'(lambda (x) (eq x NaN)) d) ;;; Note that eq had to be used in last two searches. ;;; Because NaN is special and may result from +infinity/-infinity or ;;; 0/0 or -0/0 , etc. it is dangerous to say that two NaNs are = ;;; Therefore (= NaN NaN) always returns NIL. ;;; And so will (find-slices-if #'(lambda (x) (= x NaN)) d) ;;; ;;; We might write a function then that checks for NaNs ;;; as follows: (defun find-NaNs (thing) (find-slices-if #'(lambda (x) (eq x NaN)) thing)) (find-NaNs a) (find-NaNs b) (find-NaNs c) (find-NaNs d) (find-NaNs e) ;;; ;;; And it is a small step from there to one that checks ;;; arbitrary slices for NaNs and illustrates a lot of what ;;; we have learned so far. ;;; (defun find-NaNs (thing &key (slices :elements) (order :row)) (when (numberp slices) (setf slices (list slices))) (case order (:row (loop for i from 0 to (- (number-of-slices thing slices) 1) when (find-slices-if #'(lambda (x) (eq x NaN)) (row-major-ref-slice thing slices i)) collect (row-major-ref-slice thing slices i))) (:column (loop for i from 0 to (- (number-of-slices thing slices) 1) when (find-slices-if #'(lambda (x) (eq x NaN)) (column-major-ref-slice thing slices i)) collect (column-major-ref-slice thing slices i))) )) ;;; ;;; As before ;;; (find-NaNs a) (find-NaNs b) (find-NaNs c) (find-NaNs d) (find-NaNs e) ;;; ;;; But we can now find say all the rows of e that contain NaN ;;; (find-nans e :slices '(0 2)) ;;; All row layers (find-nans e :slices 0) ;;; All columns (find-nans e :slices '(1 2)) ;;; All layers (find-nans e :slices 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; count-slices ;;; ;;; (count-slices item ref-object ;;; :slices :elements ;;; :test #'ref-eq) ;;; ;;; Counts all slices in ref-object which match ;;; item when the function test is applied to ;;; item and the slice of ref-object. ;;; It returns the number of slices found. ;;; ;;; Counting elements (count-slices 3 a) (count-slices 9999 a) (count-slices NaN d) (count-slices 7 a :test #'>) ;;; Look for larger slices (count-slices c a :slices 0) ;;; which is there because c is a ref of the first row of a ;;; and so satisfies the test ref-eq. (count-slices c a :slices 0 :test #'eq) ;;; Neither is c a column of a. (count-slices c a :slices 1) ;;; ;;; And more general structures can be searched ;;; (count-slices (ref e 0 0 t) e :slices '(0 1)) ;;; will count a slice but not its copy. (count-slices (sel e 0 0 t) e :slices '(0 1)) (count-slices NaN a :test #'eq) (count-slices NaN b :test #'eq) (count-slices NaN c :test #'eq) (count-slices NaN d :test #'eq) (count-slices NaN e :test #'eq) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; count-slices-if ;;; ;;; (count-slices-if pred ref-object ;;; :slices :elements) ;;; ;;; Counts every slice in ref-object which returns non-NIL ;;; when the function pred is applied to it. ;;; It returns the number of slices found. ;;; ;;; ;;; Count elements (count-slices-if #'(lambda (x) (< x 3)) a) (count-slices-if #'(lambda (x) (< x 7)) e) (count-slices-if #'numberp e) (count-slices-if #'(lambda (x) (eq x NaN)) e) (count-slices-if #'(lambda (x) (eq x NaN)) d) ;;; ;;; And similarly for higher dimensionsal structures ;;; (count-slices-if #'find-nans e :slices 0) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; slice-positions ;;; ;;; ;;; ;;; (slice-positions item ref-object ;;; :order :row ;;; :slices :elements ;;; :test #'ref-eq) ;;; ;;; Finds all slices in ref-object which match ;;; item when the function test is applied to ;;; item and the slice of ref-object. ;;; It returns a list of the positions of the slices found. ;;; ;;; Look for elements (slice-positions 3 a) (print-slices a) (slice-positions 9999 a) (slice-positions NaN d) (slice-positions 7 e :test #'>) (print-slices e) (slice-positions 7 e :test #'> :order :column) (print-slices e :order :column) ;;; Positions of larger slices (slice-positions c a :slices 0) (slice-positions (ref e 0 0 t) e :slices '(0 1)) ;;; ;;; Find-slices could have been implemented using slice-positions ;;; (loop for i in (slice-positions 7 e :test #'> :order :column :slices :elements) collect (column-major-ref-slice e :elements i)) ;;; ;;; is the same as ;;; (find-slices 7 e :test #'> :order :column :slices :elements) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; slice-positions-if ;;; ;;; (slice-positions-if ;;; pred ref-object ;;; :order :row ;;; :slices :elements) ;;; ;;; Finds the position of every slice in ;;; ref-object which returns non-NIL when the ;;; function pred is applied to it. ;;; It returns a list of the positions of the slices found. ;;; (slice-positions-if #'(lambda (x) (< x 3)) a) (slice-positions-if #'(lambda (x) (< x 7)) e) (slice-positions-if #'(lambda (x) (< x 7)) e :order :column) (slice-positions-if #'(lambda (x) (eq x NaN)) a) (slice-positions-if #'(lambda (x) (eq x NaN)) d)
10,928
Common Lisp
.l
320
29.734375
86
0.520449
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c73db228203d496012791867e330e16d4fad2439a9381fad28243b2a3206e0df
33,019
[ -1 ]
33,020
select-by-pred.lsp
rwoldford_Quail/examples/arrays/select-by-pred.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Selecting elements by predicate ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. (in-package :quail-user) ;;; ;;; (setf a (array '((1.2 3 4.5) (6.7 8.9 0.1)) :dimensions '(2 3))) ;;; ;;; For large arrays, it is often more convenient to do ;;; assignment with <- instead of setf. No value is returned ;;; (and hence no value printed!) with <- (<- b (array (random-gaussian :n 100) :dimensions '(5 4 5))) (<- c (array (random-cauchy :n 100) :dimensions '(5 4 5))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; INDICES ;;; ;;; find the indices of a whose values are greater than 2. (defun 2< (x) (< 2 x)) (indices a #'2<) ;;; ;;; Look for some outliers ;;; (defun outlier (x) (> (abs x) 3)) ;;; Indices of those from a cauchy sample ;;; (indices c #'outlier) ;;; From a gaussian sample (indices b #'outlier) ;;; ;;; Now select those observations ;;; (ref b (indices b #'outlier)) (ref c (indices c #'outlier)) (ref a (indices a #'2<)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; REF-IF ;;; ;;; The above behaviour has been put together as a single function ;;;
1,222
Common Lisp
.l
46
23.347826
67
0.529049
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d3e966e96c52fc570957ab9de1bd0a0c9a93862a826ef1f592026d7ed987c808
33,020
[ -1 ]
33,021
array.lsp
rwoldford_Quail/examples/arrays/array.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Advanced array creation ;;; ;;; ;;; Authors: ;;; D.G. Anglin 1994. (in-package :q-user) (array '(1 2 3 4 5 6) :dimensions '(3 2)) (array '(1 2 3 4 5 6) :dimensions '(3 2) :fill :col) (array '((1 2) (1 1)) :dimensions '(2)) ;; (array '((1 2) (3 4) (5 6)) :dimensions '(6)) ;; an error (array (vector 0 1 2) :dimensions '(3 4)) ;; note orientation of fill !! (array (make-array '(3 1) :initial-contents '((0) (1) (2))) :dimensions '(3 4) :fill :col) (array '(1 2 3) :dimensions '(4)) ;; a warning !! (array '(1 2 3 4) :dimensions '(3)) ;; another warning .. ;; a simple implementation of matrix transpose (defun my-transpose (x) (array x :dimensions (reverse (matrix-dimensions-of x)) :fill :col)) (my-transpose (array '((1 2) (3 4)))) (my-transpose '(1 2 3 4)) ;; 1d things are by default columns; so, result is 1x4 ;; The next is an error since the contents are an incorrectly shaped ;; nested list. ;; (array '((1 2 3) (4 5 6)) :dimensions '(3 2)) ;; an error ;; Do this instead to deal with nested lists (array (flatten '((1 2 3) (4 5 6))) :dimensions '(3 2)) ;; works ;; suppose you want a ref-array full of a single list (array '(1 2 3) :deconstruct nil :dimensions '(2 2)) ;; but each element is eq (setf a1 '(1 2 3)) (setf a2 (array a1 :deconstruct nil :dimensions '(2 2))) (setf (eref (eref a2 0 1) 2) 300) a1 a2 ;; can avoid this problem, though (setf a4 (array a1 :deconstruct nil :dimensions '(2 2) :element-copy #'copy-list)) (setf (eref (eref a4 0 0) 1) 2000) a1
1,676
Common Lisp
.l
43
34.930233
83
0.585381
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f2298c12f303ba949370c26df3a288fb58b3706e126bce64e2037347ba624529
33,021
[ -1 ]
33,022
arith-ops.lsp
rwoldford_Quail/examples/arrays/arith-ops.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Arithmetic operations on arrays ;;; ;;; ;;; Authors: ;;; D.G. Anglin 1994. (in-package :quail-user) (setf a (array '((1 3 5) (6 8 10)))) (setf b (array '((101.2 103.0 104.5) (206.7 208.9 200.1)))) (setf c (array '((100.0) (200.0)))) (setf d '(0 10 20 30 40 50 60 70 80)) (setf g (array '(1 2 3 4 5) :dimensions '(5 2 3) :fill :col)) ;------------------------------------------------------------------------------ ;; Element-wise mathematical operations. ;; +, -, *, / operate element-wise in extended real numbers (ie. numbers plus ;; the special symbols NAN [Not A Number], INFINITY, +INFINITY, -INFINITY). ;; These operations are all n-ary. ;; Each operation attempts to find the most reasonable meaning of the operator ;; in a given context. ;; a and b have exactly the same shape, so they are added element-wise (+ a b) ;; similarly for other operators (* a b) (* d d d) ;; a has two rows, so the 1d object '(20 30) is treated as a column, and subtracted ;; from each column (- a '(20 30)) ;; a has three columns, so the 1d object '(100 200 300) is treated as a row, and ;; each row is divided by it element-wise. In an ambiguous case, a 1d object is ;; a column. (/ a '(100 200 300)) ;; the - and / operators can accept unary args (- d) ;; we work in extended numbers ... illegal mathematical operations in the reals ;; will often produce successful results in the extended reals (/ d) (setf (eref b 0 1) nan) b (/ b a) ;; element-wise mathematical operators work on num-arrays as well (* g (- 1 g)) ;;; ;;; Extending the functionality. ;;; ;;; Each of the four operators + - / * ;;; are implemented using the generic functions ;;; plus-object minus-object divides-object and times-object respectively. ;;; Each takes two arguments representing the two operands of the mathematical ;;; function. ;;; To introduce these functions for new data types where + - / * ;;; might have some meaning, you will need to implement the corresponding ;;; plus-object ... etc. for the class of arguments it is expected to receive. ;;; If this new + etc. might be used as a unary function, then you will also need ;;; to implement a plus-object etc whose first argument is :identity ;;; and whose second argument is an object of the new class. ;;; The logical predicates > >= < <= = have not been implemented for arrays. ;;; However their implementation would proceed in exactly the same way by implementing ;;; methods ;;; greater-than-object greater-than-equals-object ;;; less-than-object less-than-equals-object and equals-object ;------------------------------------------------------------------------------ ;; Min and Max. (min 3 a) (min (* 25 a) b) (min +infinity 5 0.7 2000) (max 5 nan) (min -infinity NaN) (max -infinity NaN) ;;; These can be extended in the same way as other operators by ;;; defining appropriate methods for min-object and max-object ;------------------------------------------------------------------------------ ;; Basic behaviour of the transpose function tp. (setf at (tp a)) (tp (array '(3 4 5))) ;------------------------------------------------------------------------------ ;; Matrix multiplication and dot product ;; ( A heuristic for remembering this operator is to think "dot" "product" ) (.* at a) (.* at b) ;; this is the dot-product operator for 1d things of same size (.* d d) ;; 1d objects are ALWAYS columns to .* (setf f (array '((1 2) (3 4)))) (.* f '(10 20)) ;; (.* '(10 20) f) ;; an error (.* (tp '(10 20)) f) ;------------------------------------------------------------------------------ ;; Advanced behavior of the transpose function tp. (setf gt (tp g)) ;; by default, the dimensions are the reverse of the original dimensions (dimensions-of gt) ;; an equivalent specification (setf gt (tp g :perm '(2 1 0))) ;; a different array (setf gt2 (tp g :perm '(2 0 1))) (dimensions-of gt2)
4,155
Common Lisp
.l
97
39.43299
87
0.598064
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e73493a5cd93a8d346a235941085283d381e24dd3ad07c5224cd4769ff4c4750
33,022
[ -1 ]
33,023
handy-arrays.lsp
rwoldford_Quail/examples/arrays/handy-arrays.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Some handy array creation functions ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. (in-package q-user) ;;; Some arrays are created frequently so it is useful to have ;;; a few functions that will create them automatically. ;;; ;;; Here are some that we find useful and so offer to you. Search for ;;; section or the topic that interests you. ;;; ;;; Contents ;;; 1. Array of ones. ;;; 2. Sequences. ;;; seq, iseq ;;; 3. Diagonals of matrices and diagonal matrices. ;;; 4. Identity-matrix. ;;; 5. Upper triangular matrices. ;;; ;;; ;;; \section 1.0 Array of ones. ;;; ;;; The function ones-array creates a numerical array (num-array) ;;; of 1s of the dimensions given. (ones-array 25) (ones-array 2 3 5) ;;; \section 2.0 Sequences. ;;; ;;; There are two functions, seq and iseq, that create arrays and ;;; lists of sequences. ;;; ;;; Create a sequence in a Quail array (seq 1 10) (seq -10 10) (seq 10 100 10) (seq 10 -10 -1) (seq 1.2 1.5 .05) ;;; ;;; Note end points are firm ;;; (seq 1.2 1.5 .06) ;;; To create a sequenced array of arbitrary dimension use array and seq ;;; together. (array (seq 1 10) :dimensions '(2 5)) ;;; ;;; A list of integers ;;; (iseq -10 10) (iseq 10 -10) (iseq -30 -20) ;;; \section 3.0 Diagonals of matrices and diagonal matrices. ;;; ;;; Occasionally it is convenient to extract only the diagonal elements ;;; of a square matrix. These are had using the function diagonal-of ;;; (<- square (array (iseq 16) :dimensions '(4 4))) (diagonal-of square) ;;; Similarly, it is sometimes convenient to construct a diagonal matrix ;;; from the contents of some other matrix. (diagonal '(1 2 3 4)) (diagonal (diagonal-of square)) (diagonal square) ;;; \section 4.0 Identity-matrix. ;;; ;;; Identity matrices are very handy and easily constructed. The ;;; 4 by 4 identity matrix (<- I4 (identity-matrix 4)) ;;; is an instance of the class identity-matrix. This has advantages ;;; for storage as (<- I100000000 (identity-matrix 100000000)) ;;; takes as much space as I4. ;;; It also has an advantage at matrix multiply time, (.* I4 square) ;;; \section 5.0 Upper triangular matrices. ;;; ;;; As with diagonal-of, we also have upper-triangle-of to create ;;; an upper triangular matrix whose upper triangle has the same elements ;;; as the upper triangle of its matrix argument.
2,783
Common Lisp
.l
86
29.476744
87
0.618347
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
74dcc3ae951573ce9e09410cda9a80419bad3564a38b92f0de2d36930c3af4a7
33,023
[ -1 ]
33,024
iter-elements.lsp
rwoldford_Quail/examples/arrays/iter-elements.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; General Iteration over elements ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;;;;;;;;;;;;;;;;;;;; ;;; ;;; SEE ALSO doslices and collect-slices (in-package :quail-user) (setf a (array '((1.2 3 4.5) (6.7 8.9 0.1)) :dimensions '(2 3))) (setf b (seq 10 -10 -1)) (setf small-b (ref b '(:c 0 1 2))) ;; all but the first three elements of b (setf c (array (random-uniform :n 4) :dimensions '(2 2))) (setf d (sel a)) ;; a copy of a (setf e (array (seq 1 24) :dimensions '(2 3 4))) ;; 2 rows, 3 cols, 4 layers ;;; ;;; In this file, we illustrate the use of the following ;;; functions for arrays: ;;; ... column-major-eref ;;; column-major-list-elements ;;; column-major-set-elements ;;; column-major-ref-slice ;;; row-major-eref ;;; row-major-list-elements ;;; row-major-set-elements ;;; row-major-ref-slice ;;; ;;; We have already illustrated some of these. ;;; They are especially useful to iterate over the elements of an array. ;;; ;;; For example, to access the elements of an arbitrary array in ;;; row-major-order, that is last index changing fastest and the first slowest, ;;; we have: (defun print-in-row-order (a) "This prints out all the elements of the array a in row major order" (let ((n (number-of-elements a))) (format *quail-terminal-io* "~&In row-major order,") (loop for i from 0 to (- n 1) do (format *quail-terminal-io* "~&Element ~s = ~s" i (row-major-eref a i))))) (print-in-row-order a) (print-in-row-order b) ;;; Or in either row or column major order (defun print-elements (a &key (order :row)) "This prints out all the elements of the array a in either row or~ column major order. Which depends on the keyword" (let ((n (number-of-elements a))) (cond ((eq order :row) (format *quail-terminal-io* "~&In row-major order,") (loop for i from 0 to (- n 1) do (format *quail-terminal-io* "~&Element ~s = ~s" i (row-major-eref a i)))) ((eq order :column) (format *quail-terminal-io* "~&In column-major order,") (loop for i from 0 to (- n 1) do (format *quail-terminal-io* "~&Element ~s = ~s" i (column-major-eref a i)))) ))) (print-elements a :order :row) (print-elements a :order :column) (print-elements b :order :row) (print-elements b :order :column) ;;; ;;; Both column-major-eref and row-major-eref can be used ;;; with setf (setf (column-major-eref a 0) 9999) a ;;; ;;; ;;; It is often required that we manipulate whole slices of a ;;; refable quantity. ;;; ;;; To that end, we provide the functions ;;; ;;; number-of-slices ;;; column-major-ref-slice ;;; row-major-ref-slice ;;; ;;; ;;; For example suppose we want to know the mean of several slices of ;;; a mult-way array. ;;; Then we could write (defun slice-means (thing slices &optional (order :row)) "Calculates and returns a list of the means of slices of thing. ~ where slices is a list of those dimensions in thing which ~ define a slice. All other dimensions determine the interior ~ contents of each slice. Order is an optional argument ~ which determines the order in which the slices are traversed.~ The default value of order is :row, it can also be :column for ~ column major order instead of row major order." (if (numberp slices) (setf slices (list slices))) ; this allows us to be a bit sloppy ; in specifying slices (let ((n (number-of-slices thing slices))) (cond ((eq order :row) (loop for i from 0 to (- n 1) collect (mean (row-major-ref-slice thing slices i)))) ((eq order :column) (loop for i from 0 to (- n 1) collect (mean (column-major-ref-slice thing slices i))))))) ;;; ;;; Row means of a are (slice-means a 0) ;;; ;;; Column means of a are (slice-means a 1) ;;; ;;; Column means of a in column major order over the slices are (slice-means a 1 :column) ;;; ;;; No difference because the slices were only over 1 fixed dimension ;;; (dimensions-of e) ;;; ;;; `layer' means of e are ;;; (slice-means e 2) ;;; ;;; Column means of e for every layer ;;; (slice-means e '(1 2)) ;;; ;;; Like row-... and column-major-eref, row-... and column-major-ref-slice ;;; can be used with setf, or <-, as in (setf (column-major-ref-slice e '(2) 0) ;; set the first (0) layer (slices = '(2) ) ;; of e to be full of 99s (array 99 :dimensions '(2 3))) (ref e t t 0) ;; all rows all columns first layer e ;;; ;;; Be careful these are genuine refs, NOT COPIES. ;;; ;;; Example: put slice of an array with the largest mean at the end ;;; by pushing it down through the array one slice at a time. ;;; (defun push-big-mean-down (x &optional slices) ;; First we will allow slices to be a number. If it is we turn it ;; into a list and carry on. (if (not (listp slices)) (setf slices (list slices))) (let (swap) ; swap is the temporary variable ; to be used for the swap. (loop for i from 1 to (- (number-of-slices x slices) 1) when (> (mean (column-major-ref-slice x slices (- i 1))) (mean (column-major-ref-slice x slices i))) ;; ;; Then we want to swap slices do (<- swap (sel (column-major-ref-slice x slices i))) ;; ^^^ note we must COPY the slice to be overwritten ;; hence the SEL. Otherwise you will lose it! (<- (column-major-ref-slice x slices i) (column-major-ref-slice x slices (- i 1))) (<- (column-major-ref-slice x slices (- i 1)) swap))) x) a ;; Push the column with the largest mean to the end of a (push-big-mean-down a 1) e ;;; Last layer of e (ref e t t 3) ;; Push the layer with the largest mean to the end of e (push-big-mean-down e 2) ;;; New last layer of e (ref e t t 3) ;;;;;;;;;;;;;;;;; ;;; ;;; slices = :element ;;; ;;; There is an important special case for the slices argument that ;;; makes column-major-ref-slice and row-major-ref-slice behave ;;; exactly as their *-major-eref counterparts. ;;; Namely, if given the keyword :elements as the value of the ;;; slices argument then they are identical to their eref counterparts. ;;; ;;; This means that the elements can be accessed and set directly with ;;; column- and row-major-ref-slice. ;;; This is very convenient for the definition of higher level mapping ;;; functions like sort, reduce-slices, etc. ;;; ;;; Alternatively, if all dimensions are specified as the slices ;;; argument then a reference to each element is returned. ;;; The distinction is illustrated below: (column-major-ref-slice a :elements 0) ;;; returns the element, whereas if all dimensions define a slice, as in (column-major-ref-slice a (iseq (number-of-dimensions a)) 0) ;;; then a zero-dimensional reference to the element is returned. ;;; ;;; Either can be used with setf and will achieve the same result (setf (column-major-ref-slice a :elements 0) 99) (eref a 0 0) (setf (column-major-ref-slice a (iseq (number-of-dimensions a)) 0) 999) (eref a 0 0) ;;;;;;;;;;;;;;; ;;; ;;; Occasionally you will want a list of all the elements in a ref'able thing. ;;; ;;; This can be had in column- or row-major order respectively with the ;;; functions: ;;; column-major-list-elements ;;; row-major-list-elements ;;; These are sometimes handy for the loop macro which can loop over lists ;;; as part of its arguments as in (loop for thing in (list "a" 1 "v") do (print thing)) a (column-major-list-elements a) (row-major-list-elements a) ;;; ;;; or ;;; (loop for x in (column-major-list-elements a) sum x) (row-major-list-elements "abcdefghij") ;;; ;;; SImilarly, you might have a list of elements which you would like to use to fill ;;; your ref'able structure with, as in: (column-major-set-elements a '(1 2 3 4 5 6)) ;;; ;;; or ;;; (row-major-set-elements a '(1 2 3 4 5 6)) ;;; ;;; The principal value of these last 4 functions is to make use ;;; of the many procedures available in Lisp that operate on lists
9,206
Common Lisp
.l
239
32.807531
90
0.587276
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fdffe36eb9ce4180c5fe6de08d46cd384510b1502238b32e352662d043801648
33,024
[ -1 ]
33,025
sort.lsp
rwoldford_Quail/examples/arrays/sort.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Sorting array contents ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. (in-package :quail-user) (setf a (array '((1.2 3 4.5) (6.7 8.9 0.1)) :dimensions '(2 3))) (setf b (seq 10 -10 -1)) (setf small-b (ref b '(:c 0 1 2))) ;; all but the first three elements of b (setf c (array (random-uniform :n 4) :dimensions '(2 2))) (setf d (sel a)) ;; a copy of a (setf e (array (iseq 1 24) :dimensions '(2 3 4))) ;; 2 rows, 3 cols, 4 layers ;;;---------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;; ;;; ;;; SORT has two required arguments: The object to be sorted and ;;; the predicate to be used to compare two elements. ;;; The predicate should take two arguments and return non-NIL if and ;;; only if the first argument is to be regarded as preceding the ;;; the second. ;;; As with the Common Lisp sort function, sort is by default destructive. ;;; Unlike the Common Lisp sort it has a keyword copy? which when T ;;; will first copy the object and then sort it. ;;; Sorts the sub-arrays of slices of ref-object into an order ;;; determined by predicate. The arguments predicate and key are to be interpreted ;;; exactly as the same named arguments in the Common Lisp sort function. ;;; The argument stable? is NIL (the default) or non-NIL depending on whether ;;; it is desirable that stability be guaranteed in the sense of the Common Lisp ;;; function stable-sort. ;;; ;;; These types of sort are possible: ;;; ;;; 1. If the arguments permit, then sort follows the Common Lisp standard. (sort '(5 4 3 5 1 2) #'<) (sort "zyxwv" #'char< ) ;;; 2. For most uses, the sort in Quail will look just like the sort in ;;; Common Lisp, just extended to cover arrays as well as sequences. (sort b #'<) ;;; As was the case in the previous example, this was destructive. ;;; This has important consequences when we use ref instead of sel ;;; to reference blocks of an array. Not only is b affected by the ;;; above sort, but so is any ref of it. Look at small-b ;;; It is now all but the first three elements of the SORTED b. ;;; ;;; For non-destructive sorts, the keyword argument copy? must ;;; be non-NIL (sort a #'< :copy? T) ;;; has now sorted the elements of a into a copy of a. The array a ;;; is unchanged. ;;; Note that the cost is cost of copying a before the sort. ;;; 3. If object is a ref-object and type is :interior then, ;;; for example, (sort d #'> :slices 1 :type :interior) ;;; rearranges the contents of each column (slices 1) of the matrix d ;;; so that the greatest element is in the first row, and so forth. ;;; 4. If object is a ref-object and type is :exterior (the default), then (sort a #'> :key #'sum :slices 1 :type :exterior) ;;; rearranges the columns (slices 1) of the matrix a ;;; so that the column with the greatest total is the 0-th column, and so forth. ;;; ;;; 5. In all of the above, destructive sorts are performed if copy? is nil ;;; (the default). ;;; If copy? is t, then a non-destructive sort is performed. ;;; ;;; ;;; ;;; Now let's start fooling around with the 3-way array e ;;; This should give us some idea of what slices are all about as well ;;; as the distinction between interior and exterior. ;;; We will always work with copies so as to not mess up the original array, e. ;;; ;;; First some familiarity with e is in order. ;;; (dimensions-of e) ;;; Now suppose that we wanted a sort where the slice was defined to be 1 (setf slice 1) ;;; that is if e is 2 by 3 by 4, then we would want to look at all 2 by 4 ;;; sub-blocks of e and these are indexed entirely by the 1 index. ;;; they are (loop for i from 0 to (- (number-of-slices e slice) 1) ; 1 must be subtracted ; because of zero based do ; indexing (print i) (print (ref e T i T)) ; Slice indexed by second ; second index i.e. index 1 ; Entries taken are with all ; other indices used (ie T) ) ;;; A little nicer print out illustrates the use of the CL format function ;;; (defun print-slice (object i) (format *quail-terminal-io* "~&Slice ~s is ~%~10T ~s" i (ref object T i T))) (loop for i from 0 to (- (number-of-slices e slice) 1) do (print-slice e i) ) ;;; ;;; Note that each slice is of the proper dimension. ;;; ;;; ;;; Suppose that we want to sort the contents of each slice in descending order ;;; (<- f (sort e #'> :slices slice :copy? T :type :interior)) (loop for i from 0 to (- (number-of-slices f slice) 1) do (print-slice f i) ) ;;; ;;; And finally, suppose that we want to shuffle the slices so that ;;; the one with the larger mean elements are first. ;;; (loop for i from 0 to (- (number-of-slices e slice) 1) do (print-slice e i) (format *quail-terminal-io* "~&~10T Mean = ~s" (mean (ref e t i t))) ) (defun bigger (a b) (> (mean a) (mean b))) (<- g (sort e #'bigger :slices slice :type :exterior :copy? T)) (loop for i from 0 to (- (number-of-slices g slice) 1) do (print-slice g i) (format *quail-terminal-io* "~&~10T Mean = ~s" (mean (ref g t i t))) ) ;;; ;;; Interior sorts when no slices are given will apply the sort to ;;; individual elements. ;;; (sort (list 1 2 3) #'> :type :interior) ;;; will try to sort each of the interiors 1, 2 and 3 respectively and ;;; so will return the original list unaltered. ;;; ;;; Similarly (sort "zyxwvutsrqponmlkjihgfedcba" #'char< :type :interior) ;;; doen't really do anything and so is quite different from (sort "zyxwvutsrqponmlkjihgfedcba" #'char< :type :exterior) ;;; ;;; The copy? flag applies only to the original object ;;; NOT TO ITS ELEMENTS! (setf foo (list a b )) (setf bar (sort (list a b) #'> :type :interior :copy? T)) ;;; Note that this sort is destructive to the interior elements! a b ;;; The copy? flag applied only to the original list foo. ;;; foo and bar have the same contents (and (eq (eref foo 0) (eref bar 0)) (eq (eref foo 1) (eref bar 1))) ;;; But bar is indeed a copy of foo and hence a different list. (eq foo bar) ;;; ;;; ;;; EXTENDING SORT. ;;; If you want to extend sort to new object classes, ;;; You need only define the appropriate methods for the generic-function ;;; sort-object using defmethod or defmethod-multi ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; SORT-POSITION and RANKS ;;; ;;; Sometimes one would only like the relative positions of the ;;; elements or slices of an object. ;;; On other occasions one would like to know the relative rankings of the ;;; elements or slices of an object. ;;; ;;; These two different functionalities are given by the functions ;;; sort-position and ranks respectively. ;;; It is easy to confuse these two different functionalities. BE CAREFUL! ;;; ;;; Some examples will help. (setf h '(1 4 2 3)) ;;; ;;; In this sequence the first number is the smallest and so has rank 0, ;;; the second is largest and so has rank 3, and so on (ranks h #'<) ;;; returns the desired rankings. ;;; ;;; When we are concerned about sorting the numbers however, we may like to ;;; know what the position the sorted elements have in the original object. ;;; Sorted, this list would be (setf i (sort h #'< :copy? T)) ;;; The positions of these elements in the original object h are (setf j (sort-position h #'<)) ;;; ;;; The sort-positions are the indices in the original object of the ;;; elements in sorted position. ;;; You could use these positions to look up ordered values in the ;;; original object, as in (loop for pos in (sort-position h #'<) collect (eref h pos)) ;;; ;;; to collect the ordered values of the list h. ;;; ;;; Alternatively there exists a function called ORDER that will ;;; do just that for you. ;;; (order h (sort-position h #'<) :copy? T ) ;;; ;;; Some higher dimensional examples: ;;; ;;; Let's look at e and a random permutation of its contents. ;;; e (dimensions-of e) (setf k (permute e :copy? T)) (dimensions-of k) ;;; ;;; First ranks ;;; ;;; The ranks of the contents (in row-major-order) are (ranks e #'<) (ranks k #'<) ;;; The ranks within every element of the contents (in row-major-order) are (ranks e #'< :type :interior) ;;; Now within various slices ;;; ;;; ;;; ;;; The ranks within each layer are easiest to see ;;; e (ranks e #'< :slices '(0 1) :type :interior) k (ranks k #'< :slices '(0 1) :type :interior) ;;; ;;; The ranks within each layer of the contents (in row-major-order) are ;;; (ranks e #'< :slices 2 :type :interior) (ranks k #'< :slices 2 :type :interior) ;;; ;;; The ranks within each row ;;; (ranks e #'< :slices '(0 2) :type :interior) (ranks k #'< :slices '(0 2) :type :interior) ;;; ;;; The ranks within each column ;;; (ranks e #'< :slices '(1 2) :type :interior) (ranks k #'< :slices '(1 2) :type :interior) ;;; ;;; And some :exterior rankings. Again layers are easiest to see. ;;; e (ranks e #'< :key #'sum :slices '(0 1) :type :exterior) ;;; ;;; or equivalently ;;; (ranks e #'(lambda (x y) (< (sum x) (sum y))) :slices '(0 1) :type :exterior) ;;; ;;; and for k ;;; k (ranks k #'< :key #'sum :slices '(0 1) :type :exterior) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; SORT-POSITION ;;; ;;; ;;; ;;; The positions of the contents (in row-major-order) are (sort-position e #'<) (sort-position k #'<) ;;; The positions within every element of the contents (in row-major-order) are (sort-position e #'< :type :interior) ;;; Now within various slices ;;; ;;; ;;; ;;; The positions within each layer are easiest to see ;;; e (sort-position e #'< :slices '(0 1) :type :interior) k (sort-position k #'< :slices '(0 1) :type :interior) ;;; ;;; The positions within each layer of the contents (in row-major-order) are ;;; (sort-position e #'< :slices 2 :type :interior) (sort-position k #'< :slices 2 :type :interior) ;;; ;;; And some :exterior rankings. Again layers are easiest to see. ;;; e (sort-position e #'< :key #'sum :slices '(0 1) :type :exterior) ;;; ;;; or equivalently ;;; (sort-position e #'(lambda (x y) (< (sum x) (sum y))) :slices '(0 1) :type :exterior) ;;; ;;; and for k ;;; k (sort-position k #'< :key #'sum :slices '(0 1) :type :exterior) ;;; ;;; The positions of the layers within each column and row ;;; (setf k (sort-position e #'> :slices '(0 1) :type :interior)) ;;; ;;; And again the sort is done by ;;; (setf m (order e k :slices '(0 1) :type :interior :copy? T )) ;;; Or (setf n (sort e #'> :slices '(0 1) :type :interior :copy? T)) ;;;;;;;;;;;;;;;;;; ;;; ;;; A little more on order. It's definition begins ;;; (defun order (object positions ;;; &key ;;; (slices :elements) ;;; (copy? NIL) ;;; (type :exterior) ;;; (order :row)) ;;; ..... ) ;;; Repositions the slices of the fixed-dimensions of object into an order ;;; determined by the second argument, a list of slice positions, ;;; in conjunction with the information ;;; given by the keyword arguments slices, types, and order. ;;; ;;; Positions is a list of indices of the elements or slices in the desired order. ;;; For example, the first element in positions is the index of the slice of ;;; object which will be in the first position of the ordered object. ;;; The list of positions can be interpreted in either row or column major order. ;;; If type is :exterior, the slices are repositioned; if it is :interior, then ;;; the elements of each slice are repositioned. ;;; ;;; ;;; ;;; ;;; And suppose we are looking at all slices of e that correspond ;;; to fixing dimensions 0 and 1 of e. It will be convenient to ;;; assign this to a variable. (setf slices '(0 1)) ;;; That is each slice will have dimensions (ref (dimensions-of e) (sort (set-difference (iseq (number-of-dimensions e)) slices) #'<)) ;;; ;;; Here's an even more helpful print function that uses the Quail ;;; iteration macro doslices ... more on that in later files. ;;; (defun print-slices (obj slices order) (let ((i 0)) (format *quail-terminal-io* "~&~% Order is ~s~%" order) (doslices (slice obj slices 'done order) (format *quail-terminal-io* "~& Slice ~s is ~s" i slice) (incf i)))) ;;; ;;; Now we can print the slices in either row or column major order. ;;; (print-slices e slices :row) (print-slices e slices :column) ;;; And suppose we want to shuffle these around according to some ;;; random permutation as in (setf pos (permute (iseq (number-of-slices e slices)))) ;;; Then using the default order (row-major) we have (print-slices e slices ::row) (setf l (order e pos :slices slices :copy? T)) (print-slices l slices ::row) ;;; which is always the same as (setf foo (order e pos :slices slices :copy? T :order :row)) (print-slices foo slices :row) ;;; But rarely the same as using a column major ordering (setf bar (order e pos :slices slices :copy? T :order :column)) (print-slices bar slices :row) ;;; Same slices, same permutation, just depends on whether ;;; we number the original slices 0 to (- (number-of-slices e '(0 1)) 1) ;;; in row or column major order. ;;; Occasionally these will yield the same results. ;;; For an example, (setf pos2 '(5 4 3 2 1 0)) (setf far (order e pos2 :slices slices :copy? T :order :row)) (setf boo (order e pos2 :slices slices :copy? T :order :column)) (print-slices far slices :row) (print-slices boo slices :row) ;;; Pen and paper exercise: Show why :row and :column must yield ;;; the same results in this case. ;;;;;;;;;;;;;;;;;; ;;; ;;; Of course we needn't use order in conjuction with order ;;; to permute slices. permute has been written more generally ;;; to permute slices randomly. ;;; ;;; PERMUTE randomly permutes the elements or slices of object. ;;; It has one required argument: the refable object to be permuted. ;;; And it accepts the keywords :slices :copy? and :type ;;; which are interpreted just as in sort. ;;; slices --- index or list of indices identifying the fixed ;;; dimensions of each slice. ;;; Default :elements. ;;; copy? --- Destructive permutation if NIL, permutes a copy otherwise. ;;; Default is NIL. ;;; type --- :exterior if slices are to be permuted randomly ;;; :interior if the contents of slices are to be ;;; randomly permuted. ;;; Default is :exterior ;;; ;;; ;;; Extending permute: The generic function permute-object which ;;; destructively permutes would need to be specialized for ;;; new data structures. ;;; It has three required args: object slices type. ;;; ;;; a (permute a) a ;;; ;;; permute the columns of a copy of a ;;; a (permute a :slices 1 :type :exterior :copy? T) ;;; ;;; permute the rows of a copy of a ;;; a (permute a :slices 0 :type :exterior :copy? T) ;;; ;;; permute the elements of the rows of a copy of a ;;; a (permute a :slices 0 :type :interior :copy? T) ;;; ;;; The following makes no pemutation because of the :interior ;;; permutation type when the elements have no structure. ;;; (permute a :slices :elements :type :interior :copy? T) ;;; ;;; Whereas an :exterior does permute ;;; (permute a :slices :elements :type :exterior :copy? T) ;;; ;;; Compare the preceding two examples ;;; to the following case. (setf foo (list a b)) (permute foo :slices :elements :type :exterior :copy? T) (permute foo :slices :elements :type :interior :copy? T) ;;; Note that the interior permutation was destructive. a ;;; ;;; permute the row-slices of a copy of e ;;; e (permute e :slices '(0) :type :exterior :copy? T) ;;; ;;; permute the rows of a copy of e ;;; e
17,334
Common Lisp
.l
462
33.311688
92
0.606698
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d27f156bde3930388d3456f1db91fae6af23b6e9350a151f2b78e0824bb2217a
33,025
[ -1 ]
33,026
glue.lsp
rwoldford_Quail/examples/arrays/glue.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Putting arrays together ;;; ;;; ;;; Authors: ;;; D.G. Anglin 1994. (in-package :quail-user) (setf a (array '((1.2 3 4.5) (6.7 8.9 0.1)) :dimensions '(2 3))) (setf b (vector 100 200)) (setf c (array 7 :dimensions '(2 2))) ;;;---------------------------------------------------------------------------- ;;; cglue glues objects with conformable columns together ;;; here a has columns of height 2, and the 1d objects b are treated as columns (cglue a b) (cglue 1 2 3) (cglue '(1 2) b c) ;; (cglue a 1) ;; an error (cglue a (array 1 :dimensions 2)) (cglue b c) ;;; rglue glues objects with conformable columns together ;;; here, by default, 1d objects are treated as rows (rglue 1 2 3) (rglue '(1 2) b c) (rglue (array "foo" :deconstruct t) a) ;; note that the return class is ref-array ;;; It *is* possible to override the default treatment of 1d objects (setf cc (ref c T 1)) (rglue '(1 2) cc) (rglue '(1 2) cc :1d :col) (cglue '(1 2) cc) (cglue '(1 2) cc :1d :row) ;;;---------------------------------------------------------------------------- ;;; There is a generalization called glue. Objects can be glued together along ;;; a given axis if the dimensions-of each object, with that axis removed, ;;; match exactly. In the following example, d and e can be glued along axis 1, ;;; since the other axes match in length. (setf d (array 1 :dimensions '(2 2 4))) (setf e (array 2 :dimensions '(2 3 4))) (setf f (glue d e :at 1)) (dimensions-of f) ;;; The axis to attempt defaults to 0, hence the following bombs ... (glue d e) ;; an error
1,718
Common Lisp
.l
43
36.372093
83
0.565619
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ee913ed1c47d5fb6219c706905e09b2028a52fcf22e9622d3b19bdf7f0e7f71f
33,026
[ -1 ]
33,027
overview.lsp
rwoldford_Quail/examples/arrays/overview.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Overview of array manipulation functions ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; There is a lot of material to be covered about array manipulation ;;; in Quail so that the examples are split up into a number of topic files. ;;; A not unreasonable tutorial would be to browse the files in order. ;;; ;;; Here we outline the contents of those files and offer a form to ;;; evaluate that will bring each example file up as desired. ;;; (in-package :quail-user) ;;; Topic Major Functions ;;; ;;; Introduction to array creation ... array ;;; array attributes ... dimensions-of ;;; number-of-dimensions ;;; number-of-elements array element access ... eref ;;; setting array elements ... (setf eref) (edit-file "eg:Arrays;intro.lsp") ;;; Some handy arrays ... ones-array, seq, iseq ;;; diagonal, diagonal-of ;;; identity-matrix, ;;; upper-triangle-of (edit-file "eg:Arrays;handy-arrays.lsp") ;;; ;;; Referencing blocks within arrays ... ref ;;; Copying blocks within arrays ... sel ;;; Setting blocks within arrays ... (setf ref), (setf sel) (edit-file "eg:Arrays;ref.lsp") ;;; ;;; Advanced array creation ... array & its keywords (edit-file "eg:Arrays;array.lsp") ;;; ;;; Basic mathematical operations ... + - * / .* ;;; min, max, tp (edit-file "eg:Arrays;arith-ops.lsp") ;;; ;;; Other Mathematical functions ... expt log exp sin cos ;;; atanh ... etc. (edit-file "eg:Arrays;math-funs.lsp") ;;; ;;; Testing by numerical predicates ... =, <, <=, >, >= ;;; equals-object, ;;; less-than-object, ;;; less-than-equals-object, ;;; greater-than-object, ;;; greater-than-equals-object, ;;; test-elements (edit-file "eg:Arrays;num-preds.lsp") ;;; ;;; Selecting elements by predicate ... indices, ref-if (edit-file "eg:Arrays;select-by-pred.lsp") ;;; ;;; Putting arrays together ... cglue, rglue, glue (edit-file "eg:Arrays;glue.lsp") ;;; ;;; Sorting, ranking, etc. ... sort, sort-object ;;; sort-position ;;; ranks ;;; order ;;; permute, permute-object (edit-file "eg:Arrays;sort.lsp") ;;; ;;; ;;; Iteration introduction ... loop, dotimes, dolist (edit-file "eg:Arrays;iter-general.lsp") ;;; ;;; General Iteration over elements ... column-major-eref ;;; row-major-eref ;;; number-of-slices ;;; column-major-ref-slice ;;; row-major-ref-slice ;;; column-major-list-elements ;;; row-major-list-elements ;;; column-major-set-elements ;;; row-major-set-elements (edit-file "eg:Arrays;iter-elements.lsp") ;;; ;;; Simple iteration macros for slices ... doslices, collect-slices (edit-file "eg:Arrays;iter-slices.lsp") ;;; ;;; ;;; Mapping functions map-element ;;; map-slices ;;; reduce-slices ;;; collapse ;;; sweep (edit-file "eg:Arrays;iter-map.lsp") ;;; ;;; Searching ref-objects ... find-slices, find-slices-if ;;; count-slices, count-slices-if ;;; slice-positions ;;; slice-positions-if (edit-file "eg:Arrays;search.lsp") ;;; ;;; Modifying ref-objects ... remove-slices ;;; remove-slices-if ;;; substitute-slices ;;; substitute-slices-if ;;; replace-slices (edit-file "eg:Arrays;iter-modify.lsp") ;;; ;;; Focus on matrices ... rank-of, trace-of ;;; determinant, inverse, ;;; condition-number-of, ;;; singular-values-of, ;;; solve, ;;; decompositions, (edit-file "eg:Arrays;Matrices;overview.lsp")
6,359
Common Lisp
.l
120
49.791667
130
0.361373
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dcaa8461c5440d4d949809990b26cbf25c8002de94ee575eabe7de8b25468674
33,027
[ -1 ]
33,028
math-funs.lsp
rwoldford_Quail/examples/arrays/math-funs.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Mathematical functions ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. (in-package :quail-user) (setf a (array '((1.2 3 4.5) (6.7 8.9 0.1)) :dimensions '(2 3))) ;;; ;;; In addition to the usual arithmetic operators ;;; All of the Common-Lisp mathematical functions have been extended ;;; to work on arrays. ;;; One notable exception is boole ;;; ;;; The functions which have been extended may be on the following symbols: *logical-numerical-ops* *numerical-type-coercion-functions* *extended-simple-functions* ;;; ;;; The functions listed on these symbols are as described in ;;; the Common Lisp Manual. They now take arrays and lists as arguments ;;; as well. ;;; ;;; Some examples (loop for fn in *logical-numerical-ops* do (format *terminal-io* "~&(~s ....)" fn)) (<- x (array '(0 0 1 1))) (<- y (array '(0 1 0 1))) (logior x y) (logxor x y) (logand x y) (logeqv x y) (lognand x y) (lognor x y) (logandc1 x y) (logandc2 x y) (logorc1 x y) (logorc2 x y) (lognot x) (logtest x y) (logbitp x y) (ash x y) (logcount x) (integer-length x) (loop for fn in *numerical-type-coercion-functions* do (format *terminal-io* "~&(~s a)" fn)) (float a) (rational a) (rationalize a) (complex a) (loop for fn in *extended-simple-functions* do (format *terminal-io* "~&(~s a)" fn)) (exp a) (sqrt a) (isqrt (ceiling a)) (abs (- a)) (phase a) (signum a) (sin a) (cos a) (tan a) (cis a) (asin a) (acos a) (atan a) (sinh a) (cosh a) (tanh a) (asinh a) (acosh a) (atanh a) (numerator (rationalize a)) (denominator (rationalize a)) (realpart (complex a)) (imagpart a) (floor a) (ceiling a) (truncate a) (round a) (ffloor a) (fceiling a) (ftruncate a) (fround a) (expt a a) (log a) (rem a a) (mod a 1) (gcd (floor a) (ceiling a)) (lcm (floor a) (ceiling a)) (conjugate (sqrt (- a)))
2,082
Common Lisp
.l
92
19.771739
76
0.588992
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
92814e3336d05b7d5238c838f88581b47375beb5bc6bbe6992b9fd27700bab9c
33,028
[ -1 ]
33,029
inverse-test.lsp
rwoldford_Quail/examples/arrays/matrices/inverse-test.lsp
(<- n 3) (<- iden (identity-matrix n)) (defun print-mat (mat) (let* ((dims (dimensions-of mat)) (dim-1 (first dims)) (dim-2 (second dims))) (loop for i from 0 below dim-1 do (format *terminal-io* "~&~%Row ~s~&~5T" i) (loop for j from 0 below dim-2 do (format *terminal-io* " ~s" (eref mat i j)) ) ))) (print-mat iden) (setf i2 (ref iden '(0 1) '(0 1))) (print-mat i2) (ref i2 0 1) (setf i~0 (ref iden '(:c 0) '(:c 0))) (print-mat i~0) (setf not-square (ref iden T '(:c 0))) (class-of not-square) (print-mat not-square) (ref iden) (setf si (sel iden)) si (print-mat si) (setf si (sel iden '(0 1) '(0 1))) (print-mat si) (setf si (sel iden '(:c 0 1) '(1) )) (print-mat si) (setf si (sel iden '(:c 0 1) '(0 1) :shape t)) (print-mat si) (setf si (sel iden '(0) '(0 1) :shape t)) (inspect si) (print-mat si) (inspect iden) (ref iden T '(:c 0)) (setf ri (ref iden)) (sel iden) (sel ri) (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2))) (<- xtx (.* (tp x) x)) (<- y (+ (.* X (array '(5 7))) (random-gaussian :n 3 :scale .1))) (<- xty (.* (tp x) y)) (<- ixtx (inverse xtx)) (inspect ixtx) (.* ixtx xtx) (slot-value ixtx 'q::inverse-object) (slot-value xtx 'q::inverse-object) (eref xtx 0 0) (eref ixtx 0 0) ;; problem is that lu-of makes a copy of the inverse-matrix first inside ;; calculate-inverse (step (eref ixtx 0 0)) (force-evaluation ixtx) (trace force-evaluation change-class sel eref ref)
1,622
Common Lisp
.l
59
22.576271
73
0.543803
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b59fde5eddc4c6c91b44d92d4238dca88cfc476a67d85ad8375dba9a548172e5
33,029
[ -1 ]
33,030
intro.lsp
rwoldford_Quail/examples/arrays/matrices/intro.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Matrix introduction ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; Contents: ;;; ;;; 1. Matrix introduction. ;;; 1.1 Matrix constructors ;;; - array, diagonal, identity-matrix, ones, seq ;;; 1.2 Matrix selectors ;;; - eref, ref, and sel. ;;; - diagonal-of, upper-triangle-of ;;; 1.3 Matrix dimensions. ;;; - dimensions-of, nrows, ncols, matrix-dimensions-of, ;;; number-of-elements ;;; 1.3.1 One dimensional matrices. ;;; 1.3.2 Zero dimensional matrices. ;;; ;;; To go directly to any of these, just search this file for the topic of ;;; of interest or to go section by section search for \section \subsection ;;; or \subsubsection. ;;; However, please note that some results will depend on ;;; having executed other forms earlier in the file. ;;; ;;; See also the matrix overview: (edit-file "eg:Arrays;Matrices;overview.lsp") ;;; See also to the array overview: (edit-file "eg:Arrays;overview.lsp") ;;; ;;; \section 1. Matrix introduction. ;;; ;;; Matrices in Quail are just Quail arrays having 2 or fewer dimensions ;;; and numerical elements. As such any function that is applicable to ;;; a general array is also applicable to a matrix. ;;; They are implemented as a class matrix. ;;; ;;; In this section, we give a brief introduction to the basic use of matrices. ;;; ;;; \subsection 1.1 Matrix constructors. ;;; ;;; There are many functions that can be used to construct a matrix. ;;; The most common and most general is the array function. ;;; It can be used to construct arrays of arbitrary dimensions and contents and ;;; is discussed at greater length in the introduction to arrays contained in (edit-file "eg:Arrays;intro.lsp") ;;; Here we illustrate only rather basic usage. ;;; For example here is a 3 by 2 matrix x (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2))) ;;; whose contents you can see by evaluating x ;;; The first argument to array is the contents argument. ;;; This is a list or other ref'able structure whose ;;; elements are to be stored as the contents of the array. ;;; The dimensions of the array are determined by the value of the keyword ;;; argument of that name. If missing, the default is determined from the ;;; structure of the contents argument. So the matrix x could also have ;;; been constructed as (<- x (array '((1 2) (3 4) (5 6)) )) ;;; A number of other keywords exist for the array function. ;;; ;;; Here we note only that the order by which the elements of x are filled ;;; can be changed through the value of the keyword argument fill. ;;; By default x is filled by row. If column-wise order was desired one ;;; need only pass array :column as the value of its keyword argument :fill. (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2) :fill :column)) ;;; with the result x ;;; A number of matrices and matrix types crop up frequently enough that it ;;; is convenient to have special constructors to produce them. ;;; A general treatment of these is given in (edit-file "eg:Arrays;handy-arrays") ;;; Here we quickly illustrate their use in constructing matrices. ;;; ;;; The first is a diagonal matrix (i.e. having zero above- and below-diagonal ;;; elements). For this we have the constructor diagonal, as in (diagonal '(1 2 3 4)) ;;; or (diagonal '(1 1 1 1)) ;;; This last case is really a 4 by 4 identity matrix and could be constructed ;;; instead using (identity-matrix 4) ;;; In this case however, it returns a genuine identity-matrix object rather ;;; than an instance of a matrix whose contents are numerically equal to those ;;; of an identity matrix. ;;; The distinction allows storage to be minimized for large identity-matrices ;;; and also makes possible methods which are specialized to work with identity ;;; matrices. ;;; ;;; Similarly, a 3 by 2 matrix of ones can be produced as (ones 3 2) ;;; Despite its printed representation, this returns an instance of the class ;;; ones-matrix. (<- ones (ones 3 2)) (class-of ones) ;;; ;;; Matrices whose contents are to be a regular sequence of numbers can ;;; be constructed using the function seq. As in (seq 1 5) (seq -10 -5) (seq -10 -15) (seq 1 2 .1) ;;; ;;; Finally, array is clever enough to use pretty much any ref'able object ;;; as its' initial contents. (array (seq 1 24) :dimensions '(8 3)) (array (identity-matrix 4) :dimensions '(16 1)) (array (random-uniform :n 16) :dimensions '(4 4)) ;;; \subsection 1.2 Matrix selectors ;;; - eref, ref, and sel. ;;; - diagonal-of, upper-triangle-of ;;; ;;; Matrix elements are selected as with any Quail array, by using eref ;;; (as a mnemonic device, consider it short for ``element-reference'') ;;; All indexing is zero-based. So for x, we have (eref x i j) ;;; selecting the (i,j)'th element of x. As in (eref x 0 0) (eref x 0 1) (eref x 1 0) (eref x 1 1) (eref x 2 0) (eref x 2 1) ;;; Similarly, referencing and copying whole blocks of a matrix use ;;; the generic array functions ref (for ``reference'') and sel (for ``select'') ;;; as referencing the top 2 by 2 block of X in any of the followinf equivalent ;;; ways: (ref x '(0 1) '(0 1)) (ref x '(0 1) T) (ref x '(0 1) ) (ref x '(:c 2) '(0 1)) (ref x '(:c 2) T) (ref x '(:c 2) ) ;;; Rows, columns, can be repeated as in (ref x '(0 0 0) T) (ref x '(0 1 0) '(0 0 1)) ;;; Replacing ``ref'' by ``sel'' in any of these statements produces a copy ;;; of the block structure but which contains the identical elements. ;;; The principal difference is that changing the contents of a cell ;;; in a reference causes the contents of the corresponding cell of the ;;; original object to change to the same thing. ;;; If the change is made to a cell in a copy of the matrix, then the change does ;;; not get reflected in the original. ;;; ;;; For greater discussion, see (edit-file "eg:Arrays;intro.lsp") ;;; and (edit-file "eg:Arrays;ref.lsp") ;;; Besides the element extraction function, eref, and the whole block ;;; extraction functions, ref and sel, ;;; one often wants the upper triangle of a matrix, as an upper triangular matrix, ;;; or perhaps just its diagonal elements. ;;; So for convenience, Quail also provides the functions upper-triangle-of, ;;; and diagonal-of as shown below. (upper-triangle-of x) ;;; Note the zero below the diagonal. ;;; The diagonal is extracted as (diagonal-of x) ;;; and is sometimes used in conjunction with the ``diagonal'' constructor ;;; to produce a diagonal matrix from the diagonal of another matrix as in (diagonal (diagonal-of x)) ;;; Note that both upper-triangle-of and diagonal-of operates on ;;; matrices of arbitrary shape. ;;; ;;; ;;; \subsection 1.3 Matrix dimensions. ;;; ;;; There are a number of functions for asking about the size of the matrix. ;;; All of them relate ultimately to the dimensions of the matrix. ;;; For our matrix x, we have (dimensions-of x) ;;; which means a matrix having (nrows x) ;;; rows and (ncols x) ;;; columns and (number-of-elements x) ;;; elements. ;;; ;;; Matrices can have 0, 1, or 2 dimensions representing scalars, column vectors, ;;; and general matrices respectively. (number-of-dimensions x) ;;; Each of these are printed slightly differently from each other and from more ;;; general arrays. ;;; ;;; The original matrix x is an example of a two dimensional matrix. ;;; Any reference of it that preserves shape will also be two dimensional: (ref x '(0 1) T) (ref x 0 T :shape T) (ref x T 0 :shape T) (ref x 0 0 :shape T) ;;; ;;; \subsubsection 1.3.1 One dimensional matrices. ;;; ;;; For an example of a 1 dimensional matrix, consider column 0 of x (<- 1d-x (ref x T 0)) (number-of-dimensions 1d-x) ;;; Its' single dimension is reflected in its printed representation. 1d-x (dimensions-of 1d-x) (nrows 1d-x) (ncols 1d-x) ;;; The following always treats the argument as if it were a matrix (matrix-dimensions-of 1d-x) ;;; NOTE: All single dimensioned matrices are assumed to be column vectors. ;;; So referencing row 0 of x will also return a column vector! (<- 1d-x (ref x 0 T)) 1d-x (number-of-dimensions 1d-x) (dimensions-of 1d-x) (nrows 1d-x) (ncols 1d-x) (matrix-dimensions-of 1d-x) ;;; Had we wanted to preserve the row shape, the call to ref would ;;; include :shape T. ;;; Of course the transpose of an n by 1 column vector will always be ;;; a 1 by n matrix. (tp 1d-x) ;;; ;;; \subsubsection 1.3.2 Zero dimensional matrices. ;;; ;;; Occasionally a zero dimensional matrix is constructed. ;;; This usually happens by referencing a single element of a matrix ;;; via ref or sel. For our example here, we will consider using sel ;;; so that we obtain a copy of a piece of x rather than a reference to it. ;;; \footnote{Sel is exactly like ref except that sel makes a copy and drops ;;; the pointer to the original data structure.} ;;; Then when we later set the value, we will do so without disrupting the ;;; original x or any other reference to it. ;;; ;;; Here's a 0-dimensional matrix, (<- 0d-x (sel x 0 0)) (number-of-dimensions 0d-x) (dimensions-of 0d-x) (nrows 0d-x) (ncols 0d-x) (matrix-dimensions-of 0d-x) ;;; Conceptually the result is a scalar and so has zero (i.e. NIL) dimensions. ;;; However it is distinct from the true scalar obtained by directly accessing ;;; the 0 0 element of x through eref. (<- x00 (eref x 0 0)) x00 ;;; They are different objects (eq x00 0d-x) ;;; but because zero-dimensional objects are treated as scalars (= x00 0d-x) (> x00 0d-x) (< x00 0d-x) (>= x00 0d-x) (<= x00 0d-x) ;;; An important consequence of this difference is that 0d-x can be regarded as a ;;; container whose contents can be changed whereas x00 cannot. ;;; For example, any of (<- (eref 0d-x) 100) ;; as a zero dimensional matrix, (<- (eref 0d-x 0) 100) ;; as a one dimensional matrix, (<- (eref 0d-x 0 0) 100) ;; or as a two dimensional matrix, ;;; will work but the same forms with x00 in place of 0d-x will result in error. ;;; Note that had we used ref instead of sel in constructing x00, these assignments ;;; would have changed the corresponding element in x as well. ;;; This is why we chose to make 0d-x a copy of part of x rather than a reference to ;;; it. ;;; ;;; Some functions (particularly foreign functions that call Fortran or C) return the ;;; results by changing the contents of arrays passed as arguments. ;;; In such cases, passing the element x00 would fail whereas passing the ``container'' ;;; 0d-x would be just right. ;;; ;;; A simpler illustration of the difference is the case where some structure ;;; maintains a pointer to the value of both x00 and 0d-x. ;;; Suppose we have a list l that points to both values, as in (<- some-list (list x00 0d-x)) some-list ;;; 0d-x would normally be changed by (<- (eref 0d-x) 222222222) ;;; and the true scalar x00 by (<- x00 111111111) ;;; Only the second element of l will contain the updated info some-list ;;; and so will be different from
11,771
Common Lisp
.l
289
37.743945
88
0.674805
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
444490bfd618e1d264470fa770d66975c54de0a92958cfc20bb61c7fef7c1934
33,030
[ -1 ]
33,031
operations.lsp
rwoldford_Quail/examples/arrays/matrices/operations.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Matrix operations ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; Contents: ;;; ;;; 2. Matrix operations. ;;; First consider selected operations that result from matrices ;;; being special kinds of Quail ref-arrays. ;;; These are the n-ary arithmetic operators, various ;;; common mathematical unary and binary operations, ;;; and numerical predicates. ;;; ;;; 2.1 Matrix specific operations. ;;; ;;; 2.1.1 Matrix multiplication. .* ;;; 2.1.2 Solving systems of linear equations ;;; 2.1.3 Matrix inversion ;;; ;;; 2.2 Numerical properties ;;; ... rank-of, condition-number-of, determinant, ;;; trace-of ;;; ;;; 2.2.1 Numerical ranks ;;; 2.2.2 Condition numbers ;;; 2.2.3 Determinant ;;; 2.2.4 Trace ;;; 2.2.5 Selected algebraic structure ;;; ;;; ;;; To go directly to any of these, just search this file for the topic of ;;; of interest or to go section by section search for \section \subsection ;;; or \subsubsection. ;;; However, please note that some results will depend on ;;; having executed other forms earlier in the file. ;;; ;;; To get to the matrix overview: (edit-file "eg:Arrays;Matrices;overview.lsp") ;;; To get to the array overview: (edit-file "eg:Arrays;overview.lsp") ;;; First we need a matrix x. (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2))) x ;;; ;;; \Section 2. Matrix operations. ;;; ;;; Here we consider selected operations that result from matrices ;;; being special kinds of Quail ref-arrays. ;;; These are the n-ary arithmetic operators, and various ;;; common mathematical unary and binary operations. ;;; ;;; All of the functions that can be used with arrays can also ;;; be used with a matrix x. Some examples typically expected ;;; of a matrix are its' transpose (tp x) ;;; and element-wise arithmetic (+ x x x) (- x x x) (/ x x x) (* x x x) (* 2 x) ;;; For these operations to work the dimensions of the arguments must conform. ;;; For example, (+ (tp x) x) will fail. ;;; ;;; If however one of the arguments is a scalar or a 0-dimensional matrix, ;;; the operation will apply to all conformable arguments equally. (+ x 999999 x) (+ x (ref x 0 0) x) ;;; And so on for the other n-ary operators -, *, and /. ;;; ;;; This also holds for 1-dimensional matrices. Here are two. (<- col-x (+ '(10000 20000 30000) (ref x T 0))) col-x (<- row-x (+ '(10 20) (ref x 0 T))) row-x ;;; Adding col-x to x results in it being added to every column of x. (+ x col-x) (+ col-x x) ;;; Adding row-x to x results in it being added to every row of x. (+ x row-x) (+ row-x x) ;;; And this works for two-dimensional matrices when one of the dimensions ;;; is 1. (+ (tp row-x) x) (+ x (tp row-x)) ;;; When one of the dimensions is 1 (nrows or ncols is 1), then some effort is ;;; made to match the remaining dimension with one of the dimensions of the ;;; other argument and operate over rows or columns accordingly. ;;; ;;; If we have ncols=nrows on the two dimensional argument then some ambiguity ;;; arises and we have arbitrarily selected column-major order. (<- square-x (array '(1 2 3 4 5 6 7 8 9) :dimensions '(3 3))) square-x (+ square-x col-x) (+ col-x square-x) (+ (tp col-x) square-x) (+ square-x (tp col-x)) ;;; NOTE: When more than two arguments are given, arithmetic operations occur ;;; in binary fashion proceeding left to right. As a consequence ;;; (aside from numerical considerations) the arithmetic operations are no ;;; longer associative when operating on matrices of which some are two ;;; dimensional and some are one dimensional. ;;; For example, (+ x col-x row-x) ;;; and (+ col-x x row-x) ;;; are equivalent but (+ col-x row-x x) will fail because (+ col-x row-x) will. ;;; If you are keen to do something different you can take matters into your ;;; own hands for element-wise operations by calling map-element directly. ;;; This will allow you to specify an order. ;;; ;;; ;;; All of Common Lisp's mathematical functions have been extended to operate ;;; on arrays in general. These are described in more detail in (edit-file "eg:Arrays;math-funs.lsp") ;;; Some examples are (* 2 x) (* x x) (/ 2 x) (log x) (log x 10) ;;; take care here not to have a base 1 log calculated. (log x (+ x 10)) (exp x) (cos x) (expt x 3) (expt x x) (sqrt x) (mod x 2) (mod x x) ;;; and so on. ;;; ;;; ;;; Similarly, numerical predicates have been extended for Quail arrays, ;;; and hence for matrices. (= x x x) (> x 3) (>= (expt x 2) x) (< x 3) (<= (expt x 2) x) ;;; For more detail, see (edit-file "eg:Arrays;num-preds.lsp") ;;; In fact, anything that operates on Quail arrays also operates on matrices. ;;; For the whole ball of wax, see (edit-file "eg:Arrays;overview.lsp") ;;; \subsection 2.1 Matrix specific operations. ;;; ;;; Besides the usual mathematical operations inherited from numerical arrays, ;;; there are a few that are peculiar to matrices. ;;; Here we examine ;;; ... Dot product for matrix multiplication: .* ;;; ... Solving linear systems of equations: solve ;;; ... Matrix inverses ;;; ;;; \subsubsection 2.1.1 Matrix multiplication. ;;; ;;; In Quail the matrix multiplication operator is the ``dot-product'' ;;; operator .* ;;; It takes arbitrarily many arguments. ;;; T ;;; For example, we determine the matrix product X X as (<- xtx (.* (tp x) x)) ;;; T ;;; and XX as (<- xxt (.* x (tp x))) ;;; Again the number of arguments is arbitrary provided the dimensions conform (.* x) (.* xxt x xtx) (.* xxt (seq 1 3)) ;;; Note that the conformability is strictly determined from the dimensions ;;; of the arguments. ;;; For example, because lists are treated as column vectors this will work (.* xxt '(1 2 3)) ;;; but (.* '(1 2 3) x) would fail. To get the dimensions right transpose the ;;; list first (.* (tp '(1 2 3)) x) ;;; It is important to remember that ref will collapse any empty dimensions ;;; and so will return a column vector when a row vector might be expected. (<- x0 (ref x 0 T)) (matrix-dimensions-of x0) ;;; So (.* x0 '(100 200)) will fail but (.* (tp x0) '(100 200)) ;;; will not. The better solution would be to have ref preserve the empty ;;; dimensions as in (<- row-0 (ref x 0 T :shape T)) (.* row-0 '(100 200)) ;;; ;;; Similarly scalars are treated as 1 by 1 matrices (.* '(1 2 3) 100 (ref x 1 1)) ;;; \subsubsection 2.1.2 Solving systems of linear equations ;;; ;;; Consider solving a system of linear equations, say the ``normal equations'' ;;; from a least-squares linear regression. ;;; That is for fixed n by p matrix X and n by 1 vector Y, we solve the ;;; following matrix equation for the unknown p by 1 vector b. ;;; ;;; T T ;;; X X b = X Y ;;; ;;; T ;;; Here's X X (<- xtx (.* (tp x) x)) ;;; ;;; And suppose y is in fact linearly related to X (<- trueb (array '(5 7))) (<- y (+ (.* X trueb) (random-gaussian :n 3 :scale .1))) ;;; T ;;; The final ingredient is X Y ;;; (<- xty (.* (tp x) y)) ;;; ;;; And to solve for b ;;; (solve xtx xty) ;;; which should have values close to the original vector ;;; used above to create y. ;;; ;;; Another way of solving this system would be to make use of any of a ;;; variety of matrix decompositions. First decompose X (e.g. via QR) or ;;; XTX (e.g. via Cholesky) and call solve on the resulting decomposition ;;; with second argument y or XTy respectively. ;;; Solve will work with most decompositions. ;;; ;;; In keeping with many statistical systems, the second argument to ;;; solve is optional. ;;; If the second argument is NIL or an identity-matrix, ;;; solve returns the matrix inverse of its' first argument. (<- xtx-inv (solve xtx NIL)) ;;; or (solve xtx (identity-matrix (nrows xtx))) ;;; In either case, this is done by calling the function inverse directly ;;; on xtx. ;;; Then the normal equations could be solved equivalently (in Quail, see ;;; following section on inverse) as ;;; (.* xtx-inv xty) ;;; \subsubsection 2.1.3 Matrix inversion ;;; ;;; To invert a square matrix the inverse function is used as in (<- i-xtx (inverse xtx)) ;;; Note that the inverse is not calculated explicitly, until needed. ;;; Instead inverse is a generic function which when called on an square ;;; matrix returns an instance of ``inverse-matrix''. This instance maintains ;;; a pointer to the original matrix so that calling inverse again will ;;; return the original matrix as in (eq xtx (inverse i-xtx)) ;;; and so we also have information to determine that (.* i-xtx xtx) ;;; must yield an identity matrix exactly! ;;; ;;; But note that the inverse is not cached on xtx (eq (inverse xtx) i-xtx) ;;; This way if xtx changes, and the inverse is asked for again, the correct ;;; result will be obtained. ;;; ;;; Only if the user actually wants to see or use the elements of the inverse ;;; matrix is it ever calculated explicitly and stored; even then, these values ;;; will never be used in a matrix multiplication. Instead, matrix multiplication ;;; of an inverse-matrix and a second matrix will call the solve function on the ;;; original matrix and the second matrix. ;;; ;;; Should it at any time be desirable to have the inverse explicitly, one need ;;; only get a copy in the usual way using sel (<- explicit-inv (sel i-xtx)) ;;; ;;; Quail employs the general strategy that where possible any operation performed ;;; on an inverse matrix which is mathematically equivalent to performing another ;;; operation on the original matrix and then inverting the result, the latter ;;; is chosen as the computational strategy. ;;; ;;; To illustrate these points, consider two square full-rank matrices A and B. (<- a (array (random-gaussian :n 4) :dimensions '(2 2))) (<- b (array (random-gaussian :n 4) :dimensions '(2 2))) ;;; -1 -1 ;;; and their inverses A and B respectively. (<- ia (inverse a)) (<- ib (inverse b)) ;;; ;;; Then mathematically we have: ;;; ;;; -1 -1 -1 ;;; A B = (BA) ;;; (- (.* ia ib) (inverse (.* b a))) ;;; which is exact because the operations are now computationally equivalent. ;;; ;;; This was possible because the inverse function caches the matrix it inverted. ;;; The calculation also benefits by suppressing the matrix inverse operation ;;; until last. The left hand side involves 2 calls to the solve ;;; function and one call to a matrix multiply whereas the right hand side involves ;;; only a single call to the solve function plus the single matrix multiply. ;;; ;;; ;;; ;;; Note on numerical stability: ;;; ;;; In most systems, the following route to the solution of the linear system ;;; is to be strictly avoided because of numerical problems. (<- b-hat (.* (inverse xtx) xty)) ;;; This is because explicitly producing a matrix inverse and then multiplying ;;; it by the vector x to get the solution is numerically unreliable for an ;;; ill-conditioned system of equations. ;;; ;;; Because the inverse is calculated only implicitly, the problem does not arise. ;;; When it comes time to do some matrix multiplication with it, ;;; the solve function is used as demanded for numerical stability. ;;; ;;; So the above solution to the normal equations will yield a solution ;;; numerically identical to that obtained earlier by (solve xtx xty). ;;; Compare this to the numerically undesirable approach (.* explicit-inv xty) ;;; which will in general be different from b-hat. ;;; ;;; It should also be noted that some small differences due to the order of ;;; operations will be obtained if we calculate b-hat directly as the mathematics ;;; would have us do (.* (inverse (.* (tp x) x)) (tp x) y) ;;; These differences are here primarily because .* has called the function solve ;;; on i-xtx and (tp X) rather than on i-xtx and xty. ;;; Like most operations, mathematically associative ;;; operators like .* are not computationally associative. ;;; ;;; When solve is given a null second argument it simply calls inverse ;;; on its first argument, as in (<- i-xtx (inverse xtx)) ;;; ;;; \subsection 2.2 Numerical properties ;;; ;;; Here we describe some functions that determine numerical ;;; properties of matrices. ;;; These are rank-of, condition-number-of, determinant, and trace-of. ;;; Some of these are defined only for square matrices so in addition to ;;; the original matrix X, we will use some square ones defined in the previous ;;; section. ;;; ;;; ;;; \subsubsection 2.2.1 Numerical ranks ;;; ;;; The numerical rank of a matrix is an assessment of the number of ;;; linearly independent rows or columns in that matrix. ;;; It is defined to be the number of non-zero singular values in the matrix, ;;; or more precisely, the number of values above some non-negative threshold. ;;; ;;; Our original matrix x has dimensions (dimensions-of x) ;;; and full column rank. That is, its' rank is the same as its' number of ;;; columns. (rank-of x) ;;; T ;;; Now XX will have the same mathematical rank as X but possibly not the ;;; same numerical rank (rank-of xxt) ;;; Any difference will be due to the floating point errors involved ;;; in calculation (either of xxt, none here, or of its rank). ;;; If we examine the singular values of xxt (singular-values-of xxt) ;;; we see that one is extremely small. Mathematically, it must be zero. ;;; A tolerance for zero can be given as a keyword argument to rank-of, as ;;; in (rank-of xxt :tolerance 1E-10) ;;; which in this case should produce the mathematically correct rank. ;;; ;;; ;;; \subsubsection 2.2.2 Condition numbers. ;;; ;;; Any n by p matrix that has rank less than the min(n,p) is said ;;; to be singular and at least one of its' singular values will mathematically ;;; be exactly zero. ;;; A numerical measure of that singularity is the ratio of the largest ;;; to the smallest singular values. This is called the condition number ;;; of the matrix and for non-zero real matrices lies between 0 and infinity. ;;; ;;; Many bounds on the error of floating point calculations are proportional ;;; to the condition number so it is desirable that it be small. For some ;;; applications, this might mean less than 30 for a column scaled matrix. ;;; ;;; In Quail, the condition number is given as (condition-number-of x) (condition-number-of xxt) ;;; And here we see that x is not too badly ``conditioned'' but that ;;; xxt is extremely ``ill-conditioned'' and hence xxt is numerically ;;; near singular. ;;; ;;; For further discussion of the condition number, see ;;; Golub and Van Loan ``Matrix Computations'' for numerical properties ;;; and Belsley ``Conditioning Diagnostics'' for statistical diagnostic uses. ;;; ;;; \subsubsection 2.2.3 Determinant ;;; ;;; The determinant of a square matrix is (determinant xtx) (determinant xxt) ;;; ;;; \subsubsection 2.2.4 Trace ;;; ;;; The trace of a square matrix is simply the sum of its diagonal elements. (trace-of xtx) ;;; Because it is mathematically invariant to cyclic permutations of the ;;; arguments of a matrix product, up to rounding error, the following should ;;; produce the same result: (trace-of xxt) ;;; A more general trace operator might be written as (defun my-trace-of (x) "A general trace that operates on any rectangular matrix x." (sum (diagonal-of x))) (my-trace-of x) (my-trace-of xxt) ;;; ;;; \subsubsection 2.2.5 Selected algebraic structure. ;;; ;;; We have already seen the computation of singular values. ;;; Other functions that are applicable to the decomposition of the matrix ;;; are sometimes directly available from the matrix. Singular-values-of ;;; is one such function. Other functions available on a matrix from its ;;; singular value decomposition ;;; T ;;; X = U D V ;;; ;;; are the (left-singular-vectors-of x) ;;; or the matrix U, and (right-singular-vectors-of x) ;;; or the matrix V. ;;; ;;; To check, X can be put back together from this structure as (<- x2 (.* (left-singular-vectors-of x) (diagonal (singular-values-of x)) (tp (right-singular-vectors-of x)))) ;;; ;;; whose mean absolute element-wise error is quite small, namely (mean (abs (- x x2))) ;;; Similarly some functions defined on other matrix decompositions ;;; also operate directly on the matrix argument. ;;;
17,579
Common Lisp
.l
446
36.621076
84
0.661299
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9ee7f2a7c78762fdf1fde46f3f1d02d5ea1997ddd71e63462f9add7fca6a19b7
33,031
[ -1 ]
33,032
matrices.lsp
rwoldford_Quail/examples/arrays/matrices/matrices.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Matrices ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;; ;;; Matrices in Quail are just Quail arrays having 2 or fewer dimensions ;;; and numerical elements. As such any function that is applicable to ;;; a general array is also applicable to a matrix. ;;; ;;; Contents: ;;; ;;; 1. Matrix introduction. ;;; 1.1 Matrix dimensions. ;;; 1.1.2 One dimensional matrices. ;;; 1.1.2 Zero dimensional matrices. ;;; ;;; 2. Matrix operations. ;;; First consider selected operations that the result of matrices ;;; being special kinds of Quail ref-arrays. ;;; 2.1 Matrix specific unary operations. ;;; ... rank-of, inverse, trace-of, determinant, ;;; condition-number-of, ;;; diagonal-of, upper-triangle-of, ;;; singular-values-of, ;;; left-singular-vectors-of, right-singular-vectors-of ;;; 2.2 Matrix specific n-ary operations. ;;; ... Dot product for matrix multiplication: .* ;;; Solving linear systems of equations: solve ;;; 2.3 Special Matrices. ;;; ... identity-matrix, diagonal ;;; inverse-matrix ;;; ;;; 3. Matrix decompositions. ;;; 3.1 Singular Value Decomposition. ;;; 3.2 QR Decomposition. ;;; 3.2 LU Decomposition. ;;; 3.2 Cholesky Decomposition. ;;; ;;; 4. Operations inherited from array. ;;; ... log, sqrt, expt, cos, ... ;;; ... +, -, *, / ;;; ... tp ;;; ... ref, eref, sel ;;; ... slice and element iteration macros ;;; ... min, max, ... ;;; ;;; 5. Common Lisp types as matrices. ;;; CL lists, vectors, and arrays. ;;; ;;; To go directly to any of these, just search this file for the topic of ;;; of interest or to go section by section search for \section \subsection ;;; or \subsubsection. ;;; However, please note that some results will depend on ;;; having executed other forms earlier in the file. ;;; ;;; \section 1. Matrix introduction. ;;; ;;; First we need a matrix x. (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2))) x ;;; Note that x is filled by row. If column-wise order was desired one ;;; need only pass array :column as the value of its keyword argument :fill. (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2) :fill :column)) x ;;; Either way its dimensions are (dimensions-of x) ;;; which means a matrix having (nrows x) ;;; rows and (ncols x) ;;; columns and (number-of-elements x) ;;; elements. ;;; ;;; \subsection 1.1 Matrix dimensions. ;;; ;;; Matrices can have 0, 1, or 2 dimensions representing scalars, column vectors, ;;; and general matrices respectively. (number-of-dimensions x) ;;; Each of these are printed slightly differently from each other and from more ;;; general arrays. ;;; ;;; The original matrix x is an example of a two dimensional matrix. ;;; Any reference of it that preserves shape will also be two dimensional: (ref x '(0 1) T) (ref x 0 T :shape T) (ref x T 0 :shape T) (ref x 0 0 :shape T) ;;; ;;; \subsubsection 1.1.2 One dimensional matrices. ;;; ;;; For an example of a 1 dimensional matrix, consider column 0 of x (<- 1d-x (ref x T 0)) (number-of-dimensions 1d-x) ;;; Its' single dimension is reflected in its printed representation. 1d-x (dimensions-of 1d-x) (nrows 1d-x) (ncols 1d-x) (matrix-dimensions-of 1d-x) ;;; NOTE: All single dimensioned matrices are assumed to be column vectors. ;;; So referencing row 0 of x will also return a column vector! (<- 1d-x (ref x 0 T)) 1d-x (number-of-dimensions 1d-x) (dimensions-of 1d-x) (nrows 1d-x) (ncols 1d-x) (matrix-dimensions-of 1d-x) ;;; Had we wanted to preserve the row shape, the call to ref would ;;; include :shape T. ;;; Of course the transpose of an n by 1 column vector will always be ;;; a 1 by n matrix. (tp 1d-x) ;;; ;;; \subsubsection 1.1.3 Zero dimensional matrices. ;;; ;;; Occasionally a zero dimensional matrix is constructed. ;;; This usually happens by referencing a single element of a matrix ;;; via ref or sel. For our example here, we will consider using sel ;;; so that we obtain a copy of a piece of x rather than a reference to it. ;;; (Sel is exactly like ref except that sel makes copies.) ;;; Then when we later set the value, we will do so without disrupting the ;;; original x or any other reference to it. ;;; ;;; Here's a 0-dimensional matrix, (<- 0d-x (sel x 0 0)) (number-of-dimensions 0d-x) (dimensions-of 0d-x) (nrows 0d-x) (ncols 0d-x) (matrix-dimensions-of 0d-x) ;;; Conceptually the result is a scalar and so has zero (i.e. NIL) dimensions. ;;; However it is distinct from the true scalar obtained by directly accessing ;;; the 0 0 element of x through eref. (<- x00 (eref x 0 0)) ;;; An important consequence of this is that 0d-x can be regarded as a container ;;; whose contents can be changed whereas x00 cannot. ;;; For example, any of (<- (eref 0d-x) 100) ;; as a zero dimensional matrix, (<- (eref 0d-x 0) 100) ;; as a one dimensional matrix, (<- (eref 0d-x 0 0) 100) ;; or as a two dimensional matrix, ;;; will work but the same forms with x00 in place of 0d-x will result in error. ;;; Note that by so doing we have also changed the corresponding element in x ;;; because 0d-x is an refernce to part of x as opposed to a copy of it. ;;; ;;; The distinction between is important when for example a function is called that ;;; needs to return a different value as the contents of 0d-x. This is often ;;; the case when foreign functions that call Fortran or C are used as these ;;; often return information as side-effects on the contents of input arrays. ;;; ;;; A simpler illustration of the difference is the case where some structure ;;; maintains a pointer to the value of both x00 and 0d-x. ;;; Suppose we have a list l that points to both values, as in (<- l (list x00 0d-x)) ;;; 0d-x would normally be changed by (<- (eref 0d-x) 222222222) ;;; and the true scalar x00 by (<- x00 111111111) ;;; Only the second element of l will contain the updated info l ;;; and so will be different from (list x00 0d-x) ;;; \Section 2. Matrix operations. ;;; ;;; All of the functions that can be used with arrays can also ;;; be used with a matrix x. Some examples typically expected ;;; of a matrix are its' transpose (tp x) ;;; and element-wise arithmetic, (+ x x x) (- x x x) (/ x x x) (* x x x) ;;; For these operations to work the dimensions of the arguments must conform. ;;; For example, (+ (tp x) x) will fail. ;;; ;;; If however one of the arguments is a scalar or a 0-dimensional matrix, ;;; the operation will apply to all conformable arguments equally. (+ x 999999 x) (+ x 0d-x x) ;;; And so on for the other operators. ;;; ;;; This is also the case for 1-dimensional matrices. Here are two. (<- col-x (+ '(10000 20000 30000) (ref x T 0))) col-x (<- row-x (+ '(10 20) (ref x 0 T))) row-x ;;; Adding col-x to x results in it being added to every column of x. (+ x col-x) (+ col-x x) ;;; Adding row-x to x results in it being added to every row of x. (+ x row-x) (+ row-x x) ;;; This also works for two-dimensional matrices when one of the dimensions ;;; is 1. (+ (tp row-x) x) (+ x (tp row-x)) ;;; When one of the dimensions is 1 (nrows or ncols is 1), then some effort is ;;; made to match the remaining dimension with one of the dimensions of the ;;; other argument and operate over rows or columns accordingly. ;;; ;;; If we have ncols=nrows on the two dimensional argument then some ambiguity ;;; arises and we have arbitrarily selected row-major order. (<- square-x (array '(1 2 3 4 5 6 7 8 9) :dimensions '(3 3))) square-x (+ square-x col-x) (+ col-x square-x) (+ (tp col-x) square-x) (+ square-x (tp col-x)) ;;; NOTE: When more than two arguments are given, arithmetic operations occur ;;; in binary fashion proceeding left to right. As a consequence ;;; (aside from numerical considerations) the arithmetic operations are no ;;; longer associative when operating on matrices some of which are two dimensional ;;; and some of which are one dimensional. ;;; For example (+ x col-x row-x) ;;; and (+ col-x x row-x) ;;; are equivalent but (+ col-x row-x x) will fail because (+ col-x row-x) will. ;;; If you are keen to do something different you can take matters into your ;;; own hands for element-wise operations by calling map-element directly. ;;; This will allow you to specify an order. ;;; ;;; ;;; There are a host of Common Lisp mathematical functions that have been ;;; extended to operate on arrays in general. These are described in more ;;; detail in (edit-file "eg:Arrays;math-funs.lsp") ;;; Similarly, anything that operates on arrays also operates on matrices. ;;; For the whole ball of wax, see (edit-file "eg:Arrays;overview.lsp") ;;; 2.1 Matrix specific unary operations. ;;; ... rank-of, inverse, trace-of, determinant, ;;; condition-number-of, ;;; diagonal-of, upper-triangle-of, ;;; singular-values-of, ;;; left-singular-vectors-of, right-singular-vectors-of (rank-of x) (<- sym-x (.* (tp x) x)) (inverse sym-x) ;;; 2.2 Matrix specific n-ary operations. ;;; ... Dot product for matrix multiplication: .* ;;; Solving linear systems of equations: solve ;;; All of the functions that can be used with arrays can also ;;; be used with a matrix x. Some examples are (* 2 x) (log x) (sqrt x) (tp x) (dimensions-of x) (eref x 0 1) (ref x '(:c 0) ) (ref x '(:c 0) 1) (ref x T 1) ;;; ;;; There are also some functions that are peculiar to matrices. ;;; ;;; nrows ... the number of rows in the matrix. ;;; ncols ... the number of columns in the matrix. ;;; ;;; Most are functions that are related to matrix algebra. ;;; They include: ;;; tp ... the transpose function, ;;; .* ... the dot product function, ;;; determinant ... the determinant of a square matrix, ;;; trace-of ... the trace of a matrix, ;;; rank-of ... the rank of a matrix, ;;; condition-number-of ... the condition number of a matrix, ;;; solve ... solves systems of linear equations, ;;; inverse ... returns the matrix inverse of a square matrix, ;;; or the Moore-Penrose generalized inverse of ;;; a rectangular matrix. ;;; ;;; as well as several matrix decompositions ;;; svd-of ... returns the singular-value decompostion of a ;;; matrix, ;;; qrd-of ... returns the QR decompostion of a matrix, ;;; lud-of ... returns the LU (lower-upper) decomposition, ;;; cholesky-of ... returns the Cholesky decomposition. ;;; ;;; We'll illustrate each of these in turn considering the problem of ;;; solving a system of linear equations, say the ``normal equations'' ;;; from a least-squares linear regression. ;;; That is for fixed n by p matrix X and n by 1 vector Y, we solve the ;;; following matrix equation for the unknown p by 1 vector b. ;;; ;;; T T ;;; X X b = X Y ;;; (rank-of x) ;;; T ;;; Here's X X (<- xtx (.* (tp x) x)) (trace-of xtx) (determinant xtx) ;;; ;;; And suppose y is in fact linearly related to X (<- trueb (array '(5 7))) (<- y (+ (.* X trueb) (random-gaussian :n 3 :scale .1))) ;;; ;;; Note that here (nrows y) (ncols y) ;;; ;;; but the dimensions of y are ;;; (dimensions-of y) ;;; To get a row vector it will be necessary to take the transpose of y. ;;; This will be a 2 dimensional matrix having a single row. (dimensions-of (tp y)) ;;; ;;; One way to force the preservation of the 2 dimensional nature of y is to ;;; take its transpose twice. (dimensions-of (tp (tp y))) ;;; T ;;; The final ingredient is X Y ;;; (<- xty (.* (tp x) y)) ;;; ;;; And to solve for b ;;; (solve xtx xty) ;;; which should have values close to the original vector ;;; used above to create y. ;;; ;;; In keeping with many statistical systems, the second argument to ;;; solve is optional. ;;; If the second argument is NIL or an identity-matrix, ;;; solve returns the matrix inverse of its' first argument. (<- xtx-inv (solve xtx NIL)) ;;; or (solve xtx (identity-matrix (nrows xtx))) ;;; ;;; Then the normal equations could be solved equivalently (in Quail) as ;;; (.* xtx-inv xty) ;;; Note on numerical stability: ;;; ;;; In most systems, this route to the solution of the linear system ;;; is to be strictly avoided because of numerical problems. ;;; This is because explicitly producing a matrix inverse and then multiplying ;;; it by the vector x to get the solution is numerically unreliable for an ;;; ill-conditioned system of equations. ;;; ;;; In Quail, the problem does not arise because the inverse is calculated only ;;; implicitly. When it comes time to do some matrix multiplication with it, ;;; the solve function is used as demanded for numerical stability. ;;; Only if the user actually wants to see or use the elements of the inverse ;;; matrix is it ever calculated explicitly and stored; even then, these values ;;; will never be used in a matrix multiplication. ;;; ;;; When solve is given a null second argument it simply calls inverse ;;; on its first argument, as in (<- i-xtx (inverse xtx)) ;;; So we could write down the solution to the normal equations as ;;; (<- b-hat (.* (inverse xtx) xty)) ;;; which would yield a solution numerically identical to that obtained earlier ;;; by (solve xtx xty). ;;; ;;; Should it at any time be desirable to have the inverse explicitly, one need ;;; only get a copy in the usual way using sel (<- explicit-inv (sel i-xtx)) ;;; Using this one could follow the numerically undesirable approach to get ;;; (.* explicit-inv xty) ;;; which will in general be different from b-hat. ;;; ;;; It should also be noted that some small differences do to the order of ;;; operations will be obtained if we caclulate b-hat directly as the mathematics ;;; would have us do (.* (inverse (.* (tp x) x)) (tp x) y) ;;; These differences are here primarily because .* has called the function solve ;;; on i-xtx and (tp X) rather than on i-xtx and xty. ;;; Like most operations, mathematically associative ;;; operators like .* are not computationally associative. ;;; ;;; Again because the inverse is only implicit, we can make some effort to have the ;;; operators take note of this and produce calculations that are more nearly correct ;;; We go far along this route by having the inverse remember it is the inverse of ;;; an original object. ;;; For example, xtx is exactly the same object as (inverse i-xtx) (eq xtx (inverse i-xtx)) ;;; and so we also have information to determine that (.* (inverse xtx) xtx) ;;; must yield an identity matrix exactly! Compare this to (.* explicit-inv xtx) ;;; ;;; Quail employs the general strategy that where possible any operation performed ;;; on an inverse matrix which is mathematically equivalent to performing another ;;; operation on the original matrix and then inverting the result, the latter ;;; is chosen as the computational strategy. ;;; ;;; To make these points consider to square full-rank matrices A and B. (<- a (array (random-gaussian :n 4) :dimensions '(2 2))) (<- b (array (random-gaussian :n 4) :dimensions '(2 2))) ;;; -1 -1 ;;; and their inverses A and B respectively. (<- ia (inverse a)) (<- ib (inverse b)) ;;; ;;; Then mathematically we have: ;;; ;;; -1 -1 -1 ;;; A B = (BA) ;;; (- (.* ia ib) (inverse (.* b a))) ;;; which is exact because the operations are now computationally equivalent. ;;; ;;; This was possible because the inverse function caches the matrix it inverted. ;;; The caclulation also benefits by suppressing the matrix inverse operation ;;; until last. The left hand side involves 2 calls to the solve ;;; function and one call to a matrix multiply whereas the right hand side involves ;;; only a single call to the solve function plus the single matrix multiply. ;;; ;;; Another way of solving this system would be to make use of any of a ;;; variety of matrix decompositions. Solve will work with most of them. ;;; \section Common Lisp types as matrices. ;;; Any list or Common Lisp vector will be treated as a one dimensional matrix ;;; and may be used as such. Matrix operations on these will typically return ;;; matrices. ;;; Some examples are (<- l (list 1 2 3 4 5 6)) l (dimensions-of l) (nrows l) (ncols l) (tp l) (<- v (vector 1 2 3 4 5 6)) v (dimensions-of v) (nrows v) (ncols v) (tp v) ;;; Note that deeper list structure is ignored. ;;; ;;; Common Lisp arrays that have two dimensions and numerical elements are ;;; treated as if they were one or two dimensional Quail matrices. ;;; Often Quail matrix operations on Common Lisp arrays preserve the ;;; CL array data type. For example ref does not. (<- cla-1 (make-array 6 :initial-contents '(1 2 3 4 5 6))) cla-1 (dimensions-of cla-1) (nrows cla-1) (ncols cla-1) (tp cla-1) (<- cla-2 (make-array '(3 2) :initial-contents '((1 2) (3 4) (5 6)))) cla-2 (dimensions-of cla-2) (nrows cla-2) (ncols cla-2) (tp cla-2) (.* (tp cla-2) cla-2)
18,310
Common Lisp
.l
466
36.669528
86
0.64741
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
483e5b1e0edcd8a0310d4b023d98dc14a8b15c966dc08b28d0e52f233da78743
33,032
[ -1 ]
33,033
cl-types.lsp
rwoldford_Quail/examples/arrays/matrices/cl-types.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Common Lisp types as matrices ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;; ;;; Matrices in Quail are just Quail arrays having 2 or fewer dimensions ;;; and numerical elements. As such any function that is applicable to ;;; a general array is also applicable to a matrix. ;;; ;;; For an introduction to matrices in Quail see ;;; (edit-file "eg:Matrices;overview.lsp") ;;; ;;; ;;; \section Common Lisp types as matrices. ;;; ;;; Any list or Common Lisp vector will be treated as a one dimensional matrix ;;; (i.e. column vector) and may be used as such. ;;; Matrix operations on these will typically return matrices. ;;; Some examples are (<- l (list 1 2 3 4 5 6)) l (dimensions-of l) (matrix-dimensions-of l) (nrows l) (ncols l) (tp l) (<- v (vector 1 2 3 4 5 6)) v (dimensions-of v) (matrix-dimensions-of v) (nrows v) (ncols v) (tp v) ;;; Note that deeper list structure is ignored. ;;; ;;; Common Lisp arrays that have two dimensions and numerical elements are ;;; treated as if they were one or two dimensional Quail matrices. ;;; Often Quail matrix operations on Common Lisp arrays preserve the ;;; CL array data type. For example ref does not. (<- cla-1 (make-array 6 :initial-contents '(1 2 3 4 5 6))) cla-1 (dimensions-of cla-1) (matrix-dimensions-of cla-1) (nrows cla-1) (ncols cla-1) (tp cla-1) (<- cla-2 (make-array '(3 2) :initial-contents '((1 2) (3 4) (5 6)))) cla-2 (dimensions-of cla-2) (matrix-dimensions-of cla-2) (nrows cla-2) (ncols cla-2) (tp cla-2) (.* (tp cla-2) cla-2)
1,914
Common Lisp
.l
66
26.272727
84
0.590316
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dfee08e5233e9038ce8ed7c2dbe02738b59d238af5d1bc6606b36b0ae89f3992
33,033
[ -1 ]
33,034
overview.lsp
rwoldford_Quail/examples/arrays/matrices/overview.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Matrix overview ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (C) 1994 Statistical Computing Laboratory, University Of Waterloo ;;; ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;; ;;; Matrices in Quail are just Quail arrays having 2 or fewer dimensions ;;; and numerical elements. As such any function that is applicable to ;;; a general array is also applicable to a matrix. ;;; ;;; For an introduction to arrays in Quail see ;;; (edit-file "eg:Arrays;overview.lsp") ;;; ;;; Contents: ;;; ;;; 1. Matrix introduction. ;;; 1.1 Matrix constructors ;;; - array, diagonal, identity-matrix, ones, seq ;;; 1.2 Matrix selectors ;;; - eref, ref, and sel. ;;; - diagonal-of, upper-triangle-of ;;; 1.3 Matrix dimensions. ;;; - dimensions-of, nrows, ncols, matrix-dimensions-of, ;;; number-of-elements ;;; 1.3.1 One dimensional matrices. ;;; 1.3.2 Zero dimensional matrices. (edit-file "eg:Arrays;Matrices;intro.lsp") ;;; ;;; 2. Matrix operations. ;;; First consider selected operations that result from matrices ;;; being special kinds of Quail ref-arrays. ;;; These are the n-ary arithmetic operators, various ;;; common mathematical unary and binary operations, ;;; and numerical predicates. ;;; ;;; 2.1 Matrix specific operations. ;;; ;;; 2.1.1 Matrix multiplication. .* ;;; 2.1.2 Solving systems of linear equations ;;; 2.1.3 Matrix inversion ;;; ;;; 2.2 Numerical properties ;;; ... rank-of, condition-number-of, determinant, ;;; trace-of ;;; ;;; 2.2.1 Numerical ranks ;;; 2.2.2 Condition numbers ;;; 2.2.3 Determinant ;;; 2.2.4 Trace ;;; 2.2.5 Selected algebraic structure ;;; (edit-file "eg:Arrays;Matrices;operations.lsp") ;;; ;;; 3. Matrix decompositions. (edit-file "eg:Arrays;Matrices;Decompositions;overview.lsp") ;;; 3.1 LU Decomposition. (edit-file "eg:Arrays;Matrices;Decompositions;lu.lsp") ;;; 3.2 Cholesky Decomposition. (edit-file "eg:Arrays;Matrices;Decompositions;cholesky.lsp") ;;; 3.3 Singular Value Decomposition. (edit-file "eg:Arrays;Matrices;Decompositions;svd.lsp") ;;; 3.4 QR Decomposition. (edit-file "eg:Arrays;Matrices;Decompositions;qr.lsp") ;;; ;;; 4. Operations inherited from array. ;;; ... log, sqrt, expt, cos, ... ;;; ... +, -, *, / ;;; ... tp ;;; ... ref, eref, sel ;;; ... slice and element iteration macros ;;; ... min, max, ... ;;; ;;; 5. Common Lisp types as matrices. ;;; CL lists, vectors, and arrays. (edit-file "eg:Arrays;Matrices;cl-types.lsp") ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Matrix specific n-ary operations. ;;; ... Dot product for matrix multiplication: .* ;;; Solving linear systems of equations: solve ;;; ;;; There are also some functions that are peculiar to matrices. ;;; ;;; nrows ... the number of rows in the matrix. ;;; ncols ... the number of columns in the matrix. ;;; ;;; Most are functions that are related to matrix algebra. ;;; They include: ;;; tp ... the transpose function, ;;; .* ... the dot product function, ;;; determinant ... the determinant of a square matrix, ;;; trace-of ... the trace of a matrix, ;;; rank-of ... the rank of a matrix, ;;; condition-number-of ... the condition number of a matrix, ;;; solve ... solves systems of linear equations, ;;; inverse ... returns the matrix inverse of a square matrix, ;;; or the Moore-Penrose generalized inverse of ;;; a rectangular matrix. ;;; ;;; as well as several matrix decompositions ;;; svd-of ... returns the singular-value decompostion of a ;;; matrix, ;;; qrd-of ... returns the QR decompostion of a matrix, ;;; lud-of ... returns the LU (lower-upper) decomposition, ;;; cholesky-of ... returns the Cholesky decomposition. ;;;
4,802
Common Lisp
.l
119
37.10084
84
0.510597
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a8fccfe375d7c454d80ab5e897c6b8cd8d38199638d8e90395a3ea83b95bef06
33,034
[ -1 ]
33,035
svd.lsp
rwoldford_Quail/examples/arrays/matrices/Decompositions/svd.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; svd.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;----------------------------------------------------------------------------- ;;; (in-package :quail-user) ;;; ;;; This is an example file illustrating the use of my favourite matrix ;;; decomposition, the singular value decomposition or svd for short. ;;; ;;; First there is some discussion of the decomposition itself and some ;;; of its important properties and relations. ;;; The remainder of the file gives example code illustrating the ;;; use of the implementation and some of the properties described here. ;;; ;;; To get to the example code search for the string **example** ;;; ;;; As defined here, it is sometimes referred to as the singular value ;;; factorization (e.g. LINPACK), the term decomposition being reserved for ;;; the case when U is required to be a complete n by n orthogonal matrix. ;;; ;;; The svd is a decomposition of the n by p matrix X ;;; into the product of three matrices, U D and V, where ;;; T ;;; 1. X = U D V ;;; ;;; 2. U is an n by p matrix such ;;; T ;;; U U = Ip ... the p by p identity matrix. ;;; ;;; The columns of U are called the left singular vectors of X. ;;; ;;; 3. V is a p by p orthogonal matrix. ;;; T T ;;; V V = VV = Ip ... the p by p identity matrix. ;;; ;;; The columns of V are called the right singular vectors of X. ;;; ;;; 4. D is a p by p diagonal matrix whose non-negative diagonal elements are ;;; the singular values of X arranged in order of decending magnitude. ;;; ;;; ;;; Note also that the following properties and relations hold: ;;; ;;; T 2 T ;;; X X = V D V And so the singular values of X are the square root ;;; of the eigen-values of XTX. ;;; The column vectors of V are the corresponding eigen-vectors. ;;; ;;; T 2 T ;;; X X = U D U And so the singular values of X are the square root ;;; of the non-zero eigen-values of XXTX. ;;; The column vectors of U are the corresponding eigen-vectors. ;;; ;;; T ;;; U U is *not* an orthogonal matrix but ;;; is an orthogonal projection matrix that will project any ;;; n by 1 real vector onto the column space of the X matrix. ;;; It is sometimes called the ``hat matrix'' in statistics ;;; and its diagonal elements are measures of ``leverage'' ;;; ;;; T ;;; I - U U is also an orthogonal projection matrix projecting a vector ;;; y onto the orthogonal complement of the column space of X. ;;; ;;; -1 T ;;; G = V D U is a generalized inverse of X; it is the Moore-Penrose ;;; inverse and satisfies the following properties: ;;; XGX = X ; GXG = G ;;; Again, for numerical reasons it is not a good idea to ;;; work with g-inverses in calculations (at least those so ;;; formed). It's better to work with a QR or LU decomposition. ;;; ;;; -1 T T ;;; b = V D U y is the least-squares solution to the overdetermined linear ;;; system Xb=y or, equivalently, to the regression problem ;;; y = Xb + r where b and the residual r are unknown. ;;; Note that this is not the recommended means of numerically ;;; determining the solution; use the solve function instead. ;;; ;;; All values are calculated using the LINPACK routine dsvdc. ;;; ;;; The **example** begins ;;; ;;; Let's get a 25 by 4 matrix X. ;;; (<- x (array (iseq 100) :dimensions '(25 4))) ;;; ;;; Its svd is simply calculated as ;;; (<- xsvd (svd-of X)) ;;; xsvd is an instance of an sv-decomposition object which stores the ;;; relevant information. ;;; The singular values are stored as a vector. (singular-values-of xsvd) ;;; The matrix U: (left-singular-vectors-of xsvd) ;;; The matrix V: (right-singular-vectors-of xsvd) ;;; ;;; The decomposition has been cached on the original matrix X so that ;;; we can ask for these quantities from either the svd or directly from ;;; the matrix X. ;;; Had the svd not been calculated before, it would be calculated and ;;; cached as soon as X was queried for singular-value information. ;;; So we have (eq (singular-values-of X) (singular-values-of xsvd)) ;;; returning T because both calls return the same vector. ;;; The same holds for the other calls for right left singular ;;; values. ;;; NOTE: Any stored decompositions can always be cleared with (clear-decompositions X) ;;; Any further decomposition calls will require recalculation. ;;; And now xsvd calculated previously will no longer be eq to the ;;; new calculations (eq (singular-values-of X) (singular-values-of xsvd)) ;;; although element-wise the results are numerically equal. (and (= (eref (singular-values-of X) 0) (eref (singular-values-of xsvd) 0)) (= (eref (singular-values-of X) 1) (eref (singular-values-of xsvd) 1)) (= (eref (singular-values-of X) 2) (eref (singular-values-of xsvd) 2)) (= (eref (singular-values-of X) 3) (eref (singular-values-of xsvd) 3)) ) ;;; For numerical reasons the decomposition will rarely be exact. ;;; For example, let's multiply the pieces together and see how close ;;; the result is to the original matrix X. (<- svs (singular-values-of X)) ;;; which is a vector. We use the function diagonal to get a diagonal ;;; matrix whose diagonal elements are those of the vector. (<- d (diagonal svs)) ;;; Now for the other matrices, (<- u (left-singular-vectors-of X)) (<- v (right-singular-vectors-of X)) ;;; and the mean element-wise absolute error in caclulating X from these ;;; components is (mean (abs (- x (.* u d (tp v))))) ;;; Similarily we might test the orthogonality of the singular-vectors ;;; (mean (abs (- (.* (tp v) v) (identity-matrix 4)))) (mean (abs (- (.* v (tp v)) (identity-matrix 4)))) (mean (abs (- (.* (tp u) u) (identity-matrix 4)))) ;;; ;;; Mathematically X is only of rank 2. The second and third columns can be ;;; obtained as the sum of the first and an integer multiple of the difference ;;; between the second and first. ;;; The rank can be determined as the number of non-zero singular values. ;;; Numerically, however this will not be exactly 2. (matrix-rank-of x) ;;; Should we decide that the last two singular values are mathematically zero, ;;; we can set them to zero exactly. (<- (ref (singular-values-of x) '(2 3)) ; indices 2 and 3 are the last two. '(0 0)) ;;; Note that svs has changed as well; it was the same vector. svs ;;; ;;; The rank will now be mathematically correct. (matrix-rank-of x) ;;; Of course there is no guarantee that the resulting svd will produce ;;; more accurate answers for other calculations. (<- dnew (diagonal svs)) (mean (abs (- x (.* u dnew (tp v))))) ;;; ;;; Finally, here's how you might collect up the diagonal elements of the ;;; hat matrix ;;; T -1 T T ;;; X (X X) X = U U (collect-slices (u-row u 0) ;; That is, collect slices where each slice will be called ;; u-row. Each slice will be a slice of u, and ;; a slice of u will be defined to be all elements ;; having the same value of its 0'th index (i.e. in the same row). (sum (* u-row u-row)) ) ;;; ;;; So we might define a function that puts it all together ;;; (defun get-leverage-values (X) "Returns a list of the diagonal elements of the ~ hat matrix formed from the matrix X." (collect-slices (u-row (left-singular-vectors-of X) 0) (sum (* u-row u-row)) ) ) ;;; Note that the svd will only ever be calculated once. ;;; (get-leverage-values X) ;;; Here's a faster version that removes the overhead from ;;; sum and collect-slices; but requires a little more thinking. ;;; The basic idea is to avoid having generic functions look up ;;; the appropriate method more often than necessary. ;;; In this case, because all calculations are done with the result ;;; of an eref, we can count on that being a Common Lisp number ;;; and so may use ``sum'' in the loop macro and also ;;; the CL function * rather than the more general Quail versions ;;; of either of these. The Quail macro ``with-CL-functions'' ;;; identifies the list of functions to be replaced everywher in the ;;; body by the CL equivalent. ;;; (defun get-lev-vals (X) "Returns a list of the diagonal elements of the ~ hat matrix formed from the matrix X." (with-CL-functions (*) (let ((n (or (first (dimensions-of X)) 1)) (p (or (second (dimensions-of X)) 1)) (U (left-singular-vectors-of X)) ) (loop for i from 0 below n collect (loop for j from 0 below p as val = (eref U i j) sum (* val val) ))))) (get-lev-vals X) ;;; To compare, use time. The difference can be substantial. ;;; Again, to be fair, make sure that the svd is calculated ;;; before either call. If you have executed the statements ;;; above in order this will be the case. ;;; (time (get-leverage-values X))
9,852
Common Lisp
.l
233
38.55794
81
0.61804
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6751a182e88c6c82fab18b3ea8098c7251be213a9fced0de5b971f86e2860bf3
33,035
[ -1 ]
33,036
qr.lsp
rwoldford_Quail/examples/arrays/matrices/Decompositions/qr.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; qr.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1995 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1995. ;;; ;;; ;;;----------------------------------------------------------------------------- ;;; (in-package :quail-user) ;;; ;;; This is an example file illustrating the use of the QR decomposition. ;;; ;;; First there is some discussion of the decomposition itself. ;;; The remainder of the file gives example code illustrating the ;;; use of the implementation. ;;; For general information about matrix decompositions in Quail ;;; or to see the other decompositions, you might check out (edit-file "eg:Arrays;Matrices;Decompositions;overview.lsp") ;;; ;;; The QR decomposition of the n by p matrix X ;;; decomposes X into the product of an n by p matrix Q and an upper triangular ;;; matrix R ;;; ;;; X = Q R ;;; ;;; T ;;; such that Q Q = Ip ;;; This is often used to produce the least squares solution to ;;; ;;; y = Xb + e ;;; T 2 ;;; That is, it is used to find the solution b which minimizes e e = sum ei ;;; The least-squares solution is ;;; T -1 T -1 T ;;; b = (X X) X y = R Q y ;;; ;;; ;;; For example, consider the following matrix (<- x (array '(1 2 3 4 5 6) :dimensions '(3 2))) (<- x1 (array '(1 2 2 4 3 6) :dimensions '(3 2))) (<- qrd (qrd-of x)) (<- qrd-sx (qrd-of (sel x) :pivot t)) (<- qrd1 (qrd-of x1)) (rank-of qrd) (upper-triangle-of qrd)
1,864
Common Lisp
.l
55
30.290909
81
0.474595
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d498af6f7ff20fff58673b79461470b8cda4f9232234640af32f7952c3138398
33,036
[ -1 ]
33,037
cholesky.lsp
rwoldford_Quail/examples/arrays/matrices/Decompositions/cholesky.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; cholesky.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;----------------------------------------------------------------------------- ;;; (in-package :quail-user) ;;; ;;; This is an example file illustrating the use of the Cholesky decomposition. ;;; ;;; First there is some discussion of the decomposition itself. ;;; The remainder of the file gives example code illustrating the ;;; use of the implementation. ;;; For general information about matrix decompositions in Quail ;;; or to see the other decompositions, you might check out (edit-file "eg:Arrays;Matrices;Decompositions;overview.lsp") ;;; ;;; The Cholesky decomposition of the p by p symmetric matrix A ;;; decomposes A into the product of p by p upper triangular matrix R and ;;; its transpose, a p by p lower triangular matrix. ;;; T ;;; A = R R ;;; ;;; This is often used to solve a square linear system of equations ;;; ;;; A x = c. ;;; ;;; By decomposing A into the product of triangular matrices, ;;; the solution x can be found by first solving the triangular system ;;; ;;; T ;;; R z = c ;;; ;;; for the vector z, and then solving the triangular system ;;; ;;; R x = a ;;; ;;; for x. ;;; ;;; Each of these equations can be solved simply using the backsolve ;;; operator. ;;; ;;; For example, consider the following matrix (<- A (array (random-uniform :n 16) :dimensions '(4 4))) ;;; which can be turned into a symmetric matrix (<- A (.* (tp A) A)) ;;; We'll also need a vector (<- c (array '(1 2 3 4))) ;;; ;;; First get the Cholesky decomposition of A ;;; (<- chol (cholesky-of A)) ;;; ;;; The solution to A x = c can be had directly from the decomposition ;;; as in (<- x (solve chol c)) ;;; ;;; This is possibly quite different from the result that is returned when ;;; solve is called on A itself (solve A c) ;;; especially if the matrix A is rather ill-conditioned, as approximated ;;; by the (condition-number-of chol) ;;; ;;; This is because the Cholesky called for here did not permit pivoting ;;; whereas the LU decomposition underlying the solve function has pivoting ;;; as the default. ;;; ;;; If pivoting is desired, the Cholesky permits substantial control on this. ;;; The generic function cholesky-of takes four keyword arguments: pivot ;;; initial final and prompt-if-fail?. ;;; Default of pivot is NIL. Pivot is non-null if pivoting is requested, ;;; null otherwise. ;;; Default of initial is NIL. If pivot is non-NIL, then initial can be a list ;;; of the indices of those diagonal elements which are to be moved the leading ;;; positions of A during pivoting.If NIL, then there is no restriction ;;; on the initial columns. ;;; Default of final is NIL. If pivot is non-NIL, then final can be a list ;;; of the indices of those diagonal elements which are to be moved to the ;;; trailing positions of A during pivoting. If NIL, then there is no ;;; restriction on the last columns. ;;; Default of prompt-if-fail? T Only relevant if no pivoting is allowed. ;;; If the algorithm fails, should the user be offered the opportunity to ;;; continue? If NIL, it is assumed that continuation is preferred. ;;; Continuation will produce a cholesky-decomposition object containing only ;;; a partial decomposition together with the order of the leading submatrix ;;; found to not be positive definite and a vector z such that Az = 0 approx. ;;; These are stored as the slots info and null-vector, respectively. ;;; ;;; ;;; ;;; Other quantities that can be calculated from the Cholesky decomposition are ;;; the determinant, (approximate) condition number, the matrix rank, ;;; and the explicitly calculated inverse ;;; -1 -T ;;; R R ;;; (determinant chol) (condition-number-of chol) (rank-of chol) (rank-of chol :tolerance 1.0E-10) (inverse chol) ;;; ;;; By looking at the components of the Cholesky decomposition, much information ;;; can be had ``by hand'', but with some care. Before, undertaking this ;;; careful examination of the LINPACK manual would be wise. ;;; All the information stored on the Cholesky is that provided by the LINPACK ;;; routines DCHDC (pivoting) and DPOCO (without pivoting). ;;; ;;; The Cholesky-decomposition has four components. ;;; The first is a square matrix whose upper triangle is the matrix R. ;;; Below the diagonal are the multipliers necessary to construct tp(R). ;;; This square matrix is had as follows: (upper-triangle-of chol) ;;; ;;; The second important piece of information is the vector of pivoting ;;; information. This is stored in (jpvt-of lud) ;;; and, if pivoting was requested, JPVT(J) contains the index of the ;;; diagonal element of A that was moved into the J-th position. ;;; ;;; The original matrix's numerical conditioning is determined ;;; by the (rcond-of chol) ;;; If (= (+ 1.0 (rcond-of chol)) 1.0) ;;; then for all intents and purposes, the original matrix is numerically ;;; singular. ;;; ;;; If the original matrix, A, is close to a singular matrix, ;;; then there will be an approximate null-vector, z, in the ;;; sense that ||Az|| = rcond*||A||*||z||. ;;; This vector is stored as (null-vector-of chol) ;;; ;;; Value depends upon whether pivoting was chosen or not. ;;; If pivoting, info contains the index of the last positive diagonal ;;; element of the Cholesky factor. ;;; Otherwise, it contains the order of the leading sub-matrix found ;;; not to be positive definite. (info-of chol) ;;; ;;; ;;; Again, for most purposes this kind of detail is unnecessary; it is ;;; generally recommended that the generic functions solve, determinant ;;; and so on be used.
6,199
Common Lisp
.l
157
36.751592
82
0.660475
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
43cdbca04584242b28e7cf484eef628ae95846f7d8ddfa5664b45d2623602fe7
33,037
[ -1 ]
33,038
lu.lsp
rwoldford_Quail/examples/arrays/matrices/Decompositions/lu.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; lu.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;----------------------------------------------------------------------------- ;;; (in-package :quail-user) ;;; ;;; This is an example file illustrating the use of the LU decomposition. ;;; ;;; First there is some discussion of the decomposition itself. ;;; The remainder of the file gives example code illustrating the ;;; use of the implementation. ;;; For general information about matrix decompositions in Quail ;;; or to see the other decompositions, you might check out (edit-file "eg:Arrays;Matrices;Decompositions;overview.lsp") ;;; ;;; The LU decomposition of the p by p matrix A decomposes A ;;; into the product of p by p lower triangular matrix L and ;;; and a p by p upper triangular matrix U. ;;; ;;; A = L U ;;; ;;; This is often used to solve a square linear system of equations ;;; ;;; A x = c. ;;; ;;; By decomposing A into the product of triangular matrices LU, ;;; the solution x can be found by first solving ;;; ;;; L z = c ;;; ;;; for the vector z, and then solving the system ;;; ;;; U x = a ;;; ;;; for x. ;;; ;;; Each of these equations can be solved simply using the backsolve ;;; operator. ;;; ;;; For example, consider the following matrix (<- A (array (random-uniform :n 16) :dimensions '(4 4))) ;;; and vector (<- c (array '(1 2 3 4))) ;;; ;;; First get the LU decomposition of A ;;; (<- lud (lud-of A)) ;;; ;;; The solution to A x = c can be had directly from the lu decomposition ;;; as in (<- x (solve lud c)) ;;; ;;; As it turns out this is exactly the result that is returned when ;;; solve is called on A itself (solve A c) ;;; That's because solve on a matrix argument uses the LU decomposition ;;; of that matrix to get the result. ;;; ;;; Other quantities that can be calculated from the LU decomposition are ;;; the determinant, (approximate) condition number, the matrix rank, ;;; and the explicitly calculated inverse ;;; -1 -1 ;;; U L ;;; (determinant lud) (condition-number-of lud) (rank-of lud) (rank-of lud :tolerance 1.0E-10) (inverse lud) ;;; ;;; By looking at the components of the lu decomposition, much information ;;; can be had ``by hand'', but with some care. Before, undertaking this ;;; careful examination of the LINPACK manual would be wise. ;;; All the information stored on the lud is that provided by the LINPACK ;;; routine DGECO. ;;; ;;; The lu-decomposition has three components. The first is a square matrix ;;; whose upper triangle is the matrix U. ;;; Below the diagonal are the multipliers necessary to construct L. ;;; This square matrix is had as follows: (lu-of lud) ;;; or equivalently (lu-of A) ;;; ;;; And so L can be had as ;;; (upper-triangle-of lud) ;;; or equivalently (upper-triangle-of (lu-of A)) ;;; ;;; The second important piece of information is the vector of pivoting ;;; information. This is stored in (ipvt-of lud) ;;; ;;; Finally, the original matrix's numerical conditioning is determined ;;; by the (rcond-of lud) ;;; If (= (+ 1.0 (rcond-of lud)) 1.0) ;;; then for all intents and purposes, the original matrix is numerically ;;; singular. ;;; ;;; Again, for most purposes this kind of detail is unnecessary; it is ;;; generally recommended that the generic functions solve, determinant ;;; and so on be used.
3,848
Common Lisp
.l
118
29.70339
81
0.613896
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
07e6052f0bb080b335997be5e6045a1b9c17bd58aa68df126df9ab3ad7e20e20
33,038
[ -1 ]
33,039
eigen.lsp
rwoldford_Quail/examples/arrays/matrices/Decompositions/eigen.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; eigen.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Carsten Whimster 1997. ;;; ;;;----------------------------------------------------------------------------- ;;; This is a file demonstrating the use of the eigen value decomposition. ;;; ;;; Note that the array A must be real symmetric. (<- A (array '((1.0 2.0 3.0) (2.0 3.0 5.0) (3.0 5.0 4.0)))) (<- V (eigen-vectors-of A)) ;;; The eigen values and vectors are now cached on A, as these were automatically ;;; calculated above. Consequently the following two operations work on already ;;; existing data, and don't use any computational resources. (<- D (eigen-values-of A)) (.* V (diagonal D) (tp V)) ;; should return A (inspect (eigen-of A)) (inverse (eigen-of A)) ;;; Now we can reference it as often as we like without redoing the calculations. ;;; Here is a larger example which demonstrates the accuracy for ill conditioned ;;; matrices. First we set the random seed so that our results are repeatable. In ;;; this example, the eigen values are actually the numbers that are sent in, so ;;; we can compare the output to the input for accuracy. Note that the sequence ;;; is not important here. (setf (qk::current-value-of qk::*default-random-number-generator*) 616053555) (setf pre1 (diagonal '(100000 100000 100000 100000 100000 100000 1 1 1 1))) (setf pre2 (array (random-gaussian :n 100) :dimensions '(10 10))) (setf pre3 (right-singular-vectors-of pre2)) (setf B (.* pre3 pre1 (tp pre3))) (setf eigen (eigen-of B)) (eigen-values-of eigen) ;;; Here is the output (note that it is sorted in descending order): ;;; ;;; #1m(100000.00000000022 100000.00000000017 ;;; 100000.00000000007 100000.00000000006 ;;; 99999.99999999999 99999.99999999997 ;;; 1.0000000000147449 1.0000000000099358 ;;; 0.9999999999945548 0.9999999999911166) ;;; Finally, we can access the function behind the eigen decomposition directly. ;;; This returns the array A, the vector of eigen values, and the matrix of eigen ;;; vectors. (<- D (array 0.0 :dimensions '(3))) (<- V (array 0.0 :dimensions '(3 3)))
2,504
Common Lisp
.l
55
41.927273
82
0.597194
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
538f5e547f0dfa7c22d1df977510ec29e5aa6701aef7a3a57aa29b514f5d29a4
33,039
[ -1 ]
33,040
overview.lsp
rwoldford_Quail/examples/arrays/matrices/Decompositions/overview.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; overview.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1994 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1994. ;;; ;;; ;;;----------------------------------------------------------------------------- ;;; (in-package :quail-user) ;;; In this and subsequent files we discuss matrix decompositions that ;;; are currently available in Quail. ;;; ;;; Contents: ;;; ;;; 3.0 Matrix decompositions ;;; 3.1 LU Decomposition. ;;; 3.2 Cholesky Decomposition. ;;; 3.3 Singular Value Decomposition. ;;; 3.4 QR Decomposition. ;;; ;;; To go directly to any of these, just search this file for the topic of ;;; of interest or to go section by section search for \section \subsection ;;; or \subsubsection. ;;; However, please note that some results will depend on ;;; having executed other forms earlier in the file. ;;; ;;; See also the matrix overview: (edit-file "eg:Arrays;Matrices;overview.lsp") ;;; See also to the array overview: (edit-file "eg:Arrays;overview.lsp") ;;; ;;; \section 3.0 Matrix decompositions ;;; ;;; Matrix decompositions are useful mathematically and computationally. ;;; By decomposition, we mean here that a collection of matrices are ;;; found such that their product will yield the original matrix. ;;; The individual matrices are chosen to have certain properties ;;; (e.g. orthonormal columns, diagonal, or triangular structure) ;;; which are either mathematically or computationally convenient. ;;; ;;; For example the LU decomposition decomposes a square matrix A ;;; into the product of a lower triangular matrix L and an upper ;;; triangular matrix U so that A = LU. ;;; ;;; In Quail every kind of decomposition is a subclass of the class ;;; ``matrix-decomposition.'' For example, the subclass ;;; lu-decomposition represents the LU decomposition and an instance ;;; of this class represents the lu decomposition of a particular matrix. ;;; The general matrix-decomposition class is pretty much abstract ;;; and is intended to define the common behaviours of its sublasses. ;;; ;;; The following table lists the decompositions and the uses that they have ;;; in common. The actual uses are illustrated in the subsections which follow. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; The decompositions and their common use ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; decomposition: Singular- LU QR Cholesky ;;; value (svd) ;;; ----------------------------------------------------- ;;; Methods ;;; ;;; condition-number-of Yes Yes No Yes ;;; determinant Yes Yes No Yes ;;; inverse No Yes No Yes ;;; rank-of Yes Yes Yes Yes ;;; solve No Yes Yes No ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; In general, if the matrix decomposition of interest is ``foo'', say, ;;; then the foo decomposition of the matrix A is had by calling (foo-of A). ;;; This calculates and returns an instance of ``foo-decomposition.'' ;;; This instance can then be used as an argument to the functions ;;; listed in the above table and to functions that are of peculiar interest ;;; to a foo decomposition. ;;; ;;; Some of these functions can be called directly on a matrix, not just on ;;; a matrix decomposition. ;;; In this case, Quail chooses whichever decomposition seems most appropriate ;;; for the situation. ;;; ;;; For example, calling ``condition-number-of'' on a matrix ;;; A will cause the singular values of A to be determined and the ratio of the ;;; largest to smallest returned. ;;; But calling it on a specific ``foo-decomposition'' instance, will return ;;; an estimate of this ratio as determined from the information directly ;;; available on that decomposition instance and not necessarily from the ;;; singular values themselves. ;;; ;;; With this control over which decomposition to use in a particular situation ;;; one can, for example, choose not to incur the additional cost of a singular ;;; value decomposition given that one has an lu-decomposition in hand. ;;; The approximation available from the LU may good enough for the purpose ;;; at hand. ;;; ;;; Another means of saving calculation costs is by caching decompositions ;;; directly on the matrix. ;;; So in addition to calculating the ``foo-decomposition'' for a matrix A, ;;; (foo-of A) will also cache the returned instance on A. ;;; ;;; This caching facility has been achieved by mixing the class ;;; ;;; decomposition-mixin ;;; ;;; into the class matrix. That is the class matrix is a subclass ;;; of the class decomposition-mixin (as well as other classes). ;;; ;;; Decomposition-mixins maintain a table of cached decompositions. ;;; When a decomposition is requested, the table is first consulted. ;;; If the decomposition has already been stored, it is returned. ;;; If not, it is calculated and stored before being returned. ;;; ;;; This saves repeated calculation but it does have the potentially ;;; *dangerous* consequence that if the matrix elements are changed ;;; *after* the decomposition has been calculated, then the decomposition ;;; will no longer be that of the matrix! ;;; In this case, the decompositions should be cleared after the matrix ;;; has been changed. ;;; The function which does this is clear-decompositions. ;;; ;;; For example, suppose we have X (<- X (array (iseq 16) :dimensions '(4 4))) ;;; and calculate its' LU decomposition. (<- lud (lud-of X)) ;;; Now we change the (0 0) element of X from (eref X 0 0) ;;; to 30. (<- (eref X 0 0) 30) ;;; If we ask for the lu decomposition of X we will get the old one which will ;;; now be incorrect. (eq lud (lud-of X)) ;;; So we first (clear-decompositions X) ;;; and now (eq lud (lud-of X)) ;;; is false. Future requests for decompositions of X will be correct. ;;; ;;; In the following sections we only briefly illustrate the particular ;;; decompositions; more detailed information on each is given in separate ;;; files. ;;; To illustrate them, we will need the following matrices: ;;; (<- rect-X (array (iseq 40) :dimensions '(10 4))) (<- square-X (array (iseq 16) :dimensions '(4 4))) (<- sym-X (.* (tp rect-X) rect-X)) (<- random-X (array (random-uniform :n 16) :dimensions '(4 4))) (<- rand-sym-X (.* (tp random-X) random-X)) ;;; And some y vectors for solving equations. (<- y10 (random-gaussian :n 10)) (<- y4 (random-gaussian :n 4)) ;;; ;;; \subsection 3.1 LU Decomposition. ;;; ;;; The lu (lower upper triangular) decomposition of square real matrix. ;;; This decomposition is discussed in greater detail in (edit-file "eg:Arrays;Matrices;Decompositions;lu.lsp") ;;; Here we only illustrate the functions described in the introductory ;;; section. (lud-of square-X) (lud-of sym-X) (lud-of random-X) ;;; And you can save it. (<- lud (lud-of square-X)) ;;; Now square-X is not a full rank matrix. This is reflected in ;;; the rank-of the lud (rank-of lud) (rank-of lud :tolerance 1E-10) (condition-number-of lud) (determinant lud) ;;; Calculating the inverse would result in error. ;;; Instead, let's work with the full rank matrix random-X. (<- lud1 (lud-of random-X)) (rank-of lud1) (rank-of lud1 :tolerance 1E-10) (condition-number-of lud1) (determinant lud1) ;;; And so the inverse can be calculated (inverse lud1) ;;; and used. (.* (inverse lud1) random-X) ;;; Note that this the explicit inverse and so not as reliable as calculating ;;; the inverse of random-X. (.* (inverse random-X) random-X) ;;; ;;; And we can force the solution of the equation Ab=c ;;; to be via the LU decomposition (solve lud1 y4) ;;; which returns b where A is random-X and c is y4. ;;; ;;; \subsection 3.2 Cholesky Decomposition. ;;; ;;; The Cholesky (triangular) decomposition of square symmetric real matrix. ;;; This is mathematically equivalent to the LU when L = tp(U). ;;; This decomposition is discussed in greater detail in (edit-file "eg:Arrays;Matrices;Decompositions;cholesky.lsp") ;;; Here we only illustrate the functions described in the introductory ;;; section. ;;; ;;; First we need a full rank symmetric matrix. (<- full-rank-sym-x (.* (tp random-X) random-X)) ;;; and its' Cholesky decomposition. (setf chol (cholesky-of full-rank-sym-x)) ;;; (rank-of chol) (condition-number-of chol) (determinant chol) (inverse chol) (.* full-rank-sym-x (inverse chol)) ;;; For less than full rank matrices, pivoting is an option (setf c-sym-piv (cholesky-of sym-x :pivot T)) (rank-of c-sym-piv :tolerance 1E-5) (condition-number-of c-sym-piv) (determinant c-sym-piv) ;;; ;;; \subsection 3.3 Singular Value Decomposition. ;;; ;;; The singular value decomposition of an arbitrary real matrix. ;;; This decomposition is discussed in greater detail in (edit-file "eg:Arrays;Matrices;Decompositions;svd.lsp") ;;; Here we only illustrate the functions described in the introductory ;;; section. ;;; (svd-of rect-X) (svd-of square-X) (svd-of sym-X) (<- svd (svd-of rect-X)) ;;; The applicable functions (condition-number-of svd) (rank-of svd) (rank-of svd :tolerance 1E-10) ;;; Important note: ;;; svd is the decomposition used for the matrix versions of ;;; these functions. (condition-number-of rect-X) (rank-of rect-X :tolerance 1E-10) ;;; \subsection 3.4 QR Decomposition. ;;; ;;; This decomposition is discussed in greater detail in (edit-file "eg:Arrays;Matrices;Decompositions;qr.lsp") ;;; Here we only illustrate the functions described in the introductory ;;; section. ;;; ;;; The QR decomposition of an arbitrary real matrix. (qrd-of rect-X) (qrd-of square-X) (qrd-of sym-X) (<- qrd (qrd-of rect-X)) ;;; Rank (rank-of qrd) (rank-of qrd :tolerance 1.0E-10) ;;; And solving Ab = c when (nrows A) > (ncols A) will produce ;;; the least-squares solution of b (solve qrd y10) ;;; Note that in this instance solve returns two values. The first is the ;;; least-squares solution vector; the second is an instance of a qr-solution ;;; object which contains more complete information on the least-squares solution. ;;;
10,934
Common Lisp
.l
270
37.718519
83
0.651414
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
061fe409bd62c42946232f9f4f5561de0640e5971af28d092cef4d0da31d1c5c
33,040
[ -1 ]
33,041
section.lsp
rwoldford_Quail/contributed/rotation-and-section/section.lsp
(in-package wb) (defun align-z-axis-to-axis (data x y z) (let* ((length (sqrt (+ (* x x) (* y y) (* z z)))) (phi (acos (/ z length))) (theta (if (eq (round (* phi 1000)) 0) 0 (asin (/ y (* length (sin phi)))))) (zrot (make-instance '3d-z-rotate :angle theta)) (const (/ (* x x) (+ (* x x) (* y y)))) (axisrot (make-instance '3d-axis-rotate :x-component (sqrt (- 1 const)) :y-component (sqrt const) :z-component 0 :angle phi))) (print (list "phi" phi "theta" theta)) (apply-transform axisrot (apply-transform zrot data)))) (defun sort-data-by-z (array) (let* ((the-list (loop for i from 0 to (1- (first (array-dimensions array))) collect (list i (aref array i 2))))) (setf the-list (sort the-list #'< :key #'second)) (qk::sel array (mapcar #'first the-list) :shape t))) (defun z-section (data canvas &key (steps 10) (plot-rgn (make-region 0 0 (canvas-width canvas) (canvas-height canvas)))) (let* ((temp-data (scale-data-for-window (sort-data-by-z data) (min (aref plot-rgn 2) (aref plot-rgn 3)))) (last (1- (first (array-dimensions temp-data)))) (min (aref temp-data 0 2)) (max (aref temp-data last 2)) (inc (/ (- max min) steps)) oldmin oldmax (newmin 0) (newmax (loop for i from 0 to last while (< (aref temp-data i 2) (+ min inc)) finally (return i)))) ;(canvas-clear canvas) ;(canvas-invert canvas) (set-canvas-pen-mode canvas :patxor) (apply-transform! (make-instance '2d-shift :x-shift (round (+ (aref plot-rgn 0) (/ (aref plot-rgn 2) 2))) :y-shift (round (+ (aref plot-rgn 1) (/ (aref plot-rgn 3) 2)))) temp-data) (with-focused-canvas canvas (loop for i from 2 to steps do (progn (loop for j from newmin to (1- newmax) do (canvas-draw-point (aref temp-data j 0) (aref temp-data j 1) canvas)) (setf oldmin newmin oldmax newmax) (setf newmin (1+ oldmax) newmax (loop for j from newmin to last while (< (aref temp-data j 2) (+ min (* i inc))) finally (return j))) (loop for i from 0 to 300000 do ()) (loop for j from oldmin to (1- oldmax) do (canvas-draw-point (aref temp-data j 0) (aref temp-data j 1) canvas))))))) (defun z-section-persp (data canvas &key (steps 30) (plot-rgn (make-region 0 0 (canvas-width canvas) (canvas-height canvas)))) (let* ((temp-data (scale-data-for-window (sort-data-by-z data) (min (aref plot-rgn 2) (aref plot-rgn 3)))) (last (1- (first (array-dimensions temp-data)))) (min (aref temp-data 0 2)) (max (aref temp-data last 2)) (inc (/ (- max min) steps)) (l0 0) (l1 0) (l2 0) (l3 0) (l4 (loop for i from 0 to last while (< (aref temp-data i 2) (+ min inc)) finally (return i)))) ;(canvas-clear canvas) ;(canvas-invert canvas) (set-canvas-pen-mode canvas :patxor) (apply-transform! (make-instance '2d-shift :x-shift (round (+ (aref plot-rgn 0) (/ (aref plot-rgn 2) 2))) :y-shift (round (+ (aref plot-rgn 1) (/ (aref plot-rgn 3) 2)))) temp-data) (with-focused-canvas canvas (loop for i from 2 to steps do (progn (loop for j from l1 to (1- l2) do (canvas-draw-point (aref temp-data j 0) (aref temp-data j 1) canvas)) (loop for j from l2 to (1- l3) do (canvas-draw-filled-circle (aref temp-data j 0) (aref temp-data j 1) 1 canvas)) (loop for j from l3 to (1- l4) do (canvas-draw-filled-circle (aref temp-data j 0) (aref temp-data j 1) 2 canvas)) (setf l0 l1 l1 l2 l2 l3 l3 l4 l4 (loop for j from l3 to last while (< (aref temp-data j 2) (+ min (* i inc))) finally (return j))) ;(print (list l0 l1 l2 l3 l4)) (loop for wait from 0 to 200000 do ()) (loop for j from l0 to (1- l1) do (canvas-draw-point (aref temp-data j 0) (aref temp-data j 1) canvas)) (loop for j from l1 to (1- l2) do (canvas-draw-filled-circle (aref temp-data j 0) (aref temp-data j 1) 1 canvas)) (loop for j from l2 to (1- l3) do (canvas-draw-filled-circle (aref temp-data j 0) (aref temp-data j 1) 2 canvas)))))))
6,471
Common Lisp
.l
139
25.719424
71
0.386403
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3df91495cb744f53ba53fb1ba19a982dec9d699397bb568305f6b951641ff120
33,041
[ -1 ]
33,042
commonly-used-stuff.lsp
rwoldford_Quail/contributed/rotation-and-section/commonly-used-stuff.lsp
(defun sort-data-by-col (array col) (let* ((the-list (loop for i from 0 to (1- (first (array-dimensions array))) collect (list i (aref array i col))))) (setf the-list (sort the-list #'< :key #'second)) (qk::sel array (mapcar #'first the-list) :shape t))) (defun array-mean (array col) (/ (loop for i from 0 to (- (first (array-dimensions array)) 1) sum (aref array i col)) (first (array-dimensions array)))) (defun array-median (array col) (let* ((length (first (array-dimensions array))) (sorted-col (sort (loop for i from 0 to (1- length) collect (aref array i col)) #'<))) (print (list length sorted-col)) (if (oddp length) (elt sorted-col (/ (1- length) 2)) (/ (+ (elt sorted-col (/ length 2)) (elt sorted-col (1- (/ length 2)))) 2)))) (defun array-range (array col) (let ((min (aref array 0 col)) (max (aref array 0 col))) (loop for i from 0 to (1- (first (array-dimensions array))) do (let ((num (aref array i col))) (if (> min num) (setq min num)) (if (< man num) (setq max num)))) (- max min))) (defun array-variance (array col) (let ((mean (array-mean array col)) (n (1- (first (array-dimensions array))))) (/ (loop for i from 0 to n sum (expt (- (aref array i col) mean) 2)) n))) (defun scale-array-column! (array col scale-factor) (loop for i from 0 to (1- (first (array-dimensions array))) do (setf (aref array i col) (* (aref array i col) scale-factor)))) (defun scale-array-column-by-variance! (array col) (scale-array-column! array col (/ 1 (sqrt (array-variance array col))))) (defun scale-array-columns-by-variance! (array) (loop for col from 0 to (1- (second (array-dimensions array))) do (scale-array-column! array col (/ 1 (sqrt (array-variance array col)))))) (defun scale-data-for-window (data size) "scales 3-d data so that when rotated it will always fit in a window~ with minimum dimension SIZE" (let* ((dim (array-dimensions data)) (centered-data (make-array dim)) d) (copy-contents data centered-data) (apply-transform! (make-instance '3d-shift :x-shift (- (array-mean data 0)) :y-shift (- (array-mean data 1)) :z-shift (- (array-mean data 2))) centered-data) (setf d (/ size (sqrt (apply #'max (loop for i from 0 to (- (first dim) 1) collect (loop for j from 0 to (- (second dim) 1) sum (expt (aref centered-data i j) 2)) ))) 2)) (loop for i from 0 to (- (first dim) 1) do (loop for j from 0 to (- (second dim) 1) do (setf (aref centered-data i j) (round (* (aref centered-data i j) d))))) centered-data)) (defun copy-contents (source dest) (loop for i from 0 to (- (first (array-dimensions source)) 1) do (loop for j from 0 to (- (second (array-dimensions source)) 1) do (setf (aref dest i j) (aref source i j)))))
3,436
Common Lisp
.l
72
35.722222
89
0.526711
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d115b13e6cc192b60d13c34c7796c627cadabf2f101f8c798affacb4cb073f8f
33,042
[ -1 ]
33,043
integer-affine-trans.lsp
rwoldford_Quail/contributed/rotation-and-section/integer-affine-trans.lsp
;;; A modified version of affinetrans.lisp. It includes more specific subclasses, ;;; such as: ;;; ;;; affine-transform---- 2d-affine----- 2d-shift ;;; \ ;;; \_ 3d-affine----- 3d-rotate------ 3d-x-rotate ;;; | | ;;; |----- 3d-scale |- 3d-y-rotate ;;; | | ;;; |_____ 3d-shift |_ 3d-z-rotate (in-package :wb) (defclass affine-transform () ((dimension :initarg :dimension :accessor dimension-of :documentation "The true dimension of the transform, (n * n)") (affine :initarg :affine :accessor matrix-of :documentation "an (n+1) *(n+1) array of reals, first n rows and colums represent the transformation, the last column represents the location shift") ) (:documentation "Affine transformations for viewing 2 and 3 dimensional objects. See Foley and Van Dam for reference. Note the transforms here operate on columns whereas those in F+VD operate on row vectors" )) (defclass 2d-affine (affine-transform) ((affine :documentation "a 3 by 3 array of reals, first 2 rows and colums represent the transformation, the last column represents the location shift") (x-function :accessor x-function :documentation "function applied to object to retrieve its x location") (y-function :accessor y-function :documentation "function applied to object to retrieve its y location") (dimension :initform 2 :documentation " the true dimension of the transform, 2 by 2"))) (defclass 3d-affine (affine-transform) ((affine :documentation "a 4 by 4 array of reals, first 3 rows and colums represent the transformation, the last column represents the location shift") (x-function :accessor x-function :documentation "function applied to object to retrieve its x location") (y-function :accessor y-function :documentation "function applied to object to retrieve its y location") (z-function :accessor z-function :documentation "function applied to object to retrieve its z location") (dimension :initform 3 :documentation " the true dimension of the transform, 3 by 3"))) (defclass 2d-shift (2d-affine) ((x-shift :initarg :x-shift :accessor x-shift-of :documentation "The translation applied to the x-axis") (y-shift :initarg :y-shift :accessor y-shift-of :documentation "The translation applied to the y-axis"))) (defclass 3d-rotate (3d-affine) ((angle :initarg :angle :accessor angle-of :documentation "The angle of rotation"))) (defclass 3d-axis-rotate (3d-rotate) ((x-component :initarg :x-component :accessor x-component-of :documentation "The x-component of the arbitrary axis (length=1)") (y-component :initarg :y-component :accessor y-component-of :documentation "The y-component of the arbitrary axis (length=1)") (z-component :initarg :z-component :accessor z-component-of :documentation "The z-component of the arbitrary axis (length=1)"))) (defclass 3d-x-rotate (3d-rotate) ()) (defclass 3d-y-rotate (3d-rotate) ()) (defclass 3d-z-rotate (3d-rotate) ()) (defclass 3d-shift (3d-affine) ((x-shift :initarg :x-shift :accessor x-shift-of :documentation "The translation applied to the x-axis") (y-shift :initarg :y-shift :accessor y-shift-of :documentation "The translation applied to the y-axis") (z-shift :initarg :z-shift :accessor z-shift-of :documentation "The translation applied to the z-axis"))) (defclass 3d-scale (3d-affine) ((x-scale :initarg :x-scale :accessor x-scale-of :documentation "The scaling applied to the x-axis") (y-scale :initarg :x-scale :accessor y-scale-of :documentation "The scaling applied to the y-axis") (z-scale :initarg :z-scale :accessor z-scale-of :documentation "The scaling applied to the z-axis"))) (defmethod apply-transform ((self 2d-shift) (a array)) "apply a shift transform to a data array. Observations correspond to rows~ This routine returns a *new* array. Integer calculations are used, and ~ an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 2) :initial-contents (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (list (+ (aref a i 0) (x-shift-of self)) (+ (aref a i 1) (y-shift-of self)))))) (defmethod apply-transform ((self 3d-axis-rotate) (a array)) "rotate an array about an arbitrary axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine returns a *new* array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 3) :initial-contents (let* ((c (cos (angle-of self))) (s (sin (angle-of self))) (u (- 1 c)) (xc (x-component-of self)) (yc (y-component-of self)) (zc (z-component-of self)) ) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((x (aref a i 0)) (y (aref a i 1)) (z (aref a i 2))) (list (round (+ (* x (+ (* u xc xc) c)) (* y (- (* u xc yc) (* s zc))) (* z (+ (* u xc zc) (* s yc))))) (round (+ (* x (+ (* u xc yc) (* s zc))) (* y (+ (* u yc yc) c)) (* z (- (* u yc zc) (* s xc))))) (round (+ (* x (- (* u xc zc) (* s yc))) (* y (+ (* u yc zc) (* s xc))) (* z (+ (* u zc zc) c)))))))))) (defmethod apply-transform ((self 3d-x-rotate) (a array)) "rotate an array about the x axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine returns a *new* array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 3) :initial-contents (let ((c (round (* 1024 (cos (angle-of self))))) (s (round (* 1024 (sin (angle-of self)))))) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((y (aref a i 1)) (z (aref a i 2))) (list (aref a i 0) (ash (- (* y c) (* z s)) -10) (ash (+ (* y s) (* z c)) -10))))))) (defmethod apply-transform ((self 3d-y-rotate) (a array)) "rotate an array about the y axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 3) :initial-contents (let ((c (round (* 1024 (cos (angle-of self))))) (s (round (* 1024 (sin (angle-of self)))))) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((x (aref a i 0)) (z (aref a i 2))) (list (ash (+ (* x c) (* z s)) -10) (aref a i 1) (ash (- (* z c) (* x s)) -10))))))) (defmethod apply-transform ((self 3d-z-rotate) (a array)) "rotate an array about the z axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 3) :initial-contents (let ((c (round (* 1024 (cos (angle-of self))))) (s (round (* 1024 (sin (angle-of self)))))) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((x (aref a i 0)) (y (aref a i 1))) (list (ash (- (* x c) (* y s)) -10) (ash (+ (* x s) (* y c)) -10) (aref a i 2))))))) (defmethod apply-transform ((self 3d-shift) (a array)) "shift an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 3) :initial-contents (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (list (+ (aref a i 0) (x-shift-of self)) (+ (aref a i 1) (y-shift-of self)) (+ (aref a i 2) (z-shift-of self)))))) (defmethod apply-transform ((self 3d-scale) (a array)) "Scale an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (make-array (list (first (array-dimensions a)) 3) :initial-contents (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (list (round (* (aref a i 0) (x-scale-of self))) (round (* (aref a i 1) (y-scale-of self))) (round (* (aref a i 2) (z-scale-of self))))))) ;--------------------------------------------------------------------------- ; ; the same routines as above, but ones that destructively change the contents ; of the arrays ; ;--------------------------------------------------------------------------- (defmethod apply-transform! ((self 2d-shift) (a array)) "apply a shift transform to a data array. Observations correspond to rows~ This routine destructively modifies the given array. Integer~ calculations are used, and an INTEGER ARRAY MUST BE GIVEN TO THIS ROUTINE!!!" (loop for i from 0 to (- (first (array-dimensions a)) 1) do (progn (incf (aref a i 0) (x-shift-of self)) (incf (aref a i 1) (y-shift-of self))))) (defmethod apply-transform! ((self 3d-x-rotate) (a array)) "rotate an array about the x axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given~ array. Integer calculations are used, and an INTEGER ARRAY MUST BE~ GIVEN TO THIS ROUTINE!!!" (let ((c (round (* 1024 (cos (angle-of self))))) (s (round (* 1024 (sin (angle-of self)))))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((y (aref a i 1)) (z (aref a i 2))) (setf (aref a i 1) (ash (- (* y c) (* z s)) -10)) (setf (aref a i 2) (ash (+ (* y s) (* z c)) -10)))))) (defmethod apply-transform! ((self 3d-y-rotate) (a array)) "rotate an array about the y axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Integer calculations are used, and an INTEGER ARRAY MUST BE~ GIVEN TO THIS ROUTINE!!!" (let ((c (round (* 1024 (cos (angle-of self))))) (s (round (* 1024 (sin (angle-of self)))))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((x (aref a i 0)) (z (aref a i 2))) (setf (aref a i 0) (ash (+ (* x c) (* z s)) -10)) (setf (aref a i 2) (ash (- (* z c) (* x s)) -10)))))) (defmethod apply-transform! ((self 3d-z-rotate) (a array)) "rotate an array about the z axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Integer calculations are used, and an INTEGER ARRAY MUST BE~ GIVEN TO THIS ROUTINE!!!" (let ((c (round (* 1024 (cos (angle-of self))))) (s (round (* 1024 (sin (angle-of self)))))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((x (aref a i 0)) (y (aref a i 1))) (setf (aref a i 0) (ash (- (* x c) (* y s)) -10)) (setf (aref a i 1) (ash (+ (* x s) (* y c)) -10)))))) (defmethod apply-transform! ((self 3d-shift) (a array)) "shift an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Integer calculations are used, and an INTEGER ARRAY MUST BE~ GIVEN TO THIS ROUTINE!!!" (loop for i from 0 to (- (first (array-dimensions a)) 1) do (progn (incf (aref a i 0) (x-shift-of self)) (incf (aref a i 1) (y-shift-of self)) (incf (aref a i 2) (z-shift-of self))))) (defmethod apply-transform! ((self 3d-scale) (a array)) "Scale an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Integer calculations are used, and an INTEGER ARRAY MUST BE~ GIVEN TO THIS ROUTINE!!!" (loop for i from 0 to (- (first (array-dimensions a)) 1) do (progn (setf (aref a i 0) (round (* (aref a i 0) (x-scale-of self)))) (setf (aref a i 1) (round (* (aref a i 1) (y-scale-of self)))) (setf (aref a i 2) (round (* (aref a i 2) (z-scale-of self)))))))
15,207
Common Lisp
.l
273
43.384615
195
0.548284
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7fc64ea834ae05416eca2d2ed1baa39038de07fec1eaef07690613fcd2473b93
33,043
[ -1 ]
33,044
make-data.lsp
rwoldford_Quail/contributed/rotation-and-section/make-data.lsp
(in-package :wb) (defun make-positive-data (n &key (x 100) (y 100) (z 100)) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list (abs (- (/ x 2) (random x))) (abs (- (/ y 2) (random y))) (abs (- (/ z 2) (random z))))))) (defun make-structured-data (n &key (x 50) (y 50) (z 50)) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list (round (* x (cos (/ (* 2 pi i) n)))) (round (* y (sin (/ (* 4 pi i) n)))) (round (* z (cos (/ (* 20 pi i) n)))))))) (defun make-data (n &key (x 100) (y 100) (z 100)) (let* ((a (+ 2 (random (- 200 2)))) (b (+ 2 (random (- 200 2)))) (c (min a b)) (d (max a b))) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list (round (if (< i c) (+ (/ x 4) (random (/ x 4))) (- (random (/ x 4)) (* x .75)))) (round (if (< i d) (+ (/ x 4) (random (/ y 4))) (- (random (/ x 4)) (* y .75)))) (round (- (/ z 2) (random b)))))))) (defun make-spherical-data (n r) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (let ((theta (- (* (random 1000) (/ pi 1000)) (/ pi 2))) (alpha (* (random 1000) (/ pi 500)))) (list (round (* r (cos theta) (cos alpha))) (round (* r (cos theta) (sin alpha))) (round (* r (sin theta)))))))) (defun make-half-spherical-data (n r) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (let ((theta (* (random 1000) (/ pi 1000))) (alpha (* (random 1000) (/ pi 500)))) (list (round (* r (cos theta) (cos alpha))) (round (* r (cos theta) (sin alpha))) (round (* r (sin theta)))))))) (defun make-cube-data (n l) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (let ((choice (random 3)) (c1 (random l)) (c2 (random l)) (c3 (random l))) (list (if (eq choice 0) (* (random 2) l) c1) (if (eq choice 1) (* (random 2) l) c2) (if (eq choice 2) (* (random 2) l) c3)))))) (defun make-data-on-axis (n x y z) (align-z-axis-to-axis (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list 0 0 (random (round (sqrt (+ (* x x) (* y y) (* z z)))))))) x y z))
3,283
Common Lisp
.l
60
33.116667
96
0.359526
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
83a39010e4481512d8f1e711a13c9575e3c8d210a47b9e1be5c52d00e749da6c
33,044
[ -1 ]
33,045
modified-affine-trans.lsp
rwoldford_Quail/contributed/rotation-and-section/modified-affine-trans.lsp
;;; A modified version of affinetrans.lisp. It includes more specific subclasses, ;;; such as: ;;; ;;; affine-transform---- 2d-affine----- 2d-shift ;;; \ ;;; \_ 3d-affine----- 3d-rotate------ 3d-x-rotate ;;; | | ;;; |----- 3d-scale |- 3d-y-rotate ;;; | | ;;; |_____ 3d-shift |_ 3d-z-rotate (in-package :wb) (defclass affine-transform () ((dimension :initarg :dimension :accessor dimension-of :documentation "The true dimension of the transform, (n * n)") (affine :initarg :affine :accessor matrix-of :documentation "an (n+1) *(n+1) array of reals, first n rows and colums represent the transformation, the last column represents the location shift") ) (:documentation "Affine transformations for viewing 2 and 3 dimensional objects. See Foley and Van Dam for reference. Note the transforms here operate on columns whereas those in F+VD operate on row vectors" )) (defclass 2d-affine (affine-transform) ((affine :documentation "a 3 by 3 array of reals, first 2 rows and colums represent the transformation, the last column represents the location shift") (x-function :accessor x-function :documentation "function applied to object to retrieve its x location") (y-function :accessor y-function :documentation "function applied to object to retrieve its y location") (dimension :initform 2 :documentation " the true dimension of the transform, 2 by 2"))) (defclass 3d-affine (affine-transform) ((affine :documentation "a 4 by 4 array of reals, first 3 rows and colums represent the transformation, the last column represents the location shift") (x-function :accessor x-function :documentation "function applied to object to retrieve its x location") (y-function :accessor y-function :documentation "function applied to object to retrieve its y location") (z-function :accessor z-function :documentation "function applied to object to retrieve its z location") (dimension :initform 3 :documentation " the true dimension of the transform, 3 by 3"))) (defclass 2d-shift (2d-affine) ((x-shift :initarg :x-shift :accessor x-shift-of :documentation "The translation applied to the x-axis") (y-shift :initarg :y-shift :accessor y-shift-of :documentation "The translation applied to the y-axis"))) (defclass 3d-rotate (3d-affine) ((angle :initarg :angle :accessor angle-of :documentation "The angle of rotation"))) (defclass 3d-axis-rotate (3d-rotate) ((x-component :initarg :x-component :accessor x-component-of :documentation "The x-component of the arbitrary axis (length=1)") (y-component :initarg :y-component :accessor y-component-of :documentation "The y-component of the arbitrary axis (length=1)") (z-component :initarg :z-component :accessor z-component-of :documentation "The z-component of the arbitrary axis (length=1)"))) (defclass 3d-x-rotate (3d-rotate) ()) (defclass 3d-y-rotate (3d-rotate) ()) (defclass 3d-z-rotate (3d-rotate) ()) (defclass 3d-shift (3d-affine) ((x-shift :initarg :x-shift :accessor x-shift-of :documentation "The translation applied to the x-axis") (y-shift :initarg :y-shift :accessor y-shift-of :documentation "The translation applied to the y-axis") (z-shift :initarg :z-shift :accessor z-shift-of :documentation "The translation applied to the z-axis"))) (defclass 3d-scale (3d-affine) ((x-scale :initarg :x-scale :accessor x-scale-of :documentation "The scaling applied to the x-axis") (y-scale :initarg :x-scale :accessor y-scale-of :documentation "The scaling applied to the y-axis") (z-scale :initarg :z-scale :accessor z-scale-of :documentation "The scaling applied to the z-axis"))) (defmethod apply-transform ((self 2d-shift) (a array)) "apply a shift transform to a data array. Observations correspond to rows~ This routine returns a *new* array" (make-array (list (first (array-dimensions a)) 2) :initial-contents (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (list (+ (aref a i 0) (x-shift-of self)) (+ (aref a i 1) (y-shift-of self)))))) (defmethod apply-transform ((self 3d-axis-rotate) (a array)) "rotate an array about an arbitrary axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine returns a *new* array." (make-array (list (first (array-dimensions a)) 3) :initial-contents (let* ((c (cos (angle-of self))) (s (sin (angle-of self))) (u (- 1 c)) (xc (x-component-of self)) (yc (y-component-of self)) (zc (z-component-of self)) ) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((x (aref a i 0)) (y (aref a i 1)) (z (aref a i 2))) (list (+ (* x (+ (* u xc xc) c)) (* y (- (* u xc yc) (* s zc))) (* z (+ (* u xc zc) (* s yc)))) (+ (* x (+ (* u xc yc) (* s zc))) (* y (+ (* u yc yc) c)) (* z (- (* u yc zc) (* s xc)))) (+ (* x (- (* u xc zc) (* s yc))) (* y (+ (* u yc zc) (* s xc))) (* z (+ (* u zc zc) c))))))))) (defmethod apply-transform ((self 3d-x-rotate) (a array)) "rotate an array about the x axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine returns a *new* array." (make-array (list (first (array-dimensions a)) 3) :initial-contents (let ((c (cos (angle-of self))) (s (sin (angle-of self)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((y (aref a i 1)) (z (aref a i 2))) (list (aref a i 0) (round (- (* y c) (* z s))) (round (+ (* y s) (* z c))))))))) (defmethod apply-transform ((self 3d-y-rotate) (a array)) "rotate an array about the y axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array." (make-array (list (first (array-dimensions a)) 3) :initial-contents (let ((c (cos (angle-of self))) (s (sin (angle-of self)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((x (aref a i 0)) (z (aref a i 2))) (list (round (+ (* x c) (* z s))) (aref a i 1) (round (- (* z c) (* x s))))))))) (defmethod apply-transform ((self 3d-z-rotate) (a array)) "rotate an array about the z axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array." (make-array (list (first (array-dimensions a)) 3) :initial-contents (let ((c (cos (angle-of self))) (s (sin (angle-of self)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (let ((x (aref a i 0)) (y (aref a i 1))) (list (round (- (* x c) (* y s))) (round (+ (* x s) (* y c))) (aref a i 2))))))) (defmethod apply-transform ((self 3d-shift) (a array)) "shift an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array." (make-array (list (first (array-dimensions a)) 3) :initial-contents (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (list (+ (aref a i 0) (x-shift-of self)) (+ (aref a i 1) (y-shift-of self)) (+ (aref a i 2) (z-shift-of self)))))) (defmethod apply-transform ((self 3d-scale) (a array)) "Scale an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This returns a *new* array." (make-array (list (first (array-dimensions a)) 3) :initial-contents (loop for i from 0 to (- (first (array-dimensions a)) 1) collect (list (round (* (aref a i 0) (x-scale-of self))) (round (* (aref a i 1) (y-scale-of self))) (round (* (aref a i 2) (z-scale-of self))))))) ;--------------------------------------------------------------------------- ; ; the same routines as above, but ones that destructively change the contents ; of the arrays ; ;--------------------------------------------------------------------------- (defmethod apply-transform! ((self 2d-shift) (a array)) "apply a shift transform to a data array. Observations correspond to rows~ This routine destructively modifies the given array. Floating point~ calculations are used." (loop for i from 0 to (- (first (array-dimensions a)) 1) do (progn (incf (aref a i 0) (x-shift-of self)) (incf (aref a i 1) (y-shift-of self))))) (defmethod apply-transform! ((self 3d-x-rotate) (a array)) "rotate an array about the x axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given~ array. Floating point calculations are used." (let ((c (cos (angle-of self))) (s (sin (angle-of self)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((y (aref a i 1)) (z (aref a i 2))) (setf (aref a i 1) (- (* y c) (* z s))) (setf (aref a i 2) (+ (* y s) (* z c))))))) (defmethod apply-transform! ((self 3d-y-rotate) (a array)) "rotate an array about the y axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Floating point calculations are used." (let ((c (cos (angle-of self))) (s (sin (angle-of self)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((x (aref a i 0)) (z (aref a i 2))) (setf (aref a i 0) (+ (* x c) (* z s))) (setf (aref a i 2) (- (* z c) (* x s))))))) (defmethod apply-transform! ((self 3d-z-rotate) (a array)) "rotate an array about the z axis through a given angle, specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Floating point calculations are used." (let ((c (cos (angle-of self))) (s (sin (angle-of self)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((x (aref a i 0)) (y (aref a i 1))) (setf (aref a i 0) (- (* x c) (* y s))) (setf (aref a i 1) (+ (* x s) (* y c))))))) (defmethod apply-transform! ((self 3d-shift) (a array)) "shift an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Floating point calculations are used." (loop for i from 0 to (- (first (array-dimensions a)) 1) do (progn (incf (aref a i 0) (x-shift-of self)) (incf (aref a i 1) (y-shift-of self)) (incf (aref a i 2) (z-shift-of self))))) (defmethod apply-transform! ((self 3d-scale) (a array)) "Scale an array along all three axes specified~ by the transformation. Observations in the array correspons to rows~ in the order x,y,z. This routine destructively modifies the given array.~ Floating point calculations are used." (loop for i from 0 to (- (first (array-dimensions a)) 1) do (progn (setf (aref a i 0) (round (* (aref a i 0) (x-scale-of self)))) (setf (aref a i 1) (round (* (aref a i 1) (y-scale-of self)))) (setf (aref a i 2) (round (* (aref a i 2) (z-scale-of self)))))))
13,961
Common Lisp
.l
261
40.858238
195
0.536571
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
92ce42b3017825dec23285c594b7ba6da8c95f1db8774f9b60fa864c22ff2cea
33,045
[ -1 ]
33,046
load-plain-spin.lsp
rwoldford_Quail/contributed/rotation-and-section/load-plain-spin.lsp
(in-package :wb) (load "Devel:Quail:contributed:rotation-and-section:commonly-used-stuff.lisp") (load "Devel:Quail:contributed:rotation-and-section:make-data.lisp") (load "Devel:Quail:contributed:rotation-and-section:integer-affine-trans.lisp") (load "Devel:Quail:contributed:rotation-and-section:spin:wb-extensions") (load "Devel:Quail:contributed:rotation-and-section:section.lisp") (load "Devel:Quail:contributed:rotation-and-section:spin:spin-with-affine-trans.lisp")
477
Common Lisp
.l
7
66.428571
86
0.802548
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fa604e39a539291018b89eac7e220ad4cf8f9b2b6a6fbffda3139e428de7b0a5
33,046
[ -1 ]
33,047
spin-at&bm.lsp
rwoldford_Quail/contributed/rotation-and-section/spin-with-bitmap&at/spin-at&bm.lsp
(in-package wb) (defun user-select-direction (a b c) (let ((r (random 3))) (cond ((eq r 0) a) ((eq r 1) b) (t c)))) (defun rotate-point-cloud (data c &key (increment (/ pi 30)) (plot-rgn (make-region 0 0 (- (canvas-width c) (mod (canvas-width c) 8)) (canvas-height c)))) "rotates a point-cloud using bitmaps. The point cloud is in array form~ with each row an x,y,z observation. This array must be integer!!" (let* ((scaled-data (scale-data-for-window data (min (aref plot-rgn 2) (aref plot-rgn 3)))) (old-data (make-array (array-dimensions data))) (new-data (make-array (array-dimensions data))) (location-trans (make-instance '2d-shift :x-shift (round (+ (aref plot-rgn 0) (/ (aref plot-rgn 2) 2))) :y-shift (round (+ (aref plot-rgn 1) (/ (aref plot-rgn 3) 2))))) (xrot (make-instance '3d-x-rotate :angle 0)) (yrot (make-instance '3d-y-rotate :angle 0)) (zrot (make-instance '3d-z-rotate :angle 0)) rot temp (bm (make-bitmap :width (- (canvas-width c) (mod (canvas-width c) 8)) :height (canvas-height c) :raw-bitmap (let ((bm (qd::make-bitmap 0 0 (- (canvas-width c) (mod (canvas-width c) 8) 1) (- (canvas-height c) 1)))) (with-bitmap-as-window bm w) bm) ))) (canvas-clear c) ;(canvas-invert c) ;(set-canvas-pen-mode c :patxor) (setf rot (user-select-direction xrot yrot zrot)) (copy-contents scaled-data old-data) (apply-transform! location-trans old-data) (plot-points-on-bitmap old-data bm) (canvas-bitblt bm c) (erase-points-on-bitmap old-data bm) (if (listen) (read)) (loop until (read-char-no-hang) do (progn (loop until (or (eq (random 20) 1) (read-char-no-hang)) do (progn (setf (angle-of rot) (+ (angle-of rot) increment)) (copy-contents scaled-data new-data) (apply-transform! rot new-data) (apply-transform! location-trans new-data) (plot-points-on-bitmap new-data bm) (canvas-bitblt bm c) (erase-points-on-bitmap new-data bm) (setf temp old-data) (setf old-data new-data) (setf new-data temp))) (apply-transform! rot scaled-data) (setf rot (user-select-direction xrot yrot zrot)) (setf (angle-of rot) 0) ))))
3,175
Common Lisp
.l
65
30.123077
105
0.447021
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
df0a4abda495eb7171e66a9daccec5f44a081f3ab44515882edcad3eb1ac3a1c
33,047
[ -1 ]
33,048
plot-directly-on-bitmap.lsp
rwoldford_Quail/contributed/rotation-and-section/spin-with-bitmap&at/plot-directly-on-bitmap.lsp
(in-package :wb) ;;; The following lines are just for test purposes, and are consequently ;;; commented out #| (setf bm (make-box-bitmap (- (canvas-width c) (mod (canvas-width c) 8)) (canvas-height c))) (setf bm (make-bitmap :width (1+ (- (canvas-width c) (mod (canvas-width c) 8))) :height (1+ (canvas-height c)) :raw-bitmap (let ((bm (qd::make-bitmap 0 0 (- (canvas-width c) (mod (canvas-width c) 8)) (canvas-height c)))) (with-bitmap-as-window bm w) bm) )) |# (defun plot-points-on-bitmap (array bm) "Plot points onto a bitmap by putting bytes into memory. This can be VERY~ DANGEROUS if you miss. points outside the bitmap's ploting region should~ be caught by the mod function, but will wrap around. A bitmap with a~ width divisible by 8 is required, as each byte is 8 adjacent points.~ The array must have observations in the rows, and the first two~ columns are plotted." (let* ((w (rref (bitmap-raw-bitmap bm) bitmap.rowbytes)) (h (bitmap-height bm)) (hminus2 (- h 2)) (max (1- (* w h))) (ptr (rref (bitmap-raw-bitmap bm) bitmap.baseaddr)) x number offset) (loop for i from 0 to (- (first (array-dimensions array)) 1) do (progn (setf x (aref array i 0)) (setf number (choose-number (mod x 8))) (setf offset (mod (+ (* (- hminus2 (aref array i 1)) w) (ash x -3)) max)) ;(print (list "plot" (aref array i 0) (aref array i 1) w h ptr number offset max)) (%put-byte ptr (logior (%get-unsigned-byte ptr offset) number) offset) )))) (defun erase-points-on-bitmap (array bm) "erase points from a bitmap using a simiar method to plot-points-on-bitmap~ The ENTIRE BYTE with the point is erased for added speed. The array must~ have observations in the rows, and the first two columns are plotted." (let* ((w (rref (bitmap-raw-bitmap bm) bitmap.rowbytes)) (h (bitmap-height bm)) (hminus2 (- h 2)) (max (1- (* w h))) (ptr (rref (bitmap-raw-bitmap bm) bitmap.baseaddr)) x offset) (loop for i from 0 to (- (first (array-dimensions array)) 1) do (progn (setf x (aref array i 0)) (setf offset (mod (+ (* (- hminus2 (aref array i 1)) w) (ash x -3)) max)) ;(print (list "erase" (aref array i 0) (aref array i 1) w h ptr 0 offset)) (%put-byte ptr 0 offset) )))) (defun choose-number (n) "the fastest way to calclate the byte representing a point in the ith~ position. This is used by plot-points-on-bitmap" (cond ((eq n 0) 128) ((eq n 1) 64) ((eq n 2) 32) ((eq n 3) 16) ((eq n 4) 8) ((eq n 5) 4) ((eq n 6) 2) (t 1)))
3,175
Common Lisp
.l
69
33.927536
98
0.525653
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b5a2a536df00711efab15cb42071fe7a9a99082e547ade72accd94e15b116cc6
33,048
[ -1 ]
33,049
spin.lsp
rwoldford_Quail/contributed/rotation-and-section/spin/spin.lsp
(in-package wb) (defun make-data (n &key (x 100) (y 100) (z 100)) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list (- (/ x 2) (random x)) (- (/ y 2) (random y)) (- (/ z 2) (random z)))))) (defun make-structured-data (n &key (x 50) (y 50) (z 50)) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list (* x (cos (/ (* 2 pi i) n))) (* y (sin (/ (* 4 pi i) n))) (* z (cos (/ (* 20 pi i) n))))))) (defun make-data (n &key (x 100) (y 100) (z 100)) (let* ((a (+ 2 (random (- n 2)))) (b (+ 2 (random (- n 2)))) (c (min a b)) (d (max a b))) (make-array (list n 3) :initial-contents (loop for i from 1 to n collect (list (if (< i c) (+ (/ x 4) (random (/ x 4))) (- (random (/ x 4)) (* x .75))) (if (< i d) (+ (/ x 4) (random (/ y 4))) (- (random (/ x 4)) (* y .75))) (- (/ z 2) (random b))))))) (defun zrot (a angle) (let ((new-array (make-array (array-dimensions a)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((x (aref a i 0)) (y (aref a i 1)) (c (cos angle)) (s (sin angle))) (setf (aref new-array i 0) (- (* x c) (* y s))) (setf (aref new-array i 1) (+ (* y c) (* x s))))) new-array)) (defun yrot (a angle) (let ((new-array (make-array (array-dimensions a)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((x (aref a i 0)) (z (aref a i 2)) (c (cos angle)) (s (sin angle))) (setf (aref new-array i 0) (+ (* x c) (* z s))) (setf (aref new-array i 1) (aref a i 1)))) new-array)) (defun xrot (a angle) (let ((new-array (make-array (array-dimensions a)))) (loop for i from 0 to (- (first (array-dimensions a)) 1) do (let ((y (aref a i 1)) (z (aref a i 2)) (c (cos angle)) (s (sin angle))) (setf (aref new-array i 0) (aref a i 0)) (setf (aref new-array i 1) (- (* y c) (* z s))))) new-array)) (defun make-current-trans (angle direction) (make-array '(3 3) :initial-contents (cond ((eq direction :z) (list (list (cos angle) (sin angle) 0) (list (- (sin angle)) (cos angle) 0) (list 0 0 1))) ((eq direction :y) (list (list (cos angle) 0 (- (sin angle))) (list 0 1 0) (list (sin angle) 0 (cos angle)))) ((eq direction :x) (list (list 1 0 0) (list 0 (cos angle) (sin angle)) (list 0 (- (sin angle)) (cos angle))))))) (defun user-select-direction () (let ((r (random 3))) (cond ((eq r 0) :x) ((eq r 1) :y) (t :x)))) (defun rotate-point-cloud (data c &key (increment (/ pi 30))) (let* ((temp-data data) (old-data temp-data) (new-data temp-data) (direction (user-select-direction)) direction-fn (angle 0)) (canvas-invert c) (set-canvas-pen-mode c :patxor) (with-focused-canvas c (loop for i from 0 to (- (first (array-dimensions old-data)) 1) do (canvas-draw-point (round (+ 100 (aref old-data i 0))) (round (+ 100 (aref old-data i 1))) c))) (if (listen) (read)) (loop until (read-char-no-hang) do (progn (setf direction-fn (cond ((eq direction :x) #'xrot) ((eq direction :y) #'yrot) ((eq direction :z) #'zrot))) (loop until (eq (random 20) 1) do (progn (setf angle (+ angle increment)) (setf new-data (funcall direction-fn temp-data angle)) (with-focused-view c (loop for i from 0 to (- (first (array-dimensions old-data)) 1) do (progn (canvas-draw-point (round (+ 100 (aref old-data i 0))) (round (+ 100 (aref old-data i 1))) c) (canvas-draw-point (round (+ 100 (aref new-data i 0))) (round (+ 100 (aref new-data i 1))) c) )) ) (setf old-data new-data))) (setf temp-data (quail-user::z.* temp-data (make-current-trans angle direction))) (setf angle 0) (setf direction (user-select-direction)) )) (canvas-clear c)))
5,696
Common Lisp
.l
121
27.900826
92
0.376468
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8cc039869f1f2c5eb478184315ba2a52c47b4b405894ea62ca7e926e62f71a29
33,049
[ -1 ]
33,050
spin-with-affine-trans.lsp
rwoldford_Quail/contributed/rotation-and-section/spin/spin-with-affine-trans.lsp
(in-package wb) (defun user-select-direction (a b c) (let ((r (random 3))) (cond ((eq r 0) a) ((eq r 1) b) (t c)))) (defun rotate-point-cloud (data c &key (increment (/ pi 30)) (plot-rgn (make-region 0 0 (canvas-width c) (canvas-height c)))) "rotates a point-cloud using plotting traps. The point cloud is in array form~ with each row an x,y,z observation. This array must be integer!!" (let* ((scaled-data (scale-data-for-window data (min (aref plot-rgn 2) (aref plot-rgn 3)))) (old-data (make-array (array-dimensions data))) (new-data (make-array (array-dimensions data))) (location-trans (make-instance '2d-shift :x-shift (round (+ (aref plot-rgn 0) (/ (aref plot-rgn 2) 2))) :y-shift (round (+ (aref plot-rgn 1) (/ (aref plot-rgn 3) 2))))) (xrot (make-instance '3d-x-rotate :angle 0)) (yrot (make-instance '3d-y-rotate :angle 0)) (zrot (make-instance '3d-z-rotate :angle 0)) rot temp ) (setf increment (* increment (/ (1- (first (array-dimensions data))) 75))) (canvas-clear c) (canvas-invert c) (set-canvas-pen-mode c :patxor) (setf rot (user-select-direction xrot yrot zrot)) (copy-contents scaled-data old-data) (apply-transform! location-trans old-data) (with-focused-canvas c (loop for i from 0 to (- (first (array-dimensions old-data)) 1) do (canvas-draw-point (round (aref old-data i 0)) (round (aref old-data i 1)) c))) (if (listen) (read)) (loop until (read-char-no-hang) do (loop until (read-char-no-hang) do (setf (angle-of rot) (+ (angle-of rot) increment)) (copy-contents scaled-data new-data) (apply-transform! rot new-data) (apply-transform! location-trans new-data) (with-focused-canvas c (canvas-clear c) (loop for i from 0 to (- (first (array-dimensions old-data)) 1) do (progn ;;(canvas-draw-point (aref old-data i 0) ;; (aref old-data i 1) ;; c) (canvas-draw-point (aref new-data i 0) (aref new-data i 1) c)))) (setf temp old-data) (setf old-data new-data) (setf new-data temp)) (apply-transform! rot scaled-data) (setf rot (user-select-direction xrot yrot zrot)) (setf (angle-of rot) 0) finally (loop for i from 0 to (- (first (array-dimensions old-data)) 1) do (canvas-draw-point (aref old-data i 0) (aref old-data i 1) c)))))
3,475
Common Lisp
.l
64
33.203125
105
0.438742
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ea648f6028e3762a0601c4e229ee525df9ece3f62ff897216254441e45627f76
33,050
[ -1 ]
33,051
wb-extensions.lsp
rwoldford_Quail/contributed/rotation-and-section/spin/wb-extensions.lsp
;;; just a note: the first macro has a quote around it so that I can check that ;;; the form it iexpamding to is what I want. #| (defmacro with-focused-canvas (canvas &body body) `(quote (with-focused-view ,canvas ,@body)))|# (in-package wb) (defmacro with-focused-canvas (canvas &body body) `(with-focused-view ,canvas ,@body)) (defun canvas-draw-point (x y canvas) (let ((p (make-point x (mac-to-canvas-y y canvas)))) (with-focused-canvas canvas (#_MoveTo :long p) (#_LineTo :long p)))) (defun canvas-draw-point (x y canvas) (let ((new-y (mac-to-canvas-y y canvas))) (with-focused-canvas canvas (#_MoveTo x new-y) (#_LineTo x new-y)))) (defun canvas-draw-points (array canvas) (with-focused-canvas canvas (loop for i from 0 to (1- (first (array-dimensions array))) do (canvas-draw-point (aref array i 0) (aref array i 1) canvas)))) (defmacro set-canvas-pen-mode (canvas mode) `(qd::set-pen-mode ,canvas ,mode)) (defun canvas-draw-filled-circle (x y radius canvas) (qd::paint-oval canvas (- x radius) (canvas-to-mac-y (+ y radius) canvas) (+ x radius) (canvas-to-mac-y (- y radius) canvas)))
1,267
Common Lisp
.l
30
35.433333
80
0.619281
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
959c05af78a37b0d5288abbade3cfa41a7dba08a709496ff8697cc199e80d046
33,051
[ -1 ]
33,052
active-object.lsp
rwoldford_Quail/contributed/tba/active-object/active-object.lsp
;;;------------------------------------------------------------------------ ;;; ;;; active-value.lisp ;;; ;;;------------------------------------------------------------------------ (in-package 'quail-user) (defclass active-value (quail-object) ((value :initarg :value :initform nil :accessor value-of) (get-function :initarg :get-function :initform nil :accessor get-function-of) (put-function :initarg :put-function :initform nil :accessor put-function-of))) ;----- (defun active-value-p (val) (typep val 'active-value)) ;---------------------------------------------------------------------------------- (defmethod slot-value-method ((self quail-object) slot-name) (let ((slot (funcall *old-slot-value* self slot-name))) (if (active-value-p slot) (get-value self slot) slot))) ;----- (defmethod (setf slot-value) (new-value (self quail-object) &rest slot-name) (let ((slot (apply *old-slot-value* self slot-name))) (if (active-value-p slot) (put-value self slot new-value) (funcall *old-setf-slot-value* self (first slot-name) new-value)))) ;----- (defun get-value (obj slot) (funcall (get-function-of slot) obj slot)) ;----- (defun put-value (obj slot new-value) (funcall (put-function-of slot) obj slot new-value)) ;----- (defclass test (quail-object) ((a :initarg :a) (b :initarg :b) (c :initarg :c))) (defmethod a-of ((self test)) (funcall (symbol-function 'slot-value) self 'a)) (defmethod b-of ((self test)) (funcall (symbol-function 'slot-value) self 'b)) (defmethod c-of ((self test)) (funcall (symbol-function 'slot-value) self 'c)) ;----- (setf c (make-instance 'active-value :get-function #'(lambda (object slot) (or (value-of slot) (max (a-of object) (b-of object)) :put-function #'(lambda (object slot new-value) (declare (ignore object slot new-value)) (quail-print "PUT")))) (setf x (make-instance 'test :a 9 :b y)) ;-----
2,417
Common Lisp
.l
60
29.7
84
0.47473
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4ec61d38c98320dfa975a2f05bc20092fc992727829eca5ef6b7e27cfb593870
33,052
[ -1 ]
33,053
new-slot-value.lsp
rwoldford_Quail/contributed/tba/active-object/new-slot-value.lsp
;;;------------------------------------------------------------------------ ;;; ;;; new-slot-value.lisp ;;; ;;;------------------------------------------------------------------------ (in-package 'quail-user) (defvar *old-slot-value* ()) (eval-when (compile load eval) (unless *old-slot-value* (setf *old-slot-value* (symbol-function 'slot-value)))) ;----- (defvar *old-setf-slot-value* ()) (eval-when (compile load eval) (unless *old-setf-slot-value* (setf *old-setf-slot-value* (symbol-function (first (macroexpand '(setf (slot-value object slot-name) new-value))))))) ;----- (defgeneric slot-value-method (self slot-name)) (defmethod slot-value-method ((self t) slot-name) (funcall *old-slot-value* self slot-name)) ;----- (defgeneric setf-slot-value-method (self slot-name new-value)) (defmethod setf-slot-value-method ((self t) slot-name new-value) (funcall *old-setf-slot-value* self slot-name new-value)) ;----- (eval-when (compile load eval) (setf (symbol-function 'slot-value) (symbol-function 'slot-value-method))) (eval-when (compile load eval) (defsetf slot-value (object slot-name) (new-value) `(setf-slot-value-method ,object ,slot-name ,new-value))) ;-----
1,278
Common Lisp
.l
31
36.83871
101
0.58615
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ede15546c7bc5a06859c0326608c4a7a73d3265511fb584f7aa8302513091e17
33,053
[ -1 ]
33,054
depository.lsp
rwoldford_Quail/contributed/tba/active-object/depository.lsp
;;;------------------------------------------------------------------------ ;;; inverse.lisp ;;; ;;;------------------------------------------------------------------------ (in-package :pcl) ;----- (defvar *old-slot-value* ()) (unless *old-slot-value* (setf *old-slot-value* (symbol-function 'slot-value))) ;----- (defgeneric slot-value-method (self slot-name)) (defmethod slot-value-method ((self t) slot-name) (funcall *old-slot-value* self slot-name)) ;----- (setf (symbol-function 'slot-value) #'(lambda (self slot-name) (slot-value-method self slot-name))) ;----- (defvar *new-slot-value* ()) (unless *new-slot-value* (setf *new-slot-value* (symbol-function 'slot-value))) ;------------------------------------------------------------------------------------- (defvar *old-describe* ()) (unless *old-describe* (setf *old-describe* (symbol-function 'describe))) (setf (symbol-function 'describe) #'(lambda (object) (describe-object object *quail-standard-output*) (values))) ;----- (defmethod describe-object ((self t) stream) (funcall *old-describe* self)) ;------------------------------------------------------------------------------------ (defclass test (matrix) ((object :initarg :object :initform nil :accessor object-of) (calculated? :initarg :calculated? :initform nil :accessor calculated-of))) ;----- (defmethod print-object :around ((self test) stream) (if (calculated-p self) (call-next-method) (format stream "~A" "#<TEST>")) self) ;----- (defmethod describe-object ((self test) stream) (if (calculated-p self) (call-next-method) (unwind-protect (progn (setf (symbol-function 'slot-value) *old-slot-value*) (call-next-method)) (setf (symbol-function 'slot-value) *new-slot-value*))) self) ;----- (defmethod calculated-p ((self test)) (not (null (calculated-of self)))) ;--------------------------------------------------------------------------------- (defmethod inverse :around ((x matrix)) (if (apply #'= (dimensions-of x)) (call-next-method) (quail-error "INVERSE only defined for square matrices."))) (defmethod inverse ((x matrix)) (let ((result (make-instance 'test :object (change-class x 'test)))) (setf (object-of x) result) (setf (dimensions-of result) (dimensions-of x)) (setf (calculated-of x) t) result)) (defmethod inverse ((self test)) (object-of self)) ;----- (defmethod slot-value-method ((self test) slot-name) (if (calculated-p self) (call-next-method) (unwind-protect (progn (setf (symbol-function 'slot-value) *old-slot-value*) (slot-value (force-evaluation self) slot-name)) (setf (symbol-function 'slot-value) *new-slot-value*)))) ;---------------------------------------------------------------------------- (defmethod ref :after ((self test) &rest args) (setf (calculated-of self) t)) (defmethod eref :after ((self test) &rest args) (setf (calculated-of self) t)) (defmethod sel :after ((self test) &rest args) (setf (calculated-of self) t)) ;----- (defgeneric force-evaluation (self)) (defmethod force-evaluation ((self t)) self) (defmethod force-evaluation ((self test)) (if (calculated-p self) (call-next-method) (let ((inv (calculate-inverse (object-of self)))) (with-slots ((self-proto proto) (self-ref-obj ref-obj) (self-specs-mask specs-mask) (self-specs specs) (self-dimensions dimensions) (self-ref-contents ref-contents) (self-decomposition decomposition) (self-calculated? calculated?)) self (with-slots ((inv-proto proto) (inv-ref-obj ref-obj) (inv-specs-mask specs-mask) (inv-specs specs) (inv-dimensions dimensions) (inv-ref-contents ref-contents) (inv-decomposition decomposition)) inv (psetf self-proto inv-proto self-ref-obj inv-ref-obj self-specs-mask inv-specs-mask self-specs inv-specs self-dimensions inv-dimensions self-ref-contents inv-ref-contents self-decomposition inv-decomposition self-calculated? t))) self))) ;----- (defmethod dot-times-object :around ((x test) (y test)) (if (or (eql x (object-of y)) (eql y (object-of x))) (make-identity-matrix (first (dimensions-of x))) (call-next-method))) ;------------------------------------------------------------------------- ;DEFCLASS: identity-matrix ;------------------------------------------------------------------------- (defclass identity-matrix (matrix) ()) (defun make-identity-matrix (extent) (array (list extent extent) :initial-contents (loop for i from 1 to extent collect (loop for j from 1 to extent collect (if (= i j) 1 0))) :class 'identity-matrix)) (defmethod inverse ((self identity-matrix)) self) ;------------------------------------------------------------------------- ;DEFUN: calculate-inverse ;------------------------------------------------------------------------- (defun calculate-inverse (x) (let ((lu (lu-of x))) (if (= 1.0 (+ 1.0 (eref (rcond-of lu)))) (quail-error "Matrix is singular to working precision.") (let* ((a (sel (a-of lu))) (ipvt (ipvt-of lu)) (det (array (list 2) :initial-element 0)) (job 1)) (dgedi a ipvt det job) a)))) ;-----
6,144
Common Lisp
.l
157
30.713376
87
0.490915
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
aacfc367806a390503cbefe5c1adecaceed8c59e93f1f8774ec376abcb05769b
33,054
[ -1 ]
33,056
basic-statistics-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/basic-statistics-tpc.lsp
(setf (doc 'BASIC-STATISTICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "BASIC-STATISTICS" :PACKAGE "QUAIL-USER" :SYMBOL 'BASIC-STATISTICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((SUMMARY-STATISTICS :TOPIC) (SWEEP :FUNCTION))) ) (setf (doc 'BASIC-STATISTICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "BASIC-STATISTICS" :PACKAGE "QUAIL-USER" :SYMBOL 'BASIC-STATISTICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((SUMMARY-STATISTICS :TOPIC) (SWEEP :FUNCTION))) )
790
Common Lisp
.l
48
12.625
52
0.666667
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3f0b88bc78845554edd6a8ab5ef25fe6ee8b4f1ef393df1b439221e1502ee169
33,056
[ -1 ]
33,057
summary-statistics-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/summary-statistics-tpc.lsp
(setf (doc 'SUMMARY-STATISTICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "SUMMARY-STATISTICS" :PACKAGE "QUAIL-USER" :SYMBOL 'SUMMARY-STATISTICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((COV :GENERIC-FUNCTION) (FIVE-NUM-SUM :GENERIC-FUNCTION) (IQR :GENERIC-FUNCTION) (MEAN :GENERIC-FUNCTION) (MEDIAN :GENERIC-FUNCTION) (QUARTILE :GENERIC-FUNCTION) (RANGE :GENERIC-FUNCTION) (SD :GENERIC-FUNCTION) (SUM :FUNCTION) (VAR :GENERIC-FUNCTION))) ) (setf (doc 'SUMMARY-STATISTICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "SUMMARY-STATISTICS" :PACKAGE "QUAIL-USER" :SYMBOL 'SUMMARY-STATISTICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((COV :GENERIC-FUNCTION) (FIVE-NUM-SUM :GENERIC-FUNCTION) (IQR :GENERIC-FUNCTION) (MEAN :GENERIC-FUNCTION) (MEDIAN :GENERIC-FUNCTION) (QUARTILE :GENERIC-FUNCTION) (RANGE :GENERIC-FUNCTION) (SD :GENERIC-FUNCTION) (SUM :FUNCTION) (VAR :GENERIC-FUNCTION))) )
1,242
Common Lisp
.l
54
18.925926
80
0.6875
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7a8ba52cc6d0edacac4865735d69fe86011e1a897c88b46283a824ded6d56429
33,057
[ -1 ]
33,058
synonyms-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/synonyms-tpc.lsp
(setf (doc 'SYNONYMS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "SYNONYMS" :PACKAGE "QUAIL-USER" :SYMBOL 'SYNONYMS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((** :MACRO) (** :VARIABLE) (ALIAS :MACRO) (MAKE-SYNONYM :MACRO) (^ :MACRO) (_ :MACRO))) ) (setf (doc 'SYNONYMS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "SYNONYMS" :PACKAGE "QUAIL-USER" :SYMBOL 'SYNONYMS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((** :MACRO) (** :VARIABLE) (ALIAS :MACRO) (MAKE-SYNONYM :MACRO) (^ :MACRO) (_ :MACRO))) )
832
Common Lisp
.l
50
12.72
79
0.614396
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
039e7680d4e374b3c8b94f4ea65b8d0750d9d0f6a56accd1f463a405da190abf
33,058
[ -1 ]
33,059
hardcopy-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/hardcopy-tpc.lsp
(setf (doc 'HARDCOPY :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "HARDCOPY" :PACKAGE "QUAIL-USER" :SYMBOL 'HARDCOPY :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((HARDCOPY-MCL :TOPIC))) ) (setf (doc 'HARDCOPY :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "HARDCOPY" :PACKAGE "QUAIL-USER" :SYMBOL 'HARDCOPY :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((HARDCOPY-MCL :TOPIC))) )
694
Common Lisp
.l
48
10.625
37
0.641745
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d2dab710ab185907ca26070e12f236a8387f94a8b5c5a89665968198aecdb2e9
33,059
[ -1 ]
33,060
color-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/color-tpc.lsp
(setf (doc 'COLOR :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "COLOR" :PACKAGE "QUAIL-USER" :SYMBOL 'COLOR :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((*BLACK-COLOR* :VARIABLE) (*BLUE-COLOR* :VARIABLE) (*BROWN-COLOR* :VARIABLE) (*DARK-GRAY-COLOR* :VARIABLE) (*DARK-GREEN-COLOR* :VARIABLE) (*GRAY-COLOR* :VARIABLE) (*GREEN-COLOR* :VARIABLE) (*LIGHT-BLUE-COLOR* :VARIABLE) (*LIGHT-GRAY-COLOR* :VARIABLE) (*ORANGE-COLOR* :VARIABLE) (*PINK-COLOR* :VARIABLE) (*PURPLE-COLOR* :VARIABLE) (*RED-COLOR* :VARIABLE) (*TAN-COLOR* :VARIABLE) (*WHITE-COLOR* :VARIABLE) (*YELLOW-COLOR* :VARIABLE))) ) (setf (doc 'COLOR :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "COLOR" :PACKAGE "QUAIL-USER" :SYMBOL 'COLOR :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((*BLACK-COLOR* :VARIABLE) (*BLUE-COLOR* :VARIABLE) (*BROWN-COLOR* :VARIABLE) (*DARK-GRAY-COLOR* :VARIABLE) (*DARK-GREEN-COLOR* :VARIABLE) (*GRAY-COLOR* :VARIABLE) (*GREEN-COLOR* :VARIABLE) (*LIGHT-BLUE-COLOR* :VARIABLE) (*LIGHT-GRAY-COLOR* :VARIABLE) (*ORANGE-COLOR* :VARIABLE) (*PINK-COLOR* :VARIABLE) (*PURPLE-COLOR* :VARIABLE) (*RED-COLOR* :VARIABLE) (*TAN-COLOR* :VARIABLE) (*WHITE-COLOR* :VARIABLE) (*YELLOW-COLOR* :VARIABLE))) )
1,564
Common Lisp
.l
62
20.903226
80
0.640854
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9d330e5ea2b386b32171f7a93e809eec701180c276fbde54df0b4b572c1e80d6
33,060
[ -1 ]
33,061
host-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/host-tpc.lsp
(setf (doc 'HOST :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "HOST" :PACKAGE "QUAIL-USER" :SYMBOL 'HOST :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((WINDOW-BASICS:HOST-WINDOW :CLASS))) ) (setf (doc 'HOST :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "HOST" :PACKAGE "QUAIL-USER" :SYMBOL 'HOST :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((WINDOW-BASICS:HOST-WINDOW :CLASS))) )
696
Common Lisp
.l
48
10.666667
41
0.636646
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a75287515d626ddac9da5abd51972871a7a2d6da1a258ed37caeb8dbfbdb2eac
33,061
[ -1 ]
33,062
statistics-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/statistics-tpc.lsp
(setf (doc 'STATISTICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "STATISTICS" :PACKAGE "QUAIL-USER" :SYMBOL 'STATISTICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((BASIC-STATISTICS :TOPIC))) ) (setf (doc 'STATISTICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "STATISTICS" :PACKAGE "QUAIL-USER" :SYMBOL 'STATISTICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((BASIC-STATISTICS :TOPIC))) )
714
Common Lisp
.l
48
11.041667
37
0.652568
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5ec40918fe3d0deb32c3b8f20c6dd34d8d806e0a1f94051b52da52578b8f46bc
33,062
[ -1 ]
33,063
window-basics-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/window-basics-tpc.lsp
(setf (doc 'WINDOW-BASICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "WINDOW-BASICS" :PACKAGE "QUAIL-USER" :SYMBOL 'WINDOW-BASICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((COLOR :TOPIC) (HARDCOPY :TOPIC) (HOST :TOPIC))) ) (setf (doc 'WINDOW-BASICS :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "WINDOW-BASICS" :PACKAGE "QUAIL-USER" :SYMBOL 'WINDOW-BASICS :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((COLOR :TOPIC) (HARDCOPY :TOPIC) (HOST :TOPIC))) )
774
Common Lisp
.l
48
12.291667
53
0.648199
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fbaa9db1bc8f19bd45d543bc1b56c04b82f96a2af90ce55b8caff8e1781d68ac
33,063
[ -1 ]
33,064
initialization-tpc.lsp
rwoldford_Quail/doc/auto/quail-user/initialization-tpc.lsp
(setf (doc 'INITIALIZATION :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "INITIALIZATION" :PACKAGE "QUAIL-USER" :SYMBOL 'INITIALIZATION :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((SYNONYMS :TOPIC))) ) (setf (doc 'INITIALIZATION :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "INITIALIZATION" :PACKAGE "QUAIL-USER" :SYMBOL 'INITIALIZATION :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((SYNONYMS :TOPIC))) )
722
Common Lisp
.l
48
11.208333
37
0.659701
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4242fac343502d2ecfa08c1aa9e4f34fc885e755c4e373075d09aa19599a3651
33,064
[ -1 ]
33,066
quail-tpc.lsp
rwoldford_Quail/doc/auto/quail/quail-tpc.lsp
(setf (doc 'QUAIL :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "QUAIL" :PACKAGE "QUAIL" :SYMBOL 'QUAIL :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((INITIALIZATION :TOPIC) (STATISTICS :TOPIC) (WINDOW-BASICS :TOPIC))) ) (setf (doc 'QUAIL :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "QUAIL" :PACKAGE "QUAIL" :SYMBOL 'QUAIL :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES 'NIL :REFERENCES NIL :SEE-ALSO 'NIL :SUPER-TOPICS 'NIL :SUB-TOPICS '((INITIALIZATION :TOPIC) (STATISTICS :TOPIC) (WINDOW-BASICS :TOPIC))) )
756
Common Lisp
.l
48
11.916667
73
0.647727
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
248806fc4dd3f187c8668b3aa995859ff351a651330db35373347918fe2c46ab
33,066
[ -1 ]
33,067
examples-tpc.lsp
rwoldford_Quail/doc/polished/topics/examples-tpc.lsp
(setf (doc 'EXAMPLES :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "EXAMPLES" :PACKAGE "QUAIL" :DOC-CAPSULE "Examples can be found by direct selection from the Quail menu ~ or by editing files in the Quail examples directory eg: ~%~%~ These are the principal source of instruction in Quail." :DOC-ELABORATION NIL :EXAMPLES NIL :REFERENCES NIL :SEE-ALSO NIL :SUPER-TOPICS NIL :SUB-TOPICS NIL ) )
627
Common Lisp
.l
24
16.208333
73
0.52862
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fe5b7a118a050d569919c6d26872e01438b4093584155ff7bdaec5fa9e177f80
33,067
[ -1 ]
33,068
general-tpc.lsp
rwoldford_Quail/doc/polished/topics/general-tpc.lsp
(setf (doc 'GENERAL :topic) (MAKE-INSTANCE 'QUAIL-KERNEL::TOPIC-DOCUMENTATION :NAME "GENERAL" :PACKAGE "QUAIL" :DOC-CAPSULE NIL :DOC-ELABORATION NIL :EXAMPLES NIL :REFERENCES NIL :SEE-ALSO NIL :SUPER-TOPICS '() :SUB-TOPICS '((HELP-INFORMATION :TOPIC) (COMMON-LISP-LANGUAGE-EXTENSIONS :TOPIC) (EXTENDED-ARITHMETIC :TOPIC) (ARITHMETIC-OPERATORS :TOPIC) (NUMERICAL-PROCEDURES :TOPIC) (LOGICAL-PROCEDURES :TOPIC) (ASSIGNMENT :TOPIC) (ITERATION :TOPIC) (DEFINING-NEW-PROCEDURES :TOPIC) (DEFINING-NEW-DATA-TYPES :TOPIC) (BUILDING-DATA-STRUCTURES :TOPIC) (READING-FILES :TOPIC) (QUAIL-SESSION :TOPIC) (INTERACTIVE-I/O :TOPIC) (ARRAY-MANIPULATION :TOPIC) (MATRIX-MANIPULATION :TOPIC) (DATASET-MANIPULATION :TOPIC) (REFERENCING-ELEMENTS :TOPIC) (DATA-PREDICATES :TOPIC) (WRITING-FASTER-CODE :TOPIC) (COERCION :TOPIC) (FOREIGN-ENVIRONMENTS :TOPIC) (TIME :TOPIC) (SHADOWED-SYMBOLS :TOPIC) (QUAIL-IMAGE :TOPIC) (EXTENDING-QUAIL :TOPIC) ) ) )
1,124
Common Lisp
.l
48
18.375
50
0.658582
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
750fc74d1b5ca9038c3643937d6eb3cdb148fdb8dbcfbece2db4edfc16cdcacc
33,068
[ -1 ]
33,069
documentation-tpc.lsp
rwoldford_Quail/doc/polished/common-lisp/documentation-tpc.lsp
(setf (doc 'documentation :topic) (make-instance 'quail-kernel::topic-documentation :name "documentation" :doc-capsule "How documentation is accessed and created in Quail." :doc-elaboration "Documentation is accessed online primarily through the ~ function help. There are several kinds of documentation ~ available, often on the same symbol. All types are ~ specified by a keyword (e.g. :topic, :function, :class). ~ A list of ~ the documentable types for any symbol can be found by ~ calling the function documentable-uses on that symbol." :examples nil :references nil :see-also nil :sub-topics '((help :function) (documentable-uses :function) (make-doc :generic-function) (write-tex-doc :function) (make-documentation-index :function) (make-sorted-documentation-index :function) (sort-doc :function) (documentation-objects :topic)) :super-topics NIL ))
1,724
Common Lisp
.l
32
31.4375
82
0.390431
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a0b2be76b3c0359cf58bfa3317595474f7224020df36d2842b3cbf9426fa47d4
33,069
[ -1 ]
33,070
fast-surface-fill-fn.tex
rwoldford_Quail/doc/tex/window-basics/fast-surface-fill-fn.tex
\headerbox{FAST-SURFACE-FILL}{}{FUNCTION} {\bf Description} No description available. {\bf Lambda List} (CANVAS X-ORIGIN Y-ORIGIN X Y CZ SZV C NCOL AA FAST-COLOR-TABLE) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf CANVAS} {\bf X-ORIGIN} {\bf Y-ORIGIN} {\bf X} {\bf Y} {\bf CZ} {\bf SZV} {\bf C} {\bf NCOL} {\bf AA} {\bf FAST-COLOR-TABLE} \endhang {\bf Home Package} WINDOW-BASICS
524
Common Lisp
.l
22
16.909091
65
0.680203
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
480ba3787b11d8c6903f3c301e6f1282c7d476b08d8735c2395f207fdbc84453
33,070
[ -1 ]
33,071
starblack-colourstar-var.tex
rwoldford_Quail/doc/tex/window-basics/starblack-colourstar-var.tex
\headerbox{*BLACK-COLOUR*}{}{VARIABLE} {\bf Description} No description available. {\bf Default value} 0 {\bf Home Package} WINDOW-BASICS
166
Common Lisp
.l
7
18.714286
39
0.746377
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6a8ed7efed6bf2b8e66602597f4f672636f0fa2c9f6e301776eed41f3990aba7
33,071
[ -1 ]
33,072
get-left-button-fn-fn.tex
rwoldford_Quail/doc/tex/window-basics/get-left-button-fn-fn.tex
\headerbox{GET-LEFT-BUTTON-FN}{}{FUNCTION} {\bf Description} No description available. {\bf Lambda List} (CANVAS) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf CANVAS} \endhang {\bf Home Package} WINDOW-BASICS
273
Common Lisp
.l
12
17.583333
43
0.735426
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a86a6c2346fd7c39a125811a26a447781e5212e13f6258bf6bc42f277cc3833f
33,072
[ -1 ]
33,073
stardark-gray-colourst-var.tex
rwoldford_Quail/doc/tex/window-basics/stardark-gray-colourst-var.tex
\headerbox{*DARK-GRAY-COLOUR*}{}{VARIABLE} {\bf Description} No description available. {\bf Default value} 4210752 {\bf Home Package} WINDOW-BASICS
176
Common Lisp
.l
7
20.142857
43
0.756757
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e631db67ce0a4f64630181f69b73877e2a28fbd64920344adc19b1518fe95591
33,073
[ -1 ]
33,074
stargray-colorstar-var.tex
rwoldford_Quail/doc/tex/window-basics/stargray-colorstar-var.tex
\headerbox{*GRAY-COLOR*}{}{VARIABLE} {\bf Description} No description available. {\bf Default value} 8421504 {\bf Home Package} WINDOW-BASICS
170
Common Lisp
.l
7
19.285714
37
0.753521
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
32ab043d7cfa87e02297e56c5e9c92f48355c8a259c795c8b4f8661667e562ea
33,074
[ -1 ]
33,075
starsystem-default-men-var.tex
rwoldford_Quail/doc/tex/window-basics/starsystem-default-men-var.tex
\headerbox{*SYSTEM-DEFAULT-MENUBAR*}{}{VARIABLE} {\bf Description} The default menubar of the system. {\bf Default value} (\#\<CCL:APPLE-MENU ""\> \#\<CCL:MENU "File"\> \#\<CCL:MENU "Edit"\> \#\<CCL:MENU "Eval"\> \#\<CCL:MENU "Tools"\> \#\<CCL:MENU "Windows"\>) {\bf Home Package} WINDOW-BASICS
324
Common Lisp
.l
7
41.285714
141
0.635135
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
eaeb9513f7de062a089eee15c7f4b3241f72948b892f0e1d593df12ffc1902a0
33,075
[ -1 ]
33,076
set-up-default-canvas-r-fn.tex
rwoldford_Quail/doc/tex/window-basics/set-up-default-canvas-r-fn.tex
\headerbox{SET-UP-DEFAULT-CANVAS-REGION}{}{FUNCTION} {\bf Description} Sets the default region where a new canvas will appear on the screen. {\bf Lambda List} (\&OPTIONAL LEFT BOTTOM WIDTH HEIGHT) {\bf Arguments} \beginhang {\bf \&optional}\hspace{2em} {\bf LEFT} {\bf BOTTOM} {\bf WIDTH} {\bf HEIGHT} \endhang {\bf Home Package} WINDOW-BASICS
418
Common Lisp
.l
15
21.933333
70
0.729651
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
207ec5a0019884f624fa317c45856ed663b8b242f396165a2d7c0c53c9c667d5
33,076
[ -1 ]
33,077
staryellow-colourstar-var.tex
rwoldford_Quail/doc/tex/window-basics/staryellow-colourstar-var.tex
\headerbox{*YELLOW-COLOUR*}{}{VARIABLE} {\bf Description} No description available. {\bf Default value} 16511493 {\bf Home Package} WINDOW-BASICS
174
Common Lisp
.l
7
19.857143
40
0.760274
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9cb2c3f894fe9358f6fc95516b21916fde4f038ef6a4f5fee603c3db36c220ca
33,077
[ -1 ]
33,078
control-key-p-fn.tex
rwoldford_Quail/doc/tex/window-basics/control-key-p-fn.tex
\headerbox{CONTROL-KEY-P}{}{FUNCTION} {\bf Description} Tests whether the control key is being held down. {\bf Arguments} {\bf Home Package} WINDOW-BASICS
182
Common Lisp
.l
6
24.833333
50
0.754839
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1e12e314358579c7958410756750948edebf3495e235f369bfcf1ef53775e331
33,078
[ -1 ]
33,079
starbright-white-color-var.tex
rwoldford_Quail/doc/tex/window-basics/starbright-white-color-var.tex
\headerbox{*BRIGHT-WHITE-COLOR*}{}{VARIABLE} {\bf Description} No description available. {\bf Default value} 16711422 {\bf Home Package} WINDOW-BASICS
179
Common Lisp
.l
7
20.571429
45
0.761589
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
81bb92617d92217ffaca874609bdd31e6fe162e78c8722c5577897dc5a0b1a8d
33,079
[ -1 ]
33,080
redisplay-p-of-gf.tex
rwoldford_Quail/doc/tex/window-basics/redisplay-p-of-gf.tex
\headerbox{REDISPLAY-P-OF}{}{GENERIC-FUNCTION} {\bf Description} No description available. {\bf Lambda List} (CANVAS-REDISPLAY-MIXIN) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf CANVAS-REDISPLAY-MIXIN} \endhang {\bf Home Package} WINDOW-BASICS
309
Common Lisp
.l
12
20.583333
47
0.756757
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
446ae706eb2671af78d610a9e9c7da92e7dc36aa663506015ab67b83beb92124
33,080
[ -1 ]
33,081
left-title-items-of-gf.tex
rwoldford_Quail/doc/tex/window-basics/left-title-items-of-gf.tex
\headerbox{LEFT-TITLE-ITEMS-OF}{}{GENERIC-FUNCTION} {\bf Description} No description available. {\bf Lambda List} (MENU-CANVAS) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf MENU-CANVAS} \endhang {\bf Home Package} WINDOW-BASICS
292
Common Lisp
.l
12
19.166667
52
0.743802
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a564a8a5634b25739173d5376bf137a4e6572fb3fd0befb33c80677e95c00683
33,081
[ -1 ]
33,082
region-left-mc.tex
rwoldford_Quail/doc/tex/window-basics/region-left-mc.tex
\headerbox{REGION-LEFT}{}{QUAIL-KERNEL::MACRO} {\bf Description} No description available. {\bf Lambda List} (R) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf R} \endhang {\bf Home Package} WINDOW-BASICS
267
Common Lisp
.l
12
17.083333
47
0.723502
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b3a8d5d3afb8f6f5d33de403fbdd9c87bc5d34be8403e0e67b0b7b2974a38cb4
33,082
[ -1 ]
33,083
set-system-default-menu-fn.tex
rwoldford_Quail/doc/tex/window-basics/set-system-default-menu-fn.tex
\headerbox{SET-SYSTEM-DEFAULT-MENUBAR}{}{FUNCTION} {\bf Description} Sets the *system-default-menubar* to be the value of the optional argument menubar ( defaults to the Macintosh's *default-menubar* ) . {\bf Lambda List} (\&OPTIONAL MENUBAR) {\bf Arguments} \beginhang {\bf \&optional}\hspace{2em} {\bf MENUBAR} \endhang {\bf Home Package} WINDOW-BASICS
405
Common Lisp
.l
12
28.583333
135
0.743662
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6bc91da98edd5faaf189160e2315ab774a5e73968ce3a2a02e572ad5b6d1f2d4
33,083
[ -1 ]
33,084
prompt-for-ps-filenames-fn.tex
rwoldford_Quail/doc/tex/window-basics/prompt-for-ps-filenames-fn.tex
\headerbox{PROMPT-FOR-PS-FILENAMES}{}{FUNCTION} {\bf Description} Prompt user for postscript file information for the given canvas. {\bf Lambda List} (CANVAS) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf CANVAS} \endhang {\bf Home Package} WINDOW-BASICS
318
Common Lisp
.l
12
21.333333
66
0.753731
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3e5a3b114b69fd6320e94b20fe9058f62098d5f36998c2d14d82295a0918671d
33,084
[ -1 ]
33,085
startan-colourstar-var.tex
rwoldford_Quail/doc/tex/window-basics/startan-colourstar-var.tex
\headerbox{*TAN-COLOUR*}{}{VARIABLE} {\bf Description} No description available. {\bf Default value} 9400634 {\bf Home Package} WINDOW-BASICS
170
Common Lisp
.l
7
19.285714
37
0.753521
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
aede3b188935fb28451d3072051256f56aa75a2870fba1f1ae7549f8975a98e6
33,085
[ -1 ]
33,086
plus-object-gf.tex
rwoldford_Quail/doc/tex/new-math/plus-object-gf.tex
\headerbox{PLUS-OBJECT}{}{GENERIC-FUNCTION} {\bf Description} No description available. {\bf Lambda List} (A B) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf A} {\bf B} \endhang {\bf Home Package} NEW-MATH
277
Common Lisp
.l
13
15.846154
44
0.707763
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
140b6240681c98a314f18a630a4251278906a72aed1b99406bb248c62b6f369e
33,086
[ -1 ]
33,087
defmethod-multi-mc.tex
rwoldford_Quail/doc/tex/quail-kernel/defmethod-multi-mc.tex
\headerbox{DEFMETHOD-MULTI}{}{MACRO} {\bf Description} No description available. {\bf Lambda List} (\&REST DEFMETHOD-ARGS) {\bf Arguments} \beginhang {\bf \&rest}\hspace{2em} {\bf DEFMETHOD-ARGS} \endhang {\bf Home Package} QUAIL-KERNEL
287
Common Lisp
.l
12
18.75
37
0.729958
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ca5fae5c5a20328ad3a65876277b1cab18e8902ab5a9990ff0ddb09bcc9286eb
33,087
[ -1 ]
33,088
collect-slices-mc.tex
rwoldford_Quail/doc/tex/quail-kernel/collect-slices-mc.tex
\headerbox{COLLECT-SLICES}{}{QUAIL-KERNEL::MACRO} {\bf Description} Provides straightforward iterations over selected slices of a refable object. Syntax: ( collect-slices ( slice-var object slices [order] ) \{form\}* ) First collect-slices evaluates the form object, which should produce a refable object. It then executes the body once for each slice in the object as determined by slices. The order of iteration is determined by the optional argument order: either :row ( the default ) for row major order, or :col for column major order. The result of each iteration is collected into a list and returned as the value of the collect-slices form. If slices is omitted, looping is over each element of the object. {\bf Lambda List} ((SLICE-VAR OBJECT SLICES \&OPTIONAL (ORDER ROW)) \&BODY BODY) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf (SLICE-VAR OBJECT SLICES \&OPTIONAL (ORDER ROW))} \endhang {\bf Home Package} QUAIL-KERNEL
996
Common Lisp
.l
12
77.833333
647
0.766385
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
931ea7caab67834feadbd3511f1485f26d9f0953587efaf84352b62277cfbb26
33,088
[ -1 ]
33,089
doslices-mc.tex
rwoldford_Quail/doc/tex/quail-kernel/doslices-mc.tex
\headerbox{DOSLICES}{}{QUAIL-KERNEL::MACRO} {\bf Description} Provides straightforward iteration over selected slices of a refable object. Syntax: ( doslices ( slice-var object slices \{[return-form] \| [order]\} ) \{form\}* ) First doslices evaluates the form object, which should produce a refable object. It then executes the body once for each slice in the object as determined by slices. The order of iteration is determined by the optional argument order: either :row ( the default ) for row major order, or :col for column major order. The variable slice-var is bound to the slice. Then, return-form is evaluated and the result is the value of the doslices form. ( When the return-form is evaluated, the control variable slice-var is still bound and has the value NIL. ) If return-form is omitted, the result is NIL. If slices is omitted, looping is over each element of the object. {\bf Lambda List} ((SLICE-VAR OBJECT SLICES \&OPTIONAL RETURN-FORM (ORDER ROW)) \&BODY BODY) {\bf Arguments} \beginhang {\bf Required}\hspace{2em} {\bf (SLICE-VAR OBJECT SLICES \&OPTIONAL RETURN-FORM (ORDER ROW))} \endhang {\bf Home Package} QUAIL-KERNEL
1,195
Common Lisp
.l
12
94.416667
828
0.759825
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bf0c5ee32c0fdf6a267740309121535c8acdda0417238e439e33346c22a0bfda
33,089
[ -1 ]
33,090
drawline.ps
rwoldford_Quail/foreign/postscript/drawline.ps
%------------------------------------------------------------------------------ % PROCEDURE: ps_canvas_draw_line %------------------------------------------------------------------------------ % DESCRIPTION: This procedure draws a line between given coordinates (x1,y1) % and (x2,y2). Optional arguments are colour and line width. % % COMMAND LINE: % x1 y1 x2 y2 [lwidth] [r g b] ps_canvas_draw_line % % Arguments in brackets are optional. % Optional commands which are not specified will be replaced by default % values. % % NOTE: When specifying colours explicitly, all three of red, green, and blue % MUST be specified. %------------------------------------------------------------------------------ /ps_canvas_draw_line {ps_draw_dict begin /y_dest exch def /x_dest exch def /y_init exch def /x_init exch def x_init y_init moveto x_dest y_dest lineto stroke end }def /l {ps_canvas_draw_line} bind def
951
Common Lisp
.l
28
31.357143
80
0.532468
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3bc09885162e32892a158f32bd198af871591ec4edb80c597057f7b1b9fabe03
33,090
[ -1 ]
33,091
fpolygon.ps
rwoldford_Quail/foreign/postscript/fpolygon.ps
%------------------------------------------------------------------------------ % PROCEDURE: ps_canvas_draw_filled_polygon %------------------------------------------------------------------------------ % DESCRIPTION: This procedure accepts a variable number of pairs of % coordinates on the stack (points), an iteration counter % (= n, the number of points on the stack), and a colour to fill % the polygon with. % % COMMAND LINE: % x1 y1 x2 y2 ... xn yn counter ps_canvas_draw_filled_polygon %------------------------------------------------------------------------------ /ps_canvas_draw_filled_polygon { ps_draw_dict begin /counter exch def /last_y exch def /last_x exch def newpath last_x last_y moveto counter 1 sub { /current_y exch def /current_x exch def current_x current_y lineto } repeat closepath fill end } def /fp {ps_canvas_draw_filled_polygon} bind def
1,044
Common Lisp
.l
28
32.178571
80
0.463054
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
21d02697b51947bd2722d2254dce3f3914e47a96cb117c9513a50760b72b336a
33,091
[ -1 ]
33,092
fellipse.ps
rwoldford_Quail/foreign/postscript/fellipse.ps
%------------------------------------------------------------------------------- % PROCEDURE: ps_canvas_draw_filled_ellipse %------------------------------------------------------------------------------ % DESCRIPTION: This function is identical to ps_canvas_draw_ellipse save that % it fills the drawn ellipse with the specified colour instead of % merely outlining it. % % COMMAND LINE: % see ps_canvas_draw_ellipse %------------------------------------------------------------------------------ /ps_canvas_draw_filled_ellipse {ps_draw_dict begin /y_radius exch def /x_radius exch def /y_translate exch def /x_translate exch def /savematrix mtrx currentmatrix def x_translate y_translate translate x_radius y_radius scale 0 0 1 0 360 arc fill savematrix setmatrix end }def /fe {ps_canvas_draw_filled_ellipse} bind def
1,083
Common Lisp
.l
25
33.64
81
0.428166
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ff62fbd08cc2a22df24fa70a65ceece00e278b1216676b195db630e358746cc4
33,092
[ -1 ]
33,093
defaults.ps
rwoldford_Quail/foreign/postscript/defaults.ps
/ps_draw_dict 30 dict def ps_draw_dict /mtrx matrix put % Allocated space for save mtrx %------------------------------------------------------------------------------ % PROCEDURE: ps_convert_canvas_to_pages %------------------------------------------------------------------------------ % DESCRIPTION: This function converts the xpixels by ypixels input to % ps_canvas_redraw to the number of pages required for the % canvas in the x and y directions. % % COMMAND LINE: % xpixels ypixels ps_convert_canvas_to_pages % % RETURNS: % columns (pages in the x dir) and rows (pages in the y dir) %------------------------------------------------------------------------------ /ps_convert_canvas_to_pages{ ps_draw_dict begin /canvas_height exch def /canvas_width exch def canvas_width ps_paper_width canvas_horizontal_margin 2 mul sub idiv canvas_width ps_paper_width canvas_horizontal_margin 2 mul sub mod ps_paper_width canvas_horizontal_margin 2 mul sub div 0 gt{1 add}if canvas_height ps_paper_height canvas_vertical_margin 2 mul sub idiv canvas_height ps_paper_height canvas_vertical_margin 2 mul sub mod ps_paper_height canvas_vertical_margin 2 mul sub div 0 gt{1 add}if end }def %------------------------------------------------------------------------------ % PROCEDURE: ps_set_page_boundaries %------------------------------------------------------------------------------ % DESCRIPTION: This function sets the drawing boundaries of each page % in the canvas according to the horizontal and vertical % margins set in the top of the header file. % % COMMAND LINE: % ps_set_page_boundaries %------------------------------------------------------------------------------ /ps_set_page_boundaries{ ps_draw_dict begin newpath canvas_horizontal_margin canvas_vertical_margin moveto ps_paper_width canvas_horizontal_margin sub canvas_vertical_margin lineto ps_paper_width canvas_horizontal_margin sub ps_paper_height canvas_vertical_margin sub lineto canvas_horizontal_margin ps_paper_height canvas_vertical_margin sub lineto closepath clip newpath end }def %------------------------------------------------------------------------------ % PROCEDURE: ps_canvas_redraw %------------------------------------------------------------------------------ % DESCRIPTION: This procedure redraws the postscript canvas defined by % the user. It determines from the xpixels and ypixels inputs % the number of pages required to print the entire canvas % and then proceeds to fill the pages with the correct portions % of the canvas for output to the laser printer. % % COMMAND LINE: % canvas xpixels ypixels ps_canvas_redraw % % NOTE: When calling this function it is important that the graphics state % be set for the default initial values of the printer. (ie: scaling, % translated origins etc.) Therefore, it is important that the canvas % procedure call a gsave initially and a grestore at the end to ensure % that this is the case. %------------------------------------------------------------------------------ /ps_canvas_redraw{ ps_draw_dict begin /canvas_height exch def /canvas_width exch def canvas_width canvas_height ps_convert_canvas_to_pages /rows exch def /columns exch def /bigpictureproc exch def ps_set_page_boundaries canvas_horizontal_margin canvas_vertical_margin translate /canvas_horizontal {ps_paper_width canvas_horizontal_margin 2 mul sub 1 add} bind def /canvas_vertical {ps_paper_height canvas_vertical_margin 2 mul sub 1 add} bind def 0 1 rows 1 sub{ /rowcount exch def 0 1 columns 1 sub{ /colcount exch def gsave canvas_horizontal colcount mul neg canvas_vertical rowcount mul neg translate canvas_horizontal columns mul canvas_width sub 2 idiv canvas_vertical rows mul canvas_height sub 2 idiv translate bigpictureproc gsave showpage grestore grestore }for }for end }def /redraw {ps_canvas_redraw} bind def %------------------------------------------------------------------------------ % PROCEDURE: ps_set_canvas_background %------------------------------------------------------------------------------ % DESCRIPTION: This procedure sets the background colour for the canvas. % % COMMAND LINE: % [red green blue] ps_set_canvas_background % % Arguments in brackets are optional. % Optional arguments which are not specified will be replaced by default % values. % % NOTES: If colour is specified all three of red, green, and blue MUST be % specified. This function should only be called at the beginning of % a postscript file unless the user intends to clear the entire canvas. % THIS FUNCTION NEEDS TO BE CHANGED TO ALLOW FOR MULTIPLE PAGE CANVASSES %------------------------------------------------------------------------------ /ps_set_canvas_background {ps_draw_dict begin /blue exch def /green exch def /red exch def 0 0 moveto 0 ps_paper_height lineto ps_paper_width ps_paper_height lineto ps_paper_width 0 lineto 0 0 lineto red green blue setrgbcolor fill default_red default_green default_blue setrgbcolor end }def /blah{ ps_draw_dict begin pop pop pop end }def /b {blah} bind def %------------------------------------------------------------------------------ % PROCEDURE: ps_canvas_unstroked_draw_to %------------------------------------------------------------------------------ % DESCRIPTION: This procedure draws a line from the current position on the % canvas to a given (x,y) position. Optional arguments are line % width and colour. % % COMMAND LINE: % x y [lwidth] [r g b] ps_canvas_unstroked_draw_to % % Arguments in brackets are optional. % Optional commands which are not specified will be replaced by default % values. % % NOTE: This function must not be called immediately after a newpath statement % (ie: there must be a current (x,y) position in memory.). If necessary % this can be remedied by a 0 0 moveto to indicate the origin as the % current (x,y) position. As usual, if colour is specified, all three % elements must be specified. This function is used by: % ps-canvas-draw-polygon % ps-canvas-draw-filled-polygon %------------------------------------------------------------------------------ /ps_canvas_unstroked_draw_to {ps_draw_dict begin /y exch def /x exch def currentpoint moveto x y lineto end }def /u {ps_canvas_unstroked_draw_to} bind def
6,976
Common Lisp
.l
170
36.005882
94
0.574412
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b227d67c565455a3cd9e112f0e1fba900522d1ccd7f79a9e879ce63247b02d31
33,093
[ -1 ]
33,094
ellipse.ps
rwoldford_Quail/foreign/postscript/ellipse.ps
%------------------------------------------------------------------------------ % PROCEDURE: ps_canvas_draw_ellipse %------------------------------------------------------------------------------ % DESCRIPTION: This function draws an ellipse (or circle) given the x and y % offsets from the origin and the x and y radii (defined as the % length of the line segment between the intersection of the % major and minor axes and the edge of the ellipse in the x and % y directions. Optional arguments are the line width and color. % % COMMAND LINE: % x_off y_off x_rad y_rad [lwidth] [red grn blue] ps_canvas_draw_ellipse % % Arguments in brackets are optional. % Optional arguments which are omitted will be replaced by the % corresponding default values. % % NOTE: If colours are to be specified, all three of red, green and blue MUST % be specified. %------------------------------------------------------------------------------ /ps_canvas_draw_ellipse {ps_draw_dict begin /y_radius exch def /x_radius exch def /y_translate exch def /x_translate exch def /savematrix mtrx currentmatrix def x_translate y_translate translate x_radius y_radius scale newpath 0 0 1 0 360 arc stroke savematrix setmatrix end }def /e {ps_canvas_draw_ellipse} bind def
1,577
Common Lisp
.l
35
37.171429
80
0.49838
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
81fb0e4e9f071dab9423441fc24df4da7e7309a03fc3af156b25fe0ff61ac94f
33,094
[ -1 ]
33,095
quail.sty
rwoldford_Quail/foreign/tex/styles/quail.sty
% October 16, 11:12 am, by D.L. Chapman % use: \headerbox{word}{another}{last words} \def\headerbox#1#2#3{\par\vspace*{3mm} \noindent \begin{picture}(469,54)(0,0) \thicklines \put(0,0){\framebox(468,45){~#1 \hspace*{\fill} #2 \hspace*{\fill} #3~} } \end{picture} \par \vspace*{3mm}} %use: \beginhang{yourheading} % many lines of text, each item separated by a 1.5 line % % more silly drivel, based on code from: [email protected] (Anita % Marie Hoover) % \endhang \def\heading#1{\vspace*{3mm} \noindent { #1} \par} \def\beginhang#1{ \heading{#1} \begingroup \clubpenalty=10000 \widowpenalty=10000 \normalbaselines\parindent 0pt \parskip.5\baselineskip \everypar{\hangindent3em}} \def\endhang{\par\endgroup}
850
Common Lisp
.l
24
29.666667
75
0.617359
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a9c915932b20097440fd1e9bfcebb6126047139f4e9a3fb0cae891f4296a1f54
33,095
[ -1 ]
33,096
mouse-behaviour.lsp
rwoldford_Quail/comments/mouse-behaviour.lsp
#| This is an unsupported version of Quail. It is incomplete but might give you a flavour of what is available. Use at your own risk. Note that Quail assumes a three button mouse left-button = Mac mouse button middle-button = Option + Mac mouse right-button = command (clover leaf) + Mac mouse Each mouse button behaviour can be modified by simultaneously holding either the shift key or the ctrl key and any mouse button. This gives a total of 9 mouse i/o events. Most things are mouse sensitive. Have fun R.W. Oldford U. of Waterloo |#
569
Common Lisp
.l
16
32.6875
70
0.775093
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8b7fdfa4a11c2f63d6c75f38bf3373702db78a32dd2bf26504db219930d934d0
33,096
[ -1 ]
33,099
whats-new.lsp
rwoldford_Quail/comments/whats-new.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; whats-new.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1995 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1995. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; ;;; This file sets up some a mouse-sensitive window that allows the ;;; user access to information on known bugs and fixes. ;;; (in-package :quail) (export '(bugs whats-new?)) (eval-when (load eval) (load "q:comments;fixes.lsp")) (defclass bugs-window (view-window) () (:documentation "Just a place-holder class so that the bugs-window ~ isn't closed if all windows of some other class are closed.") ) (defun make-bugs-window (&rest canvas-keywords &key (left 10) (right 200) (bottom (- (wb::screen-height) 200)) (top (- (wb::screen-height) 40)) (title "(bugs)") (background-color wb:*red-colour*) (pen-color wb:*white-colour*) &allow-other-keys) (apply #'make-view-window :left left :top top :bottom bottom :right right :view-window-class 'bugs-window :title title :background-color background-color :pen-color pen-color canvas-keywords)) (defun bugs (&optional (draw? T)) "Sets up a window which allows the user to access information ~ on known bugs and fixes." (let* ((tv (text-view :text (format NIL "Some bug information. ~%~ Click on the appropriate button.") :draw? NIL :color wb:*white-color*)) (buttons #+:ccl (grid-layout :subviews (list (control-button :text "General bugs" :draw? NIL :left-fn #'(lambda () (edit-file "q:comments;bugs.lsp"))) (control-button :text "Mac specific bugs" :draw? NIL :left-fn #'(lambda () (edit-file "q:comments;bugs-mcl.lsp"))) ) :draw? NIL :rows '(1.0 0.6 0.5 0.1) ) #-:ccl (control-button :text "General bugs" :draw? NIL :left-fn #'(lambda () (edit-file "q:comments;bugs.lsp"))) ) ) (if draw? (let ((vl (view-layout :subviews (list tv buttons (text-view :text " ")) :positions '((0 10 8 10) (1 8 0.5 7) (0 10 0 0.1)) :draw? NIL)) vw vp) (setf vw (make-bugs-window)) (setf vp (make-viewport vw .1 1 0 1)) (draw-view vl :viewport vp) vl) buttons) ) ) (defun whats-new? () "Sets up a window which allows the user to access various information ~ on what is new, especially known bugs and fixes." (let* ((tv (text-view :text (format NIL "Some information. ~%~ Click on the appropriate button.") :draw? NIL :color wb:*white-color*)) (buttons (bugs NIL)) (vl (view-layout :subviews (list tv buttons (text-view :text " ")) :positions '((0 10 8 10) (1 8 0.5 7) (1 8 0 0.1)) :draw? NIL)) (vw (make-bugs-window)) (vp (make-viewport vw .1 1 0 1)) ) (draw-view vl :viewport vp) ) ) (eval-when (load eval) (bugs) (install-fixes))
4,411
Common Lisp
.l
121
22.347107
84
0.401554
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3fe54452eb3346aa93da660e5982b4ae3add02f8b3eacffc3884790c1e8e24b4
33,099
[ -1 ]
33,100
fixes.lsp
rwoldford_Quail/comments/fixes.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; fixes.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1995 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1995. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; ;;; This file sets up some MCL specific fixes. ;;; (in-package :quail) (export '(install-fixes)) (defun install-fixes () "Installs the fixes to known bugs." #+:ccl (load "q:comments;fixes-mcl.lsp") #-:ccl (print "No fixes available."))
760
Common Lisp
.l
25
26.76
84
0.347051
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
427e1f55f59282bfc83a21578684db5c3258420884c422dde31f1e30e8a983c7
33,100
[ -1 ]
33,101
re-enable-menus.lsp
rwoldford_Quail/comments/re-enable-menus.lsp
(in-package :q-user) (defvar *all-menus* (list ccl:*apple-menu* ccl:*edit-menu* ccl:*eval-menu* ccl:*file-menu* ccl:*tools-menu* ccl:*windows-menu* (q::quail-menu) (q::quail-plot-menu))) (defun re-enable-menubars (&rest whatever) (declare (ignore whatever)) (loop for m in (union *all-menus* (union (ccl::menubar) (loop for vw in (ccl::windows :class 'view-window) append (loop for (key . m) in (slot-value vw 'wb::title-menus) ;; using key here just suppresses a warning message collect (progn key m))) :test #'eq) :test #'eq) do (ccl::menu-enable m))) (ccl::def-fred-command (:function #\c) re-enable-menubars) ;;; or set this up as a bug fix button. (let* ((menubutton (control-button :text "Do it")) (tv (text-view :text (format NIL "Some buttons to fix bugs. ~%~ Evaluate the form or click on the button."))) (rm (text-view :text "(re-enable-menubars) ")) (vw (make-view-window :left 10 :top (- (wb::screen-height) 40) :bottom (- (wb::screen-height) 100) :right 300 :title "Bug fixes" :background-color wb:*red-colour* :pen-color wb:*yellow-colour*)) (vp (make-viewport vw)) (vl (view-layout :subviews (list tv rm menubutton) :positions '((0 10 5 10) (1 8 2 4) (8 10 2 4)))) ) (setf (left-fn-of menubutton) #'(lambda () (highlight-view menubutton) (set-text menubutton "OK") (eval '(re-enable-menubars)) (set-text menubutton "Done") (downlight-view menubutton) (set-text menubutton "Do it")) ) (draw-view vl :viewport vp) )
2,063
Common Lisp
.l
58
23.689655
77
0.490946
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d96f1b2ef5743ddc47f10c5713b9149986a2eedd8d33349ef0652718deada20c
33,101
[ -1 ]
33,102
bugs.lsp
rwoldford_Quail/comments/bugs.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Known Quail bugs and workarounds ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1995 Statistical Computing Laboratory, ;;; University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1995. ;;; ;;; ;;;-------------------------------------------------------------------------------- ;;; ;;; (in-package :quail-user) ;;; CODE FOR ALL FIXES MAY BE FOUND IN "q:comments;fixes.lsp" ;;; ;;; There may also be bugs and work-arounds that are peculiar to the ;;; operating system (Mac, etc.) ;;; To access those appropriate for yours, evaluate ;;; (bugs) ;;; or, for possibly more information, including bugs, evaluate ;;; (whats-new?) ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;
986
Common Lisp
.l
32
27.65625
88
0.366316
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
00cba6db67452151a01e3d849c93594a6e2c53d9a9f9bd6695d0fbf911dae400
33,102
[ -1 ]
33,120
quail-user-package.lsp
rwoldford_Quail/source/quail-user-package.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-user-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990. ;;; ;;; ;;;---------------------------------------------------------------------------- #+:cl-2 (defpackage "QUAIL-USER" (:use "QUAIL" "COMMON-LISP") (:IMPORT-FROM "QUAIL-KERNEL" "<-" ;28JUN2020 "CGLUE" ;03AUG2023 "REF") ;03AUG2023 (:IMPORT-FROM "VIEWS" "DATASET") ;28JUN2020 (:SHADOWING-IMPORT-FROM "QUAIL" "ARRAY-ELEMENT-TYPE" "ARRAY-RANK" "ARRAY-DIMENSION" "ARRAY-DIMENSIONS" "ARRAY-TOTAL-SIZE" "ARRAY-IN-BOUNDS-P" "ADJUSTABLE-ARRAY-P" "ARRAY-ROW-MAJOR-INDEX" "SORT" "+" "-" "*" "/" "FLOAT" "RATIONAL" "RATIONALIZE" "<" "<=" "=" ">" ">=" "MIN" "MAX" "EXP" "SQRT" "ISQRT" "ABS" "PHASE" "SIGNUM" "SIN" "COS" "TAN" "CIS" "ASIN" "ACOS" "ATAN" "SINH" "COSH" "TANH" "ASINH" "ACOSH" "ATANH" "NUMERATOR" "DENOMINATOR" "REALPART" "IMAGPART" "FLOOR" "CEILING" "TRUNCATE" "ROUND" "FFLOOR" "FCEILING" "FTRUNCATE" "FROUND" "COMPLEX" "EXPT" "LOG" "REM" "MOD" "GCD" "LCM" "CONJUGATE" "LOGIOR" "LOGXOR" "LOGAND" "LOGEQV" "LOGNAND" "LOGNOR" "LOGANDC1" "LOGANDC2" "LOGORC1""LOGORC2" "LOGNOT" "LOGTEST" "LOGBITP" "ASH" "LOGCOUNT" "INTEGER-LENGTH" "BOOLE") (:nicknames "Q-USER" "quail-user")) #-:cl-2 (in-package "QUAIL-USER" :use '("QUAIL" "PCL" "LISP") :nicknames '("Q-USER" "quail-user"))
2,414
Common Lisp
.l
56
26.589286
87
0.343803
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e5a5a52454fc8cd2c1ad53a7ef7ae554d858c2127d00ed70f5e14597b1a0d93d
33,120
[ -1 ]
33,121
quail-package.lsp
rwoldford_Quail/source/quail-package.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; quail-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; Greg Anglin 1989, 1990, 1992. ;;; R.W. Oldford 1992. ;;; ;;;---------------------------------------------------------------------------- #+:cl-2 (defpackage "QUAIL" (:use "NEW-MATH" "QUAIL-KERNEL" "COMMON-LISP") (:SHADOWING-IMPORT-FROM "NEW-MATH" "ARRAY-ELEMENT-TYPE" "ARRAY-RANK" "ARRAY-DIMENSION" "ARRAY-DIMENSIONS" "ARRAY-TOTAL-SIZE" "ARRAY-IN-BOUNDS-P" "ADJUSTABLE-ARRAY-P" "ARRAY-ROW-MAJOR-INDEX" "SORT" "+" "-" "*" "/" "FLOAT" "RATIONAL" "RATIONALIZE" "<" "<=" "=" ">" ">=" "MIN" "MAX" "EXP" "SQRT" "ISQRT" "ABS" "PHASE" "SIGNUM" "SIN" "COS" "TAN" "CIS" "ASIN" "ACOS" "ATAN" "SINH" "COSH" "TANH" "ASINH" "ACOSH" "ATANH" "NUMERATOR" "DENOMINATOR" "REALPART" "IMAGPART" "FLOOR" "CEILING" "TRUNCATE" "ROUND" "FFLOOR" "FCEILING" "FTRUNCATE" "FROUND" "COMPLEX" "EXPT" "LOG" "REM" "MOD" "GCD" "LCM" "CONJUGATE" "LOGIOR" "LOGXOR" "LOGAND" "LOGEQV" "LOGNAND" "LOGNOR" "LOGANDC1" "LOGANDC2" "LOGORC1""LOGORC2" "LOGNOT" "LOGTEST" "LOGBITP" "ASH" "LOGCOUNT" "INTEGER-LENGTH" "BOOLE") (:nicknames "Q") ) #-:cl-2 (in-package "QUAIL" :use '(new-math quail-kernel pcl lisp) :nicknames '(q))
2,169
Common Lisp
.l
48
28.708333
85
0.345154
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
aed7ce7016caabffdc225c7b38d741a1f2c2fd5ea1a2a00c7c7dd61462e13e81
33,121
[ -1 ]
33,127
browser-load-bugs
rwoldford_Quail/source/analysis-map/browser-load-bugs
(mk::compile-browser) ; - Compiling system "browser" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:cl-extensions.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser bin:hacks.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:grapher-package.fasl" ; - Compiling source file ; "q;Source:Analysis-map:browser:browser-package.lisp" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:browser-package.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:grapher-var.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:grapher.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:grapher-mcl.fasl" ;Warning: FUNCTION APPLY-TO-SELECTED-NODE previously defined in: q;Source:Analysis-map:browser:grapher.lisp ; is now being redefined in: q;Source:Analysis-map:browser:grapher-mcl.lisp ; ; While executing: RECORD-SOURCE-FILE ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:graph-window.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:graph-window-mcl.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:browser-mcl.fasl" ; - Compiling source file "q;Source:Analysis-map:browser:browser.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:browser:browser.lisp" : ; Unused lexical variable PAIR, in GET-NODE-LIST. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:browser:browser.lisp" : ; Undefined function BROWSER::GET-METHOD, in BROWSER::UNDERSTANDS. ; Undefined function BROWSER::PRECEDENCE-LIST, in BROWSER::UNDERSTANDS. ; Undefined function BROWSER::TITLE-MIDDLE-SHIFT-SELECT, in BROWSER::TITLE-MIDDLE-CHOICE. ; Undefined function BROWSER::THE-SHIFT-KEY-P, in BROWSER::TITLE-MIDDLE-CHOICE. ; Undefined function BROWSER::THE-SHIFT-KEY-P, in BROWSER::TITLE-LEFT-CHOICE. ; Undefined function SCROLLING-WINDOW, in BROWSER::SCROLL-WINDOW. ; Undefined function BROWSER::THE-SHIFT-KEY-P, in BROWSER::MIDDLE-CHOICE. ; Undefined function BROWSER::THE-SHIFT-KEY-P, in BROWSER::LEFT-CHOICE. ; Undefined function BROWSER::DIRECT-SUBCLASSES, in BROWSER::GET-LINKS. ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:browser.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:browser ; bin:browser-menu.fasl" ; - Providing system browser NIL ?
2,567
Common Lisp
.l
47
52.361702
109
0.710767
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
055bd2c6369779c24f4f65a21515b2d6b6a4d3a2fd1282ab8f8ca25865d227f8
33,127
[ -1 ]
33,128
display-net-load-bigs
rwoldford_Quail/source/analysis-map/display-net-load-bigs
? (mk::compile-display-network) ; - Compiling system "display-network" ; - Compiling source file ; "q;Source:Analysis-map:display-network:quail-functions-mcl.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:quail-functions-mcl.lisp" : ; Unused lexical variable VARIABLE, in ACCESS-EXPRESSION. ; Undeclared free variable *CURRENT-EVENT*, in WINDOW-ZOOM-EVENT-HANDLER. ; Unused lexical variable MESSAGE, in WINDOW-ZOOM-EVENT-HANDLER. ; Undeclared free variable *CURRENT-EVENT* (2 references), in WINDOW-EVENT. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:quail-functions-mcl.lisp" : ; Undefined function QUAIL::MAKE-RECORD, in QUAIL::WINDOW-EVENT. ; Undefined function QUAIL::RREF (2 references), in QUAIL::WINDOW-EVENT. ; Undefined function QUAIL::WPTR, in QUAIL::WINDOW-EVENT. ; Undefined function QUAIL::WINDOW-SELECT, in QUAIL::WINDOW-CLICK-EVENT-HANDLER. ; Undefined function QUAIL::WINDOW-HIDE, in QUAIL::WINDOW-CLICK-EVENT-HANDLER. ; Undefined function QUAIL::DOUBLE-CLICK-P, in QUAIL::WINDOW-CLICK-EVENT-HANDLER. ; Undefined function QUAIL::CANVAS-DRAW-STRING, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::STRING-WIDTH, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::BITMAP-WIDTH, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::CANVAS-MOVE-TO, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::SET-VIEW-FONT, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::BITMAP-HEIGHT, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::CANVAS-BITBLT, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::GET-WINDOW-BROWSER, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::ICON-TITLE, in QUAIL::VIEW-DRAW-CONTENTS. ; Undefined function QUAIL::WINDOW-HIDE, in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function QUAIL::WINDOW-SHOW, in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function SETF::|QUAIL::ICON-W-OF|, in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function QUAIL::MAKE-POINT, in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function QUAIL::MAKE-CANVAS, in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function QUAIL::GET-WINDOW-BROWSER (2 references), in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function QUAIL::ICON-W-OF, in QUAIL::WINDOW-ZOOM-EVENT-HANDLER. ; Undefined function QUAIL::MAKE-POINT (2 references), in QUAIL::QUAIL-PRINT-HELP. ; Undefined function QUAIL::WPTR, in QUAIL::QUAIL-PRINT-HELP. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-functions-mcl.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:utility.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-icon-mcl.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:prompt-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:dated-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:initable-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:editable-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:indexed-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:named-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:documented-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:linked-object.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:zoom-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:tool-box-link.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:find-where-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:body-menu.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:title-bar-mixin.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-object.fasl" ;Warning: CCL::CLASS QUAIL-OBJECT previously defined in: q;Source:Kernel:Basic:quail-object.lisp ; is now being redefined in: q;Source:Analysis-map:display-network:quail-object.lisp ; ; While executing: CCL:RECORD-SOURCE-FILE ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:memo.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-browser.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:network-view.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:micro-view.fasl" ; - Compiling source file ; "q;Source:Analysis-map:display-network:analysis-network.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:analysis-network.lisp" : ; Unused lexical variable ITEM-CV, in GET-CLASS-MENU-ITEMS. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:analysis-network.lisp" : ; Undefined function QUAIL::APPLY-ANALYSIS-PATH, in QUAIL::ADD-ANALYSIS-NODE. ; Undefined function QUAIL::PROMPT-PRINT (4 references), in QUAIL::INTERPOSE-MEMO. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::BREAK-LINK. ; Undefined function QUAIL::PROMPT-PRINT (2 references), in QUAIL::BREAK-LINK. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::MAKE-LINK. ; Undefined function QUAIL::PROMPT-PRINT (2 references), in QUAIL::MAKE-LINK. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:analysis-network.fasl" ; - Compiling source file ; "q;Source:Analysis-map:display-network:toolbox-network.lisp" ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:toolbox-network.lisp" : ; Undeclared free variable *HORIZ-TREE*, in an anonymous lambda form inside an anonymous lambda form. ; Unused lexical variable REST, in SUB-TOOLBOX. ;Compiler warnings for "Devel:Quail:Source:Analysis-map:display-network:toolbox-network.lisp" : ; Undefined function QUAIL::PUSH-IN-BUFFER, in QUAIL::UNREAD. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::WIDEN-VIEW. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::SUB-TOOLBOX. ; Undefined function QUAIL::BROWSE, in QUAIL::SUB-TOOLBOX. ; Undefined function QUAIL::PROMPT-PRINT, in QUAIL::NAME-THIS-ITEM. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::NARROW-VIEW. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::ADD-TOOLBOX-TREE. ; Undefined function QUAIL::RECOMPUTE, in QUAIL::CREATE-VIEW. ; Undefined function QUAIL::BROWSE, in QUAIL::CREATE-VIEW. ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:toolbox-network.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:analysis-path.fasl" ; - Loading binary file "q;Binary (2.0):Analysis-map:display-network ; bin:quail-methods-mcl.fasl" ; - Providing system display-network NIL ?
7,339
Common Lisp
.l
117
60.623932
104
0.727109
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a929c8cde7eda042bda98f2ddb0cbc85790f5479aa5ae761a767e4c9243cffa9
33,128
[ -1 ]
33,129
views-mods.lsp
rwoldford_Quail/source/analysis-map/Misc/Views-mods-&-+s/views-mods.lsp
;;; replace draw axis methods in axis.lisp to accomodate changes in ;;; canvas-font-ascent, -descent, and -height. (defmethod draw-axis ((self axis) (position (eql :top)) vp) (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (if (tics? self) (let* ((bw (basic-window-of vp)) (font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-height (wb:canvas-font-height font)) (font-ascent (wb:canvas-font-ascent font)) (font-descent (wb:canvas-font-descent font)) (tic-len (ceiling (* 0.7 font-ascent))) tic-end label-posn) (if (> (- ymax ymin) (+ tic-len font-height)) (setf tic-end (- ymax tic-len ) label-posn (- tic-end font-height)) (setf label-posn (+ ymin font-descent) tic-end (+ label-posn font-ascent ))) (draw-horizontal-axis tic-list ymax tic-end label-posn font bw))))) (defmethod draw-axis ((self axis) (position (eql :bottom)) vp) (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (if (tics? self) (let* ((bw (basic-window-of vp)) (font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-height (wb:canvas-font-height font)) (font-ascent (wb:canvas-font-ascent font)) (font-descent (wb:canvas-font-descent font)) (tic-len (ceiling (* 0.7 font-ascent))) tic-end label-posn) (if (> (- ymax ymin) (+ tic-len font-height)) (setf tic-end (+ ymin tic-len ) label-posn (+ tic-end font-descent)) (setf label-posn (- ymax font-ascent) tic-end (- label-posn font-descent ))) (draw-horizontal-axis tic-list ymin tic-end label-posn font bw))))) (defmethod draw-axis ((self axis) (position (eql :right)) vp) (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (if (tics? self) (let* ((bw (basic-window-of vp)) (font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-ascent (wb:canvas-font-ascent font)) (font-descent (wb:canvas-font-descent font)) (font-height (wb:canvas-font-height font)) (tic-len (ceiling (* 0.7 font-ascent))) tic-end label-posn tic-label-wid) (setq tic-label-wid (loop for t-l in tic-list maximize (wb:canvas-string-width (cdr t-l) bw :font font))) (if (> (- xmax xmin) (+ tic-len font-descent tic-label-wid )) (setf tic-end (- xmax tic-len ) label-posn (- tic-end font-descent tic-label-wid)) (setf label-posn xmin tic-end (+ label-posn tic-label-wid ))) (draw-vertical-axis tic-list xmax tic-end label-posn font bw))))) (defmethod draw-axis ((self axis) (position (eql :left)) vp) (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (if (tics? self) (let* ((bw (basic-window-of vp)) (font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-ascent (wb:canvas-font-ascent font)) (font-descent (wb:canvas-font-descent font)) (font-height (wb:canvas-font-height font)) (tic-len (ceiling (* 0.7 font-ascent))) tic-end label-posn tic-label-wid) (setq tic-label-wid (loop for t-l in tic-list maximize (wb:canvas-string-width (cdr t-l) bw :font font))) (if (> (- xmax xmin) (+ tic-len font-descent tic-label-wid )) (setf tic-end (+ xmin tic-len) label-posn (+ tic-end font-descent )) (setf label-posn (- xmax tic-label-wid) tic-end (- label-posn font-descent))) (draw-vertical-axis tic-list xmin tic-end label-posn font bw))))) (defun draw-horizontal-axis (tic-list tic-posn-y1 tic-posn-y2 label-posn font window) (wb:canvas-draw-line (caar tic-list) tic-posn-y1 (caar (last tic-list)) tic-posn-y1 window) (loop for t-l in tic-list for tic-posn-x = (car t-l) for tic-label = (cdr t-l) do (wb:canvas-draw-line tic-posn-x tic-posn-y1 tic-posn-x tic-posn-y2 window) (wb:canvas-move-to (- tic-posn-x (truncate (wb:canvas-string-width tic-label window :font font) 2) ) label-posn window) (wb:canvas-draw-string tic-label window :font font))) (defun draw-vertical-axis (tic-list tic-posn-x1 tic-posn-x2 label-posn font window) (wb:canvas-draw-line tic-posn-x1 (caar tic-list ) tic-posn-x1 (caar (last tic-list)) window) (loop for t-l in tic-list for tic-posn-y = (car t-l) for tic-label = (cdr t-l) do (wb:canvas-draw-line tic-posn-x1 tic-posn-y tic-posn-x2 tic-posn-y window) (wb:canvas-move-to label-posn (- tic-posn-y (truncate (wb:canvas-font-ascent font) 2)) window) (wb:canvas-draw-string tic-label window :font font))) ;;; Just change fun-name at-top? to at-top-p in ;;; macros.lisp ;;; region.lisp and ;;; view-window.lisp
5,588
Common Lisp
.l
108
38.703704
86
0.550452
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
31e865f7ab78c5d94819de74bc8d9fa057b981fa18b795b618904a57e757fed6
33,129
[ -1 ]
33,131
graph-redisplay-fns.lsp
rwoldford_Quail/source/analysis-map/Misc/browser-obs/graph-redisplay-fns.lsp
;;; ;;; Graph redisplay functions ;;; (defun make-translation-vector (window) (make-position (- (get-window-x-offset window)) (- (+ (get-window-y-offset window) (get-window-height window))))) (defun mac-redisplay-graph (window &aux (w-ptr (ask window wptr))) (_BeginUpdate :ptr w-ptr) (graph::redisplay-graph window (make-translation-vector window)) (_EndUpdate :ptr w-ptr)) (defun redisplay-graph-in-rect (window rect) (with-port (ask window wptr) (_InvalRect :ptr rect)) (mac-redisplay-graph window))
587
Common Lisp
.l
15
32.6
68
0.636684
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fe4f2f52386f7bf04e4e70c0eeb19a879e619efafae8697c752e540ddba53df3
33,131
[ -1 ]
33,133
graph-var.lsp
rwoldford_Quail/source/analysis-map/Misc/browser-obs/graph-var.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; graph-var.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; some global variables must be customised to the machine ;;; ;;; Authors: ;;; G. Desvignes 1988-89 ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :graph) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*max-height-graph* *max-width-graph* *min-height-graph* *min-width-graph*))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; global variable definitions ;;; (defvar *graph-cache-node-labels* nil) (defvar *graph-default-font* '("helvetica" 10)) (defvar *graph-default-node-border* nil) (defvar *graph-default-node-font* nil) (defvar *graph-default-node-label-shade* nil) (defvar *max-height-graph* (/ wb:*screen-height* 2)) (defvar *max-width-graph* (/ wb:*screen-width* 2)) (defvar *min-height-graph* 30) (defvar *min-width-graph* 100) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; constant definition ;;; (unless (boundp '*graph-origin*) (defconstant *graph-origin* (make-position 0 0)))
1,546
Common Lisp
.l
44
31.795455
86
0.440541
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
17b8613ff5bddd5755796eea394a2f23541bf77615fb1e13cf9e7f9b29e29aa4
33,133
[ -1 ]
33,136
graph-obs.lsp
rwoldford_Quail/source/analysis-map/Misc/browser-obs/graph-obs.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; This file contains the functions and data structures which ;;; originally defined in the file having the same name without the ;;; "obs" (for obsolete) extension. All code contained here has been ;;; superseded by other code. ;;; ;;; RWO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Functionality replaced by canvas-draw-rectangle (defun draw-area-box (left bottom width height border window &optional texture) "Draw the border of the region defined by LEFT, BOTTOM, WIDTH, HEIGHT." (fill-region window left bottom border height texture) ; draw Left edge (fill-region window ; draw Top edge (+ left border) (- (+ bottom height) border) (- width border border) border texture) (fill-region window ; draw Bottom edge (+ left border) bottom (- width border border) border texture) (fill-region window ; draw Right edge (- (+ left width) border) bottom border height texture)) (defun draw-graph-node-border (border left bottom width height stream) "Interprets and draws the node border." (cond ((null border)) ; ((eq border t) (draw-area-box left bottom width height 1 stream)) ((integerp border) (or (<= border 0) (draw-area-box left bottom width height border stream))) ((listp border) (draw-area-box left bottom width height (first border) stream (second border))) (t (quail-error "Illegal border : ~S" border))))
2,016
Common Lisp
.l
43
33.813953
80
0.481879
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
89e14ba6e99116edfd016db48480d8f1ab411afc709ff353fa727fd761818eb6
33,136
[ -1 ]
33,142
z-load-base.lsp
rwoldford_Quail/source/analysis-map/Misc/old-setup-files/z-load-base.lsp
;;; ;;; loader for Z ;;; (let ((old-path-name *default-pathname-defaults*)) (setq *default-pathname-defaults* *Z-directory*) (load 'Z-functions) (load 'Z-utility) (load 'Z-icon) (load 'Z-mixins) (load 'Z) (load 'ref-arrays) (load 'Z-browser) (load 'network-view) (load 'micro-view) (load 'analysis-network) (load 'toolbox-network) (load 'analysis-path) (load 'extended-ops) (load 'Z-binops) (load 'Z-reexps) (load 'junk-extract) (load 'Z-methods) ;; This line should be useless, but it seems there is a problem with pcl, and ;; without it, the after method of initialize-instance defined in pcl is lost ;; when another after method of initialize-instance is defined in Z-mixins (load 'menu) (setq *default-pathname-defaults* old-path-name)) ;;; ;;; define a function to display a browser of the Z classes ;;; (in-package 'Z) (defun class-browse-Z (&aux browser) (browse (setq browser (make-instance 'browser::browser)) (mapcar (function find-class) '(find-where-mixin tool-box-link-mixin body-menu-mixin title-bar-mixin named-object-mixin prompt-mixin documented-object-mixin indexed-object-mixin linked-object-mixin initable-object-mixin))) (recompute browser)) ;;; ;;; display the Z classes ;;; (class-browse-Z)
1,600
Common Lisp
.l
50
23.28
81
0.581028
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b75dd202ba27e37f1adba73c73e9a9146f614e1092f2e3ffcb92f93d88a2f6f6
33,142
[ -1 ]
33,143
z-load.lsp
rwoldford_Quail/source/analysis-map/Misc/old-setup-files/z-load.lsp
(unless (quail-y-or-n-p "Current value of *Z-directory* is ~s ~%~ Is this correct?" (if (boundp '*Z-directory*) *Z-directory* (setf *Z-directory* NIL))) (setf *Z-directory* (progn (write-line (format NIL "~%Enter the new value of *Z-directory*") *quail-query-io*) (read-line *quail-query-io*)))) (let ((old-path-name *default-pathname-defaults*)) (setf *default-pathname-defaults* *Z-directory*) (load 'z-load-browser) (load 'z-load-base) (setf *default-pathname-defaults* old-path-name)) (in-package 'Z) (init-list-of-icons)
694
Common Lisp
.l
17
29.941176
83
0.551515
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ad490c7a50136a675c7da528bd67ae29595edc3b88c69adbcf3c1d28d99d28e6
33,143
[ -1 ]
33,145
compile-Z.mac
rwoldford_Quail/source/analysis-map/Misc/old-setup-files/compile-Z.mac
;;; ;;; Compiler for Z. To compile, just load file compile-Z ;;; (let ((old-path-name *default-pathname-defaults*)) (setf *default-pathname-defaults* *Z-directory*) (load 'Z-functions.mac) (compile-file 'Z-functions.mac) (load 'Z-utility.lisp) (compile-file 'Z-utility.lisp) (load 'Z-icon.mac) (compile-file 'Z-icon.mac) (load 'Z-mixins.lisp) (compile-file 'Z-mixins.lisp) (load 'Z.lisp) ;---------------- (compile-file 'Z.lisp) (load 'Z-arrays.lisp) (compile-file 'Z-arrays.lisp) (load 'Z-browser.lisp) (compile-file 'Z-browser.lisp) (load 'network-view.lisp) (compile-file 'network-view.lisp) (load 'micro-view.lisp) (compile-file 'micro-view.lisp) (load 'analysis-network.lisp) (compile-file 'analysis-network.lisp) (load 'toolbox-network.lisp) (compile-file 'toolbox-network.lisp) (load 'analysis-path.lisp) (compile-file 'analysis-path.lisp) (load 'extended-ops.lisp) (compile-file 'extended-ops.lisp) (load 'Z-binops.lisp) (compile-file 'Z-binops.lisp) (load 'Z-reexps.lisp) (compile-file 'Z-reexps.lisp) (load 'junk-extract.lisp) (compile-file 'junk-extract.lisp) (load 'Z-methods.mac) (compile-file 'Z-methods.mac) ;; This line should be useless, but it seems there is a problem with pcl, and ;; without it, the after method of initialize-instance defined in pcl is lost ;; when another after method of initialize-instance is defined in Zmixins (load 'menu.fasl) (setf *default-pathname-defaults* old-path-name))
1,613
Common Lisp
.l
45
30.577778
81
0.665161
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
03f28d66425d424d8f5087879720a9bceff709b49c14e885b8db48239ce0db96
33,145
[ -1 ]
33,147
Z-setup.lsp
rwoldford_Quail/source/analysis-map/Misc/old-setup-files/Z-setup.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Z-setup.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1990 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1990. ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; (setf *z-directory* (pathname #+:ccl "ccl;DINDE to Z:" ))
562
Common Lisp
.l
20
25.1
86
0.240296
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2d82f7ea4c0159aa8a791298f1cd275c4873f373eb49bbb30a97c69595dd4c36
33,147
[ -1 ]
33,150
views-package.lsp
rwoldford_Quail/source/views/views-package.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; views-package.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991. ;;; ;;; ;;;---------------------------------------------------------------------------- #+:cl-2 (defpackage "VIEWS" #+:sbcl-linux (:USE :clim :clim-lisp :clim-extensions) ;"COMMON-LISP") ; 19 November 2019 #+:aclpc-linux (:USE :common-lisp) (:nicknames "VI" "VW") (:SHADOW "DRAW-LINES" "DRAW-ARROW") ;; from the CLIM: defintions 19MAR2022 gwb (:IMPORT-FROM "QUAIL-KERNEL" *QUAIL-RESTORE-LISP-FUNCTIONS* *QUAIL-STANDARD-INPUT* *QUAIL-STANDARD-OUTPUT* *QUAIL-QUERY-IO* *QUAIL-DEBUG-IO* *QUAIL-ERROR-OUTPUT* *QUAIL-TRACE-OUTPUT* *QUAIL-TERMINAL-IO* QUAIL-PRINT QUAIL-ERROR QUAIL-CERROR QUAIL-QUERY QUAIL-Y-OR-N-P QUAIL-YES-OR-NO-P ADD-MIXIN-TO-QUAIL-OBJECT "<-") ;;05FEB2020 (:IMPORT-FROM "WINDOW-BASICS" HANDLE-KEY-EVENT *black-color* *white-color* *pink-color* *red-color* *orange-color* *yellow-color* *green-color* *dark-green-color* *light-blue-color* *blue-color* *purple-color* *brown-color* *tan-color* *light-gray-color* *gray-color* *dark-gray-color* *gray-color* *light-gray-color* *dark-gray-color* *bright-green-color* *magenta-color* *black-shade* *white-shade* *light-gray-shade* *dark-gray-shade* *gray-shade*) (:export *black-color* *white-color* *pink-color* *red-color* *orange-color* *yellow-color* *green-color* *dark-green-color* *light-blue-color* *blue-color* *purple-color* *brown-color* *tan-color* *light-gray-color* *gray-color* *dark-gray-color* *gray-color* *light-gray-color* *dark-gray-color* *bright-green-color* *magenta-color* *black-shade* *white-shade* *light-gray-shade* *dark-gray-shade* *gray-shade*) ) #-:cl-2 (in-package "VIEWS" :use '(;;;;window-basics pcl lisp) :nicknames '(vw vi)) #-:cl-2 (export '()) #-:CL-2 (IMPORT '(WINDOW-BASICS:HANDLE-KEY-EVENT wb:*black-color* wb:*white-color* wb:*pink-color* wb:*red-color* wb:*orange-color* wb:*yellow-color* wb:*green-color* wb:*dark-green-color* wb:*light-blue-color* wb:*blue-color* wb:*purple-color* wb:*brown-color* wb:*tan-color* wb:*light-gray-color* wb:*gray-color* wb:*dark-gray-color* wb:*gray-color* wb:*light-gray-color* wb:*dark-gray-color* wb:*bright-green-color* wb:*magenta-color* wb:*black-shade* wb:*white-shade* wb:*light-gray-shade* wb:*dark-gray-shade* wb:*gray-shade* QUAIL-KERNEL::*QUAIL-RESTORE-LISP-FUNCTIONS* QUAIL-KERNEL:*QUAIL-STANDARD-INPUT* QUAIL-KERNEL:*QUAIL-STANDARD-OUTPUT* QUAIL-KERNEL:*QUAIL-QUERY-IO* QUAIL-KERNEL:*QUAIL-DEBUG-IO* QUAIL-KERNEL:*QUAIL-ERROR-OUTPUT* QUAIL-KERNEL:*QUAIL-TRACE-OUTPUT* QUAIL-KERNEL:*QUAIL-TERMINAL-IO* QUAIL-KERNEL:QUAIL-ERROR QUAIL-KERNEL:QUAIL-CERROR QUAIL-KERNEL:QUAIL-QUERY QUAIL-KERNEL:QUAIL-Y-OR-N-P QUAIL-KERNEL:QUAIL-YES-OR-NO-P) "VIEWS")
4,413
Common Lisp
.l
140
20.15
92
0.44952
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
abb1ba5cfc1c9fdec24133491e032df5629a010a174a03c367ac6196330ddbb4
33,150
[ -1 ]
33,152
one-per-case.lsp
rwoldford_Quail/source/views/d-views/one-per-case.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; one-per-case.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( one-per-case-mixin collect-views-in-region justified-line))) ;;;---------------------------------------------------------------------------------- (defclass one-per-case-mixin (draggable-brush-view-mixin pass-draws-to-subviews) ((middle-menu :allocation :class :initform nil) (style-keys :initform '(:size :fill? :font :color) :allocation :class) ) (:default-initargs :size *default-point-size* :font *default-label-font* :fill? *default-point-fill?*)) (defgeneric collect-views-in-region (one-per-case-mixin &key viewport region) (:documentation "Select case views in region.~ If region is nil, create using mouse. ")) (defclass justified-line (justification-mixin oriented-line ) ((middle-menu :allocation :class :initform nil)) (:default-initargs :justification :bottom :justification-menu? t)) (defmethod set-justification ((self justified-line) justification &key (draw? nil) ) (if draw? (erase-view self)) (setf (justification-of self) justification) (compute-line-endpoints self) (loop for vp in (viewports-of self) for p = (find-parent self :viewport vp) when p do (map-subviews-to-viewport p nil (list self))) (if draw? (draw-view self))) (defmethod list-legal-justifications ((self justified-line)) (list :left :right :left-right :bottom :top :top-bottom)) #| Already in views/views-generl/view-ops.lsp .. email from rwo 25SEP2023 (defmethod identify-view ((self view) &key viewport ) (setq viewport (or viewport (car (viewports-of self)))) (select-one self) (let ((s (viewed-object-description-string self)) (parent (find-parent self :viewport viewport))) (if parent (setq s (format nil "~A: At ~A" s (subview-location-string parent self) ))) (quail-print s))) |# (defmethod orientation-of ((self justified-line)) (case (justification-of self) (:left :horizontal) (:right :horizontal) (:top :vertical) (t :vertical))) ;;;---------------------------------------------------------------------------------- (defmethod construct-sub-views ((self one-per-case-mixin) &rest initargs &key case-view ordered-case-views? (linkable-case-views? t) case-views-from (labels #'identifier-name) colors ) (if (member labels (variates-of self) :test #'eq-variate-exprs) (setq labels (case-access-fn self labels))) (let* ((subview-arglist (subview-arg-list case-view 'point-symbol)) (dummy (apply #'view subview-arglist)) (sub-type (class-name (class-of dummy))) (vo (cases-of self))) (when case-view (loop for key in (slot-value self 'style-keys) for hold = (getf subview-arglist key :xxx) unless (eq hold :xxx) do (set-draw-style self key hold))) (if (typep case-views-from 'view) (setf case-views-from (descendant-views-of-type case-views-from sub-type)) ) (unless (listp case-views-from) (setq case-views-from nil)) (unless (= (length vo) (length case-views-from)) (setq ordered-case-views? nil)) (flet ((get-subview(case i) (if (and ordered-case-views? case-views-from) (nth i case-views-from) (or (loop for cv in case-views-from for case-cv = (viewed-object-of cv) thereis (and (eq-dataset case case-cv) cv)) (and (listp case) (loop for cv in case-views-from for case-cv = (viewed-object-of cv) thereis (and (listp case-cv) (= (length case) (length case-cv)) (every #'eq-dataset case case-cv) cv))))))) (unless (subviews-of self) (setf (subviews-of self) (loop with sub-styles with first-col with new-sub for case in vo for i upfrom 0 for l in (if (listp labels) labels (make-list (length vo) :initial-element labels)) for old-sub = (get-subview case i) collect (cond ((typep old-sub sub-type) old-sub) (t (setq new-sub (apply #'view :data case :left-fn '(identify-view :viewport) ;; :label l :text l :linkable? t (append subview-arglist (list :label l :text l :linkable? linkable-case-views?)))) (when (null sub-styles) (setq sub-styles (loop with new = (append subview-arglist initargs ) for k in (slot-value new-sub 'style-keys) for m = (member k new) when m collect k and collect (cadr m))) (setq first-col (getf sub-styles :color))) (when colors (setf (getf sub-styles :color) (or (nth i colors) first-col))) (set-drawing-style new-sub :styles sub-styles) (if (and old-sub (link-table-of old-sub)) (fast-link2-views old-sub new-sub :draw? nil :link-table (link-table-of old-sub))) new-sub)) )))))) (defmethod init-position-subviews ((self one-per-case-mixin) &key ) (let* ((br (subview-position-region self)) (subs (subviews-of self)) (wid/2 (/ (width-of br) 20)) (ht/2 (/ (height-of br) 20)) (coords (plot-coords-of self )) (status (case-status-of self)) ) (setf (sub-view-locns-of self) (loop for (x y) in coords for s in status for sv in subs for region = (cond ((invalid-status-p s) (make-region)) #| ((typep sv 'justified-line) (case (justification-of sv) (:left (make-region (left-of br) x (- y ht/2) (+ y ht/2))) (:right (make-region x (right-of br) (- y ht/2) (+ y ht/2))) (:top (make-region (- x wid/2) (+ x wid/2) y (top-of br))) (t (make-region (- x wid/2) (+ x wid/2) (bottom-of br) y)))) ((typep sv 'oriented-line) (if (eql (orientation-of sv) 'horizontal) (make-region (left-of br) x (- y ht/2) (+ y ht/2)) (make-region (- x wid/2) (+ x wid/2) (bottom-of br) y))) |# (t (make-region (- x wid/2) (+ x wid/2) (- y ht/2) (+ y ht/2)))) collect region)))) (defmethod select-subview-status ((self one-per-case-mixin) subview) (let ((p (position subview (subviews-of self)))) (if p (elt (case-status-of self) p)))) (defmethod compute-sub-viewports ((self one-per-case-mixin) &optional viewport subviews) (let ((viewports (if viewport (list viewport) (viewports-of self))) (maps (if viewport (list (select-map-to-viewport self viewport)) (maps-to-viewports-of self))) (subview-locns (if subviews (loop for s in subviews collect (select-sub-view-locn self s)) (sub-view-locns-of self))) (status (if subviews (loop for s in subviews collect (select-subview-status self s)) (case-status-of self))) sv-vp) (setq subviews (or subviews (subviews-of self))) (loop with left and right and bottom and top for sv in subviews for svl in subview-locns for s in status for sv-rad = (cond ((typep sv 'view-with-size) (view-size-of sv)) ((typep sv 'fixed-size-rectangle) (list (rectangle-width-of sv) (rectangle-height-of sv))) (T 5)) do (loop for vp in viewports for map in maps for xy = (apply-transform map (centre-of svl)) for x = (2d-position-x xy) for y = (2d-position-y xy) for width = (if (listp sv-rad) (car sv-rad) sv-rad) for height = (if (listp sv-rad) (cadr sv-rad) sv-rad) for vp-win = (window-of vp) do (setq left (- x sv-rad) right (+ x sv-rad) bottom (- y sv-rad) top (+ y sv-rad)) (cond ((typep sv 'justified-line) (case (justification-of sv) (:left (setq left (left-of vp) right x)) (:right (setq right (right-of vp) left x)) (:top (setq top (top-of vp) bottom y )) (:bottom (setq bottom (bottom-of vp) top y)) (:left-right (setq right (right-of vp) left (left-of vp))) (:top-bottom (setq bottom (bottom-of vp) top (top-of vp))))) ((typep sv 'oriented-line) (if (eql (orientation-of sv) :horizontal) (setq left (left-of vp) right x) (setq bottom (bottom-of vp) top y))) ((typep sv 'label) (let ((rad (* 3 (length (get-text sv))))) (when (> rad width) ;or height which? (if (eql (orientation-of sv) :horizontal) (setq left (- x rad) right (+ x rad) ) (setq bottom (- y rad) top (+ y rad) ))))) (t nil)) (setq sv-vp (make-viewport vp-win left right bottom top)) (unless (active-status-p s) (deactivate-viewport sv-vp)) (add-viewport sv sv-vp vp))))) (defmethod distance-to-location ((self one-per-case-mixin) viewport location) (if (selected-p self viewport location) (let ((locn-c (if (region-p location) (centre-of location) location))) (loop with dist with mdist = (* 2 (radius-of viewport)) for sv in (subviews-of self) for s in (case-status-of self) for sv-vp = (select-viewport sv viewport) when (active-status-p s) do (setq dist (distance-from sv-vp locn-c)) (setq mdist (min mdist dist)) finally (return mdist) )) 10000)) (defmethod get-subview-size ((self one-per-case-mixin) new) (let* ((old (draw-style self :size)) (sub (car (subviews-of-type self 'view-with-size))) (inc (if sub (progn (setf (view-size-of sub) old) (view-size-increment sub)) (if (>= old 3) 2 1)))) (case new (:larger (+ old inc)) (:smaller (- old inc)) (:prompt (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change size from ~A" old))) (t old)))) (defmethod set-subview-size ((self one-per-case-mixin) new &key (draw? t) highlit?) (unless (numberp new) (setq new (get-subview-size self new))) (set-draw-style self :size new) (loop for v in (some-subviews self :highlit? highlit?) do (if (typep v 'view-with-size) (set-view-size v new :draw? draw?) (loop for vp in (viewports-of v) for vp-copy = (copy-region vp) do (set-viewport-size vp-copy (+ 2 new)) (reshape-viewport v vp :new-location vp-copy :draw? t))))) (defmethod set-invisible-subviews ((self one-per-case-mixin) new &key (draw? t) highlit?) (loop for v in (some-subviews self :highlit? highlit?) do (set-drawing-style v :invisible? new :draw? draw?))) (defmethod change-subview-class ((self one-per-case-mixin) new &key (draw? t) highlit?) (loop for v in (some-subviews self :highlit? highlit?) do (if draw? (erase-view v)) (change-class v new) (if draw? (draw-view v)))) (defmethod apply-choice-to-sub ((self one-per-case-mixin) highlit? &rest choice) (loop for v in (some-subviews self :highlit? highlit?) do (apply-choice v choice))) (defmethod bounds-menu-item-list ((self one-per-case-mixin)) (list '("Blowup" (new-bounds :region :compute)) '("Original" (new-bounds :region :original)))) (defmethod get-menu-items ((self one-per-case-mixin) (slot-name (eql 'middle-menu))) (labels ((add-to-set-style(arg) (cond ((not (listp arg)) arg) ((eq (car arg) 'set-drawing-style) (setf (cdr (last arg)) `(:highlit? *selected-subviews-only*)) arg) ;; ((eq (car arg) 'set-color-style) ;; (setf (cdr (last arg)) `(:highlit? *selected-subviews-only*)) ;; arg) ((and (symbolp (car arg)) (fboundp (car arg)) (not (compute-applicable-methods (symbol-function (car arg)) `(,self ,@(cdr arg))))) (push *selected-subviews-only* arg) (push 'apply-choice-to-sub arg) arg) ((equal (car arg) "Size") nil) ((equal (car arg) "Invisible?") nil) (t (mapcar #'add-to-set-style arg))) )) (let* ((sv (car (subviews-of self))) (sv-items (if sv (add-to-set-style (copy-tree (get-menu-items sv 'middle-menu))))) (size (loop for key in '(:smaller :larger :prompt) collect `(,(string-downcase key) (set-subview-size ,key :highlit? *selected-subviews-only*)))) (classes (loop for (c s) in *simple-view-menu-list* collect (list s `(change-subview-class ,c :highlit? *selected-subviews-only*)))) (bounds (bounds-menu-item-list self))) `(,@sv-items ( "Toggle hi" (toggle-highlight )) ( "Size" nil "" :sub-items ,size) ( "Invisible?" (set-invisible-subviews t :highlit? *selected-subviews-only* )) ( "AllVisible?" (set-invisible-subviews nil :highlit? nil)) ( "Class" nil "" :sub-items ,classes) ("-" nil) ( "Bounds" nil "" :sub-items ,bounds) )))) (defmethod toggle-highlight((self one-per-case-mixin) ) (loop for s in ( some-subviews self :highlit? nil) do (set-drawing-style s :highlight? :toggle) (if (any-highlight? s) (push s *selected-views*)) )) (defmethod update-menu-items ((self one-per-case-mixin) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (if (and m (has-draw-style-p self :fill?)) (wb:check-menu-item m "Fill?" (draw-style self :fill?)) ) )) (defmethod menu-properties ((self one-per-case-mixin ) (slot-name (eql 'middle-menu))) (let ((sv (car (subviews-of self)))) (if sv (acons :point-type (class-name (class-of sv)) nil)))) (defmethod styles-to-subs ((self one-per-case-mixin ) ) (list :highlight? :fill? :size :font :color )) (defmethod drag-brush ((self one-per-case-mixin) &key viewport &allow-other-keys) ;; mouse is already depressed (brush-high self :viewport viewport)) (defmethod high-to-down ((self one-per-case-mixin) ) ;; converts highs to down (loop for sv in (subviews-of self) for s in (case-status-of self) when (and (active-status-p s) (any-highlight? sv)) do (set-drawing-style sv :highlight? nil))) (defmethod subview-highlight-styles ((self one-per-case-mixin)) (loop for sv in (subviews-of self) for sv-style = (assoc :highlight? (car (drawing-styles-of sv))) collect sv-style)) (defmacro with-moving-brush (brush viewport &body forms) (let ((move? (gensym)) (x (gensym)) (y (gensym))) `(let* ((,x (wb:mouse-x (window-of ,viewport))) (,y (wb:mouse-y (window-of ,viewport))) (,move? (not (and (= ,x (brush-x ,brush)) (= ,y (brush-y ,brush))))) ) (when ,move? (draw-brush ,brush ,viewport) ,@forms (draw-brush ,brush ,viewport ,x ,y))))) (defmethod brush-high ((self one-per-case-mixin ) &key viewport) (let* ((bw (window-of viewport)) (points (subviews-of self)) (status (case-status-of self)) (sv-vps (loop for sv in points collect (select-viewport sv viewport))) (brush (brush-of self)) (visible-sub (visible-subviews-p self)) (f (brush-test-of self)) (highlight-styles (subview-highlight-styles self)) (mode (brushing-mode-of self)) ) (draw-brush brush viewport (wb:mouse-x bw) (wb:mouse-y bw)) (case mode (:select (loop while (wb:mouse-down-p) do (with-moving-brush brush viewport (loop for sv in points for vis in visible-sub for s in status for vp in sv-vps for sv-style in highlight-styles when (and vis (active-status-p s)) do (if (not (funcall f sv brush vp)) (if (cdr sv-style) (set-highlight-style sv nil)) (unless (cdr sv-style) (set-highlight-style sv t)) ))))) (:union (loop while (wb:mouse-down-p) do (with-moving-brush brush viewport (loop for sv in points for vis in visible-sub for s in status for vp in sv-vps for sv-style in highlight-styles when (and vis (active-status-p s)) do (if (funcall f sv brush vp) (unless (cdr sv-style) (set-highlight-style sv t)) ))))) (:intersection (loop while (wb:mouse-down-p) do (with-moving-brush brush viewport (loop for sv in points for vis in visible-sub for s in status for vp in sv-vps for sv-style in highlight-styles when (and vis (active-status-p s)) do (if (not (funcall f sv brush vp)) (if (cdr sv-style) (set-highlight-style sv nil)) ))))) (:difference (loop while (wb:mouse-down-p) do (with-moving-brush brush viewport (loop for sv in points for vis in visible-sub for s in status for vp in sv-vps for sv-style in highlight-styles when (and vis (active-status-p s)) do (if (funcall f sv brush vp) (if (cdr sv-style) (set-highlight-style sv nil)) ))))) (t nil)) (draw-brush brush viewport) (set-selected-views (loop for sv in points for sv-style in highlight-styles for vis in visible-sub for s in status when (and vis (active-status-p s) (cdr sv-style)) collect sv)))) (defmethod visible-subviews-p ((self one-per-case-mixin)) (loop with br = (bounding-region-of self) for svl in (sub-view-locns-of self) for s in (case-status-of self) collect (and (active-status-p s) (intersects-p br svl) t))) (defmethod print-subview-coords ((self one-per-case-mixin) sub) (let ((coords (coords-of self :cases (list (viewed-object-of sub))))) (print (first coords)))) (defmethod bounds-of-selected ((self one-per-case-mixin)) (loop for sub in (subviews-of self) for status in (case-status-of self) for (x y) in (plot-coords-of self) when (and (draw-style sub :highlight?) (eq status t)) minimize x into x-min maximize x into x-max minimize y into y-min maximize y into y-max finally (if (= x-min x-max) (incf x-max 0.01)) (if (= y-min y-max) (incf y-max 0.01)) (return (make-region x-min x-max y-min y-max)))) (defmethod new-bounds ((self one-per-case-mixin) &key (region :compute) pretty?) (unless (region-p region) (setq region (case region (:prompt (apply #'make-region (wb:prompt-user :result-type 'list :read-type :read :prompt-string "(left right bottom top)"))) (:original (original-bounds self :draw? t) nil) (:compute (bounds-of-selected self)) (t NIL)))) (if (region-p region) (change-bounding-region self region :pretty? pretty?))) (defmethod new-case-status ((self one-per-case-mixin) cases status &key rescale? draw? ) (let ((vp-fn (if (ignore-status-p status ) #'(lambda(v vp) (when (active-viewport-p vp) (unless (or rescale? draw? ) (erase-view v :viewport vp)) (deactivate-viewport vp))) #'(lambda(v vp) (unless (active-viewport-p vp) (activate-viewport vp) (unless (or rescale? draw? ) (draw-view v :viewport vp)))))) (viewports (viewports-of self)) (case-status (case-status-of self))) (if (eq cases (cases-of self)) (loop for s in case-status for sv in (subviews-of self) unless (invalid-status-p s) do (loop for vp in viewports do (funcall vp-fn sv (select-viewport sv vp)))) (loop for sv in (subviews-of self) for vo = (viewed-object-of sv) for s in case-status unless (invalid-status-p s) do (if (or (member vo cases :test #'eq-dataset) (member (identifier-of vo) cases :test #'eq-identifiers)) (loop for vp in viewports do (funcall vp-fn sv (select-viewport sv vp))))))) ) (defmethod new-sub-views ((self one-per-case-mixin) &key) (let* ((status (case-status-of self)) (viewports (viewports-of self))) (loop for sv in (subviews-of self) for s in status do (loop for vp in viewports for vp-sub = (select-viewport sv vp) do (if (active-status-p s) (activate-viewport vp-sub) (deactivate-viewport vp-sub)) )))) (defmethod remove-subview ((self one-per-case-mixin) subview ) (loop for vp in (viewports-of self) for sv-vp = (select-viewport subview vp ) do (erase-view subview :viewport sv-vp ) (deactivate-viewport sv-vp))) (defmethod delete-subview ((self one-per-case-mixin) subview ) (loop for vp in (viewports-of self) for sv-vp = (select-viewport subview vp ) do (deactivate-viewport sv-vp)))
27,262
Common Lisp
.l
564
31.450355
119
0.475778
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5f578f83378a23fb5c3d065e0e118830c2195a7a026ebe92795c7499dae39d8a
33,152
[ -1 ]
33,153
simple-lines.lsp
rwoldford_Quail/source/views/d-views/simple-lines.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; simple-lines.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(simple-lines ))) (defclass simple-lines (lines-mixin 2d-view simple-view) ((order-fn :initform #'< :initarg :order-fn :accessor order-fn-of)) (:documentation "Draws line segments connecting coords ordered by order-fn")) (defclass multi-style-simple-lines (multi-style-lines-mixin simple-lines) () ) (defmethod initialize-instance :before ((self simple-lines) &key multi-style?) (if (and (eq (class-name (class-of self)) 'simple-lines) multi-style?) (change-class self 'multi-style-simple-lines))) (defmethod new-variable :before ((self simple-lines) &key ) (setf (lines-coords-of self) nil)) (defmethod new-case-status ((self simple-lines) cases status &key ) (declare (ignore cases status)) (setf (lines-coords-of self) nil)) (defmethod lines-coords-of ((self simple-lines)) (declare (ignore args)) (or (slot-value self 'lines-coords) (setf (lines-coords-of self) (if (and (order-fn-of self) (plot-coords-of self)) (let* ((fn (order-fn-of self)) (reorder-styles? (and (typep self 'multi-style-lines-mixin) (= (length (viewed-elements-of self)) (length (plot-coords-of self))))) (c (if reorder-styles? (mapcar #'list (plot-coords-of self) (drawing-styles-of self) (viewed-elements-of self)) (mapcar #'list (plot-coords-of self))))) (flet ((test (a b) (let ((all-nums-a (every #'numberp a)) (all-nums-b (every #'numberp b))) (cond ((and all-nums-a all-nums-b) (funcall fn (car a) (car b))) (all-nums-a t) (t nil))))) (setq c (sort c #'test :key #'car)) (when reorder-styles? (setf (drawing-styles-of self) (mapcar #'second c)) (setf (viewed-elements-of self) (mapcar #'third c))) (loop for (ci) in c while (every #'numberp ci) collect ci))) (plot-coords-of self))))) (defmethod selected-p ((self simple-lines) viewport location) (and (active-viewport-p viewport) (contains-p viewport location)))
3,306
Common Lisp
.l
67
37.089552
92
0.484906
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4569f3217d07556e67bbb0599fcc7a059ba7ed15df9228e3f81a4d22273da0ef
33,153
[ -1 ]
33,154
boxplot.lsp
rwoldford_Quail/source/views/d-views/boxplot.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; boxplot.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(boxplot-view boxplot-box))) ;;;---------------------------------------------------------------------------------- (defclass boxplot-view (styles-cache 1d-view compound-view ) ((bp-stats :initform nil :accessor bp-stats-of) (proportional? :initform T :initarg :proportional? :accessor equal-areas-p)) (:default-initargs :orientation :vertical :color *default-bar-color* :symbol *default-point-symbol* :size *default-point-size* :fill? *default-bar-fill?*)) (defmethod get-bp-stats ((self boxplot-view)) (or (slot-value self 'bp-stats) (let* ((coords (sort (active-members self (plot-coords-of self)) #'<))) (setf (bp-stats-of self) (bp-stats coords))))) (defclass boxplot-box (bar) () (:documentation "A kind of bar which handles highlighting as appropriate for ~ the boxes in a boxplot.")) (defmethod construct-sub-views ((self boxplot-view) &key size symbol fill? color case-view boxes median-view) (let ((style-arglist (append boxes case-view (list :color color :size size :fill? fill? :symbol symbol))) (group-fn #'(lambda(c) (let* ((bounds (get-bp-stats self)) (g (or (position c bounds :test #'<=) 0))) (if (= c (elt bounds 0)) (setq g 1)) g))) (box-o (if (eq (orientation-of self) :horizontal) :vertical :horizontal)) sub-styles sub-vos) (setq boxes (subview-arg-list boxes 'boxplot-box)) (setq case-view (subview-arg-list case-view 'point-symbol)) (setq boxes (append boxes (list :orientation box-o))) (setq median-view (append (subview-arg-list median-view 'point-symbol) (list :size (* 2 (or (getf style-arglist :size) *default-point-size*))) style-arglist )) (multiple-value-setq ( sub-vos sub-styles) (group-and-sort-viewed-objs self group-fn 5 (get-viewed-obj-styles self :fill? (getf style-arglist :fill?) :color (getf style-arglist :color) :symbol (getf style-arglist :symbol) :size (getf style-arglist :size) ))) (setf (subviews-of self) (append (loop for vos in (cdr sub-vos ) for vo-style in (cdr sub-styles) collect (apply #'view :data vos :check-style? t :viewed-elements vos :drawing-style vo-style boxes)) (loop for vo in (car sub-vos) for vo-style in (car sub-styles) collect (apply #'view :data vo :check-style? t :drawing-style vo-style case-view) ) (list (apply #'view :data nil :fill? t median-view)) )) ) ; end let ); end defmethod (defmethod new-sub-views :before ((self boxplot-view) &key) (setf (bp-stats-of self) nil)) (defmethod max-count-per-unit((self boxplot-view)) (let ((min-len (loop for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) unless (zerop (- b2 b1)) minimize (- b2 b1))) (box-count (/ (length (cases-of self)) 4))) (if (not (null min-len)) (/ box-count min-len )))) (defmethod proportional-bar-widths ((self boxplot-view) &optional mcpu) (when (null mcpu) (setq mcpu (max-count-per-unit self))) (let ((box-count (/ (length (cases-of self)) 4))) (unless (or (zerop mcpu) (zerop box-count)) (if (eq (orientation-of self) :horizontal) (loop with maxh = (* .8 (height-of (bounding-region-of self))) with fac = (/ (* box-count maxh) mcpu) for r in (subview-locns-of self) for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) for barh = (/ fac (- b2 b1)) unless (zerop barh) do (setf (height-of r) barh)) (loop with maxw = (* .8 (width-of (bounding-region-of self))) with fac = (/ (* box-count maxw) mcpu) for r in (subview-locns-of self) for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) for barw = (/ fac (- b2 b1)) unless (zerop barw) do (setf (width-of r) barw)))))) (defmethod init-position-subviews ((self boxplot-view) &key) (let* ((svs (subviews-of self)) (bars (subseq svs 0 4)) (points (subseq svs 4 (length svs))) (point-vos (loop for p in points collect (viewed-object-of p))) (orientation (orientation-of self)) (br (subview-position-region self)) (proportional? (equal-areas-p self)) min width reg) (if (eq orientation :horizontal) (setq min (bottom-of br) width (height-of br) ) (setq min (left-of br) width (width-of br) )) (loop for bar in bars for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) for i upfrom 0 do (setq reg (ecase orientation (:horizontal (if (or (= i 0) (= i 3)) (make-region b1 b2 (+ min (* 0.3 width)) (+ min (* 0.7 width))) (make-region b1 b2 (+ min (* 0.1 width)) (+ min (* 0.9 width))))) (:vertical (if (or (= i 0) (= i 3)) (make-region (+ min (* 0.3 width)) (+ min (* 0.7 width)) b1 b2 ) (make-region (+ min (* 0.1 width)) (+ min (* 0.9 width)) b1 b2)))) ) (place-subview self bar reg)) (if proportional? (proportional-bar-widths self)) (loop with w = (* width .05) for p in (butlast points) for pc in (plot-coords-of self :cases point-vos) do (setq reg (ecase orientation (:horizontal (make-region (- pc w) (+ pc w) (+ min (* 0.3 width)) (+ min (* 0.7 width)))) (:vertical (make-region (+ min (* 0.3 width)) (+ min (* 0.7 width)) (- pc w) (+ pc w) )))) (place-subview self p reg) finally (let ((m (third (bp-stats-of self)))) (place-subview self (car (last points)) (ecase orientation (:horizontal (make-region (- m w) (+ m w) (+ min (* 0.3 width)) (+ min (* 0.7 width)))) (:vertical (make-region (+ min (* 0.3 width)) (+ min (* 0.7 width)) (- m w) (+ m w) )))) )))) #| (defmethod init-position-subviews ((self boxplot-view) &key) (let* ((svs (subviews-of self)) (bars (subseq svs 0 4)) (points (subseq svs 4 (length svs))) (point-vos (loop for p in points collect (viewed-object-of p))) (orientation (orientation-of self)) (br (subview-position-region self)) (proportional? (equal-areas-p self)) min max width length reg) (if (eq orientation :horizontal) (setq min (bottom-of br) max (top-of br) width (height-of br) length (width-of br) ) (setq min (left-of br) max (right-of br) width (width-of br) length (height-of br) )) (if proportional? (let* ((min-bar-length (loop for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) unless (zerop (- b2 b1)) minimize (- b2 b1))) (max-bar-width (* 0.8 width)) (bar-display-area (* (/ min-bar-length length) (/ max-bar-width width))) ) (loop for bar in bars for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) for i upfrom 0 do (let ((bar-length (- b2 b1)) margin bar-width) (if (zerop bar-length) (setf bar-width width) (setf bar-width (* bar-display-area width (/ length bar-length))) ) (setf margin (/ (- width bar-width) 2)) (setf reg (ecase orientation (:horizontal (make-region b1 b2 (+ min margin) (- max margin))) (:vertical (make-region (+ min margin) (- max margin) b1 b2))) ) (place-subview self bar reg))) ) (loop for bar in bars for b1 in (bp-stats-of self) for b2 in (cdr (bp-stats-of self)) for i upfrom 0 do (setq reg (ecase orientation (:horizontal (if (or (= i 0) (= i 3)) (make-region b1 b2 (+ min (* 0.3 width)) (+ min (* 0.7 width))) (make-region b1 b2 (+ min (* 0.1 width)) (+ min (* 0.9 width))))) (:vertical (if (or (= i 0) (= i 3)) (make-region (+ min (* 0.3 width)) (+ min (* 0.7 width)) b1 b2 ) (make-region (+ min (* 0.1 width)) (+ min (* 0.9 width)) b1 b2)))) ) (place-subview self bar reg)) ) (loop with w = (* width .05) for p in (butlast points) for pc in (plot-coords-of self :cases point-vos) do (setq reg (ecase orientation (:horizontal (make-region (- pc w) (+ pc w) (+ min (* 0.3 width)) (+ min (* 0.7 width)))) (:vertical (make-region (+ min (* 0.3 width)) (+ min (* 0.7 width)) (- pc w) (+ pc w) )))) (place-subview self p reg) finally (let ((m (third (bp-stats-of self)))) (place-subview self (car (last points)) (ecase orientation (:horizontal (make-region (- m w) (+ m w) (+ min (* 0.3 width)) (+ min (* 0.7 width)))) (:vertical (make-region (+ min (* 0.3 width)) (+ min (* 0.7 width)) (- m w) (+ m w) )))) )))) |# (defmethod highlight-view ((self boxplot-box) &key viewport ) "Highlight a proportion of each color-fill combintation ~ by examining drawing styles. " (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((op (highlight-operation self)) (axis (orientation-of self)) (new-r (copy-region vp)) (w (window-of vp)) (highlight-proportion 0)) (setf highlight-proportion (or (loop with styles = (style-proportions self '(:highlight?)) for (style) in (first styles) for prop in (second styles) thereis (and style prop)) 0) ) (unless (zerop highlight-proportion) (if (eql axis :horizontal) (scale-sides-by new-r 1 highlight-proportion) (scale-sides-by new-r highlight-proportion 1)) (wb:canvas-highlight-rectangle w (max l (left-of new-r)) (min r (right-of new-r)) (max b (bottom-of new-r)) (min tp (top-of new-r)))) :color *default-highlight-color* :operation op) ))) (defmethod use-x-axis-p ((self boxplot-view)) t) (defmethod use-y-axis-p ((self boxplot-view)) t) (defmethod show-x-axis-p ((self boxplot-view)) (eql (orientation-of self) :horizontal)) (defmethod show-y-axis-p ((self boxplot-view)) (eql (orientation-of self) :vertical))
14,676
Common Lisp
.l
311
29.553055
111
0.430787
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
de0b37fc81128a809b1df29a1d56b6866445d8203fe0cc5f96b49fbe434fdd10
33,154
[ -1 ]
33,155
axis.lsp
rwoldford_Quail/source/views/d-views/axis.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; axis.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(axis ntics-of set-tic-format axis basic-axis tic-list-of ;;(setf tic-list-of) default-axis-settings set-tics set-ntics set-extent))) ;;;---------------------------------------------------------------------------------- (defclass basic-axis (tic-mixin justification-mixin orientation-mixin simple-view ) ((style-keys :initform '(:tics? :tic-labels? :font :color :tic-ruler?) :allocation :class) (tic-length :initform nil :initarg :tic-length :accessor tic-length-of) (middle-menu :allocation :class :initform nil)) (:default-initargs :tic-ruler? t :color *default-axis-color* :tics? t :tic-labels? t :justification :default :initform-fn nil :orientation :horizontal :font wb:*very-small-graphics-font*)) (defclass axis ( basic-axis 1d-view) ((middle-menu :allocation :class :initform nil)) (:default-initargs :initform-fn nil)) #| (defclass axis (tic-mixin justification-mixin 1d-view simple-view ) ((style-keys :initform '(:tics? :tic-labels? :font :color :tic-ruler?) :allocation :class) (tic-length :initform nil :initarg :tic-length :accessor tic-length-of) (middle-menu :allocation :class :initform nil)) (:default-initargs :tic-ruler? t :tics? t :tic-labels? t :justification :default :initform-fn nil :orientation :horizontal :font wb:*very-small-graphics-font*)) |# (defgeneric default-axis-settings (axis) (:documentation "Gives axis default number of tics") ) (defgeneric set-extent (axis min max &key viewport &allow-other-keys) (:documentation "Sets the min and max of axis.~ If min or max is nil the user is prompted.")) (defgeneric set-tics (axis tics &key viewport &allow-other-keys) (:documentation "Changes to tics.~ If tics is nil the user is prompted for a list.")) (defgeneric set-ntics (axis ntics &key viewport &allow-other-keys) (:documentation "Changes to number of tics ntics.~ If ntics is nil the user is prompted.")) (defgeneric set-tic-format (axis format &key viewport &allow-other-keys) (:documentation "Changes tic format.~ If format is nil the user is prompted. ~ Format must be a string that is a legal Common Lisp format ~ for numbers.")) ;;;---------------------------------------------------------------------------------- (defmethod initialize-instance :after ((self basic-axis) &key orientation justification) (if (eq justification :default) (if (eq orientation :horizontal) (setf (justification-of self) :bottom) (setf (justification-of self) :right)))) (defmethod draw-view ((self basic-axis) &key viewport) (let* ((orient (orientation-of self)) (just (justification-of self)) (draw-just (if (eq orient :vertical) (if (eq just :right) :right :left) (if (eq just :top) :top :bottom)))) (with-exposed-viewports self viewport vp (draw-axis self draw-just vp)))) (defmethod erase-view ((self basic-axis) &key viewport) ;; erases the axis in VIEWPORT, if supplied, else erases in all exposed ;; viewports ;; axes have labels outside of bounds-- erase a bigger region (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) rl rb rw rh) (when vp (if (eq (orientation-of self) :horizontal) (setq rl (- (left-of vp) 4) rb (1- (bottom-of vp)) rw (+ 9 (width-of vp)) rh (+ 3 (height-of vp))) (setq rl (- (left-of vp) 1) rb (- (bottom-of vp) 4) rw (+ 3 (width-of vp)) rh (+ 9 (height-of vp)))) (wb:canvas-clear w :canvas-left rl :canvas-bottom rb :width rw :height rh))))) (defun draw-horizontal-axis (tic-list tic-line tic-start tic-end label-posn font tic-labels? window) (if tic-line (wb:canvas-draw-line window (caar tic-list) tic-line (caar (last tic-list)) tic-line)) (loop for t-l in tic-list for tic-posn-x = (car t-l) for tic-label = (cdr t-l) do (wb:canvas-draw-line window tic-posn-x tic-start tic-posn-x tic-end) (wb:canvas-move-to window (- tic-posn-x (truncate (wb:canvas-string-width window tic-label :font font) 2) ) label-posn) (if tic-labels? (wb:with-canvas-font window font (wb:canvas-draw-string window tic-label))))) (defun draw-vertical-axis (tic-list tic-line tic-start tic-end label-posn font tic-labels? window) (if tic-line (wb:canvas-draw-line window tic-line (caar tic-list ) tic-line (caar (last tic-list)))) (loop for t-l in tic-list for tic-posn-y = (car t-l) for tic-label = (cdr t-l) do (wb:canvas-draw-line window tic-start tic-posn-y tic-end tic-posn-y) (wb:canvas-move-to window label-posn (- tic-posn-y (truncate (wb:canvas-font-ascent window :font font) 2)) ) (if tic-labels? (wb:with-canvas-font window font (wb:canvas-draw-string window tic-label))))) (defmethod tic-list-for-viewport ((self basic-axis) vp ) (let* ((orientation (orientation-of self)) (tic-list (normalize-tic-list (tic-list-of self) (tic-format-of self) orientation (justification-of self) )) (map (select-map-to-viewport self vp) ) offset scale min max) (if (eql orientation :horizontal) (setf offset (x-shift map) scale (x-scale map) min (left-of vp) max (right-of vp)) (setf offset (y-shift map) scale (y-scale map) min (bottom-of vp) max (top-of vp))) (loop for tic in tic-list for tic-pos-vp = (round (+ offset (* scale (car tic)))) when (and (>= tic-pos-vp (- min 2)) (<= tic-pos-vp (+ 2 max))) collect (cons tic-pos-vp (cdr tic))))) (defmethod draw-axis ((self basic-axis) (position (eql :top)) vp) (let ((bw (window-of vp))) (wb:with-pen-values bw (draw-style self :color) 1 nil (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (declare (ignore ymin)) (if (draw-style self :tics?) (let* ((font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-ascent (wb:canvas-font-ascent bw :font font)) (font-height (wb:canvas-font-height bw :font font)) tic-len tic-elen tic-end label-posn) (if (eq (tic-length-of self) :viewport) (setf tic-len (height-of vp) tic-elen 0) (setf tic-len (or (first (tic-length-of self)) (ceiling (* 0.7 font-ascent))) tic-elen (or (second (tic-length-of self)) 0))) (setf tic-end (- ymax tic-len ) label-posn (- tic-end font-height)) (draw-horizontal-axis tic-list (and (draw-style self :tic-ruler?) ymax) (+ ymax tic-elen) tic-end label-posn font (draw-style self :tic-labels?) bw)) (if (draw-style self :tic-ruler?) (wb:canvas-draw-line bw xmin ymax xmax ymax))))))) (defmethod draw-axis ((self basic-axis) position vp) (declare (ignore position)) (let ((bw (window-of vp))) (wb:with-pen-values bw (draw-style self :color) 1 nil (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (declare (ignore ymax)) (if (draw-style self :tics?) (let* ((font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-ascent (wb:canvas-font-ascent bw :font font)) (font-descent (wb:canvas-font-descent bw :font font)) tic-len tic-elen tic-end label-posn) (if (eq (tic-length-of self) :viewport) (setf tic-len (height-of vp) tic-elen 0) (setf tic-len (or (first (tic-length-of self)) (ceiling (* 0.7 font-ascent))) tic-elen (or (second (tic-length-of self)) 0))) (setf tic-end (+ ymin tic-len ) label-posn (+ tic-end font-descent)) (draw-horizontal-axis tic-list (and (draw-style self :tic-ruler?) ymin) (- ymin tic-elen) tic-end label-posn font (draw-style self :tic-labels?) bw)) (if (draw-style self :tic-ruler?) (wb:canvas-draw-line bw xmin ymin xmax ymin))))))) (defmethod draw-axis ((self basic-axis) (position (eql :right)) vp) (let ((bw (window-of vp))) (wb:with-pen-values bw (draw-style self :color) 1 nil (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (declare (ignore xmin)) (if (draw-style self :tics?) (let* ((font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-ascent (wb:canvas-font-ascent bw :font font)) (font-descent (wb:canvas-font-descent bw :font font)) (tic-len ) (tic-elen ) tic-end label-posn tic-label-wid) (if (eq (tic-length-of self) :viewport) (setf tic-len (width-of vp) tic-elen 0) (setf tic-len (or (first (tic-length-of self)) (ceiling (* 0.7 font-ascent))) tic-elen (or (second (tic-length-of self)) 0))) (setq tic-label-wid (loop for t-l in tic-list maximize (wb:canvas-string-width bw (cdr t-l) :font font))) (setf tic-end (- xmax tic-len ) label-posn (- tic-end font-descent tic-label-wid)) (draw-vertical-axis tic-list (and (draw-style self :tic-ruler?) xmax) tic-end (+ xmax tic-elen) label-posn font (draw-style self :tic-labels?) bw)) (if (draw-style self :tic-ruler?) (wb:canvas-draw-line bw xmax ymin xmax ymax))))))) (defmethod draw-axis ((self basic-axis) (position (eql :left)) vp) (let ((bw (window-of vp))) (wb:with-pen-values bw (draw-style self :color) 1 nil (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (declare (ignore xmax)) (if (draw-style self :tics?) (let* ((font (draw-style self :font)) (tic-list (tic-list-for-viewport self vp)) (font-ascent (wb:canvas-font-ascent bw :font font)) (font-descent (wb:canvas-font-descent bw :font font)) (tic-len ) (tic-elen ) tic-end label-posn ) (if (eq (tic-length-of self) :viewport) (setf tic-len (width-of vp) tic-elen 0) (setf tic-len (or (first (tic-length-of self)) (ceiling (* 0.7 font-ascent))) tic-elen (or (second (tic-length-of self)) 0))) (setf tic-end (+ xmin tic-len) label-posn (+ tic-end font-descent )) (draw-vertical-axis tic-list (and (draw-style self :tic-ruler?) xmin) tic-end (- xmin tic-elen) label-posn font (draw-style self :tic-labels?) bw)) (if (draw-style self :tic-ruler?) (wb:canvas-draw-line bw xmin ymin xmin ymax))))))) (defmethod default-axis-settings ((self basic-axis)) (setf (ntics-of self) (default-ntics)) (setf (slot-value self 'tic-info) nil) (setf (tic-list-of self) nil)) (defmethod set-extent ((self basic-axis) min max &key viewport (draw? t) (msg "Change extent from ~S to:")) (default-axis-settings self) (let ((pos (prompt-position self viewport)) (dir (axis-of-orientation self))) (cond ((and (null min) (null max)) (let ((new (wb:prompt-user :result-type 'list :read-type :read :prompt-string (format nil msg (coerce (tic-interval-of self) 'list)) :left (2d-position-x pos) :top (2d-position-y pos)))) (setq min (first new)) (setq max (second new)))) ((null min) (setq min (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change min from ~S to:" (min-of (tic-interval-of self))) :left (2d-position-x pos) :top (2d-position-y pos)))) ((null max) (setq max (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change max from ~S to:" (max-of (tic-interval-of self))) :left (2d-position-x pos) :top (2d-position-y pos)))) (t nil)) (change-bounding-region self (region-of-extent self min max) :ignore-x? (eq dir :y) :ignore-y? (eq dir :x) :draw? draw?))) (defmethod set-tics ((self basic-axis) tics &key viewport (draw? t) (msg "Enter a list of tics")) (let ((pos (prompt-position self viewport)) (dir (axis-of-orientation self))) (setf tics (or tics (wb:prompt-user :result-type 'list :read-type :read :prompt-string msg :left (2d-position-x pos) :top (2d-position-y pos)))) (setf (tic-list-of self) tics) (let* ((f (car tics)) (min (if (listp f) (car f) f)) (l (first (last tics))) (max (if (listp l) (car l) l))) (with-constrained-extent self dir draw? (set-bounding-region self :region (region-of-extent self min max) ))))) (defmethod set-ntics ((self basic-axis) ntics &key viewport (draw? t) (msg "Enter number of tics")) (default-axis-settings self) (let ((pos (prompt-position self viewport)) (dir (axis-of-orientation self))) (setf ntics (or ntics (wb:prompt-user :result-type 'integer :read-type :eval :prompt-string msg :left (2d-position-x pos) :top (2d-position-y pos)))) (setf (ntics-of self) ntics) (with-constrained-extent self dir draw? (set-bounding-region self :region (copy-region (bounding-region-of self)))))) (defmethod set-tic-format ((self basic-axis) format &key viewport (draw? t)) (unless format (let* ((pos (prompt-position self viewport)) (format-types '("Lisp format directive" "Fixed-format floating point" "Exponential floating point" "Dollars floating point" "General floating point" "Decimal" "Binary" "Octal" "Hexadecimal" "Radix" )) (format-type (wb:pick-one format-types)) ) (cond ((string-equal format-type "Lisp format directive") (setf format (wb:prompt-user :result-type 'string :read-type :eval :prompt-string (format nil "Format directive string:") :left (2d-position-x pos) :top (2d-position-y pos)))) ((string-equal format-type "Fixed-format floating point") (setf format "~") (setf format-type (wb:collect-input '(("Width in characters" ) ("Digits after decimal place" ) ("Scale factor" ) ("Overflow character" ) ("Pad character" ) ) :prompt-text (format NIL "Fixed-format floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((string-equal (car pair) "Overflow character") (concatenate 'string format (format NIL "'~a" (cdr pair)) ",") ) ((string-equal (car pair) "Pad character") (concatenate 'string format (format NIL "'~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ","))) (concatenate 'string format ",")))) (setf format (concatenate 'string format "F")) ) ((string-equal format-type "Exponential floating point") (setf format "~") (setf format-type (wb:collect-input '(("Width in characters" ) ("Digits after decimal place" ) ("Digits for exponent" ) ("Scale factor" ) ("Overflow character" ) ("Pad character" ) ("Exponent character" ) ) :prompt-text (format NIL "Exponential floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Overflow character") (string-equal (car pair) "Pad character") ) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",") ) ((string-equal (car pair) "Exponent character") (concatenate 'string format (format NIL "'~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ","))) (concatenate 'string format ",")))) (setf format (concatenate 'string format "E")) ) ((string-equal format-type "Decimal") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Decimal. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "D")) ) ((string-equal format-type "Binary") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Binary. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "B")) ) ((string-equal format-type "Octal") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Octal. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "O")) ) ((string-equal format-type "Hexadecimal") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Hexadecimal. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "X")) ) ((string-equal format-type "Radix") (setf format "~") (setf format-type (wb:collect-input '(("Radix" ) ("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Radix. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "R")) ) ((string-equal format-type "Dollars floating point") (setf format "~") (setf format-type (wb:collect-input '(("Digits after decimal place" ) ("Minimum number of digits before decimal") ("Minimum total width" ) ("Pad character" ) ) :prompt-text (format NIL "Dollars floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (if (string-equal (car pair) "Pad character") (concatenate 'string format (format NIL "'~a" (cdr pair)) ) (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) (concatenate 'string format ",")))) (setf format (concatenate 'string format "$")) ) ((string-equal format-type "General floating point") (setf format "~") (setf format-type (wb:collect-input '(("Width in characters" ) ("Digits after decimal place" ) ("Digits for exponent" ) ("Scale factor" ) ("Overflow character" ) ("Pad character" ) ("Exponent character" ) ) :prompt-text (format NIL "General floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Overflow character") (string-equal (car pair) "Pad character") ) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",") ) ((string-equal (car pair) "Exponent character") (concatenate 'string format (format NIL "'~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ","))) (concatenate 'string format ",")))) (setf format (concatenate 'string format "G")) ) (T (setf format (wb:prompt-user :result-type 'string :read-type :eval :prompt-string (format nil "Format directive string:") :left (2d-position-x pos) :top (2d-position-y pos)))) ) ) ) (setf (tic-format-of self) format) (if draw? (draw-view self :erase? t))) (defmethod style-menu-items ((self basic-axis)) `(("Font" nil "" :sub-items ,(font-menu-items)) ("Tics On?" (set-drawing-style :tics? :toggle)) ("Tics Labels?" (set-drawing-style :tic-labels? :toggle)) )) (defmethod get-menu-items ((self basic-axis) (slot-name (eql 'middle-menu))) `(( "#Tics" (set-ntics nil :viewport)) ( "Tic Limits" (set-extent nil nil :viewport)) ( "Tic List" (set-tics nil :viewport)) ( "Tic format" (set-tic-format nil :viewport)) )) (defmethod update-menu-items :before ((self basic-axis) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (wb:check-menu-item m "Tics On?" (draw-style self :tics?)) (wb:check-menu-item m "Tics Labels?" (draw-style self :tics?)) )) (defmethod new-variable ((self axis) &key ) (declare (ignorable self)) ;(ignore self)) ; 04SEP2023 (call-next-method) ) (defmethod new-variable :before ((self axis) &key ) (setf (tic-list-of self) nil)) (defmethod hide-axis-p ((self basic-axis)) (case (orientation-of self) (:vertical (not (some #'(lambda(v) (and (not (typep v 'axis)) (show-y-axis-p v))) (link-bounds-y-of self)))) (t (not (some #'(lambda(v) (and (not (typep v 'axis)) (show-x-axis-p v))) (link-bounds-x-of self)))))) #| Currently, plotting on an alternate (eg log) scale is not supported, without actually transforming the data via x-function y-function, etc. To allow alternate scales, add a -plot-scale variable to each 1d and 2d view, whose default value is identity, but could be log... This additonal transformation would be applied to the cases (after -function -transform), see the function case-coords in abstract-views.lisp. Axis should be modified to provide tic-labels on the original scale. |#
35,799
Common Lisp
.l
759
27.620553
126
0.425498
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
24fd6703d18d8c322ea8866f17066fa03e38cbfcad5ae5d61dae84fee6284223
33,155
[ -1 ]
33,156
grid-view.lsp
rwoldford_Quail/source/views/d-views/grid-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grid-view.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1998 National University of Ireland Maynooth ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(grid-lines grid-view set-grid))) (defclass grid-lines (basic-axis) ((style-keys :initform '(:tics? :color :font ) :allocation :class) (line-interval :initform nil :accessor line-interval-of :initarg :line-interval) (middle-menu :allocation :class :initform nil)) (:default-initargs :tic-length :viewport :box? nil )) (defmethod draw-view ((self grid-lines) &key viewport) (let ((orient (orientation-of self)) (c (draw-style self :color))) (with-exposed-viewports self viewport vp (draw-grid-lines self orient vp :color c)))) (defmethod erase-view ((self grid-lines) &key viewport ) (let ((orient (orientation-of self))) (with-exposed-viewports self viewport vp (draw-grid-lines self orient vp :operation :boole-andc1)))) (defmethod highlight-operation ((self grid-lines)) :default) (defmethod highlight-view ((self grid-lines) &key viewport ) (let ((orient (orientation-of self))) (with-exposed-viewports self viewport vp (draw-grid-lines self orient vp :operation (highlight-operation self) :color *default-highlight-color* )))) (defmethod invert-view ((self grid-lines) &key viewport ) (let ((orient (orientation-of self))) (with-exposed-viewports self viewport vp (draw-grid-lines self orient vp :operation :boole-xor)))) (defmethod draw-grid-lines ((self grid-lines) orient vp &key color operation) (let ((bw (window-of vp)) (tic-list (tic-list-for-viewport self vp)) (line-interval (line-interval-of self))) (wb:with-pen-values bw color 1 operation (multiple-value-bind (xmin xmax ymin ymax) (bounds-of vp) (if (draw-style self :tics?) (if (eq orient :horizontal) (progn (if line-interval (let* ((map (select-map-to-viewport self vp) ) ( oy (y-shift map)) ( sy (y-scale map))) (unless (eq (car line-interval) :viewport) (setq ymin (truncate (+ oy (* sy (car line-interval)))))) (unless (eq (cadr line-interval) :viewport) (setq ymax (truncate (+ oy (* sy (cadr line-interval)))))))) (loop for t-l in tic-list for tic-x = (car t-l) do (wb:canvas-draw-line bw tic-x ymin tic-x ymax))) (progn (if line-interval (let* ((map (select-map-to-viewport self vp) ) ( ox (x-shift map)) ( sx (x-scale map))) (unless (eq (car line-interval) :viewport) (setq xmin (truncate (+ ox (* sx (car line-interval)))))) (unless (eq (cadr line-interval) :viewport) (setq xmax (truncate (+ ox (* sx (cadr line-interval)))))))) (loop for t-l in tic-list for tic-y = (car t-l) do (wb:canvas-draw-line bw xmin tic-y xmax tic-y))))))))) (defmethod style-menu-items ((self grid-lines)) ) (defmethod get-menu-items ((self grid-lines) (slot-name (eql 'middle-menu))) ) (defmethod get-menu-items :around ((self grid-lines) (slot-name (eql 'middle-menu))) (append (style-menu-items self) `(( "#Lines" (set-ntics nil :viewport :msg "Enter number of lines")) ( "Line positions" (set-tics nil :viewport :msg "Enter line locations")) ( "Line length" (set-line-length nil nil :viewport )) ( "Grid extent" (set-extent nil nil :viewport)) ))) (defmethod set-line-length ((self grid-lines) min max &key viewport (draw? t) ) (let ((pos (prompt-position self viewport)) (current (line-interval-of self)) ) (cond ((and (null min) (null max)) (let ((new (wb:prompt-user :result-type 'list :read-type :read :prompt-string (if current (format nil "Change min and max from ~S to:" current) (format nil "Change min and max from viewport extent to:" )) :left (2d-position-x pos) :top (2d-position-y pos)))) (setq min (first new)) (setq max (second new)))) ((null min) (setq min (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (if current (format nil "Change min from ~S to:" (first current)) (format nil "Change min from viewport minimum to:" )) :left (2d-position-x pos) :top (2d-position-y pos)))) ((null max) (setq max (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (if current (format nil "Change max from ~S to:" (second current)) (format nil "Change max from viewport maximum to:" )) :left (2d-position-x pos) :top (2d-position-y pos)))) (t nil)) (if draw? (erase-view self :viewport viewport )) (setf (line-interval-of self) (list min max)) (if draw? (draw-view self :viewport viewport :erase? nil)))) (defmethod region-of-extent ((self grid-lines) min max) (multiple-value-bind (l r b tp) (bounds-of self) (ecase (orientation-of self) (:horizontal (make-region (min min l) (max max r) 0 1)) (:vertical (make-region 0 1 (min min b) (max max tp) ))))) (defmethod style-menu-items :around ((self grid-lines)) `(("Color" nil "" :sub-items ,(color-menu-items)) ("Invisible?" (set-drawing-style :invisible? :toggle)))) (defmethod distance-to-location ((self grid-lines) viewport location) (if (draw-style self :tics?) (if (selected-p self viewport location) (let* ((c (if (region-p location) (centre-of location) location)) (x (2d-position-x c)) (y (2d-position-y c)) (tics-vp (tic-list-for-viewport self viewport))) (if (eq (orientation-of self) :horizontal) (expt (loop for tic in tics-vp for ti = (car tic) minimize (abs (- x ti))) 2) (expt (loop for tic in tics-vp for ti = (car tic) minimize (abs (- y ti)) ) 2) )) (call-next-method)))) (defclass grid-view(pass-draws-to-subviews 2d-view compound-view) ((style-keys :initform '( :grid :color) :allocation :class) ;;(action-target :initform nil :initarg :action-target :accessor action-target-of) (horizontal-lines :initform nil :initarg :x-lines :accessor horizontal-lines-of) (vertical-lines :initform nil :initarg :y-lines :accessor vertical-lines-of)) (:default-initargs :initform-fn nil )) (defmethod init-position-subviews ((self grid-view) &key ) (let ((br (bounding-region-of self))) (setf (sub-view-locns-of self) (loop repeat (length (subviews-of self)) collect (make-region br)))) (constrain-bounds self)) (defmethod styles-to-subs ((self grid-view ) ) (list :highlight? :color )) (defmethod construct-sub-views ((self grid-view) &rest keyword-pairs &key ) (setf (subviews-of self) (list (setf (vertical-lines-of self) (apply #'view :type 'grid-lines :orientation :horizontal keyword-pairs)) (setf (horizontal-lines-of self) (apply #'view :type 'grid-lines :orientation :vertical keyword-pairs)))) ) (defmethod constrain-bounds ((self grid-view) &key draw? region (link-bounds-x? t) (link-bounds-y? t)) "Constrains the bounds of the views." (let ((views (list self (horizontal-lines-of self) (vertical-lines-of self)))) (setq region (or region (bounding-region-of self) )) (when link-bounds-x? (link-view-bounds views :x) (set-view-extents views :x :region region :recompute? nil)) (when link-bounds-y? (link-view-bounds views :y) (set-view-extents views :y :region region :recompute? nil)) (if (or link-bounds-y? link-bounds-x?) (loop for v in views do (remap-to-viewports v :erase? t :draw? draw?))))) (defmethod set-grid ((self grid-view) value &key (draw? t)) (setq value (case value (:on t) (:off nil) (t (not (draw-style self :grid))))) (if value (progn (set-draw-style self :grid t) (loop for v in (subviews-of self) do (set-drawing-style v :tics? t :draw? draw? :erase? nil))) (progn (set-draw-style self :grid nil) (loop for v in (subviews-of self) do (set-drawing-style v :tics? nil :erase? draw?))))) (defmethod style-menu-items ((self grid-view)) `(("Grid?" (set-grid :toggle) ))) (defmethod set-color-style((self grid-view) &rest keys &key dir color &allow-other-keys) (declare (ignore keys)) (if (eq color :prompt) (setq color (wb::prompt-user-for-color))) (if (eq dir :horizontal) (set-drawing-style (vertical-lines-of self) :color color) (if (eq dir :vertical) (set-drawing-style (horizontal-lines-of self) :color color) (set-drawing-style self :color color)))) (defmethod distance-to-location ((self grid-view) viewport location) (if (selected-p self viewport location) (let* ((c (if (region-p location) (centre-of location) location)) (x (2d-position-x c)) (y (2d-position-y c))) (multiple-value-bind (la ra ba ta) (bounds-of viewport) (min (abs (- x la)) (abs (- x ra)) (abs (- y ba)) (abs (- y ta))))))) (defmethod row-views((self grid-view)) (list (list (vertical-lines-of self) (horizontal-lines-of self)))) (defmethod col-views((self grid-view)) (list (list (vertical-lines-of self) (horizontal-lines-of self)))) (defmethod compute-sub-viewports ((self grid-view) &optional viewport subviews) (let ((viewports (if viewport (list viewport) (viewports-of self))) ) (setq subviews (or subviews (subviews-of self))) (loop for sv in subviews do (loop for vp in viewports for sv-vp = (or (select-viewport sv vp) (make-viewport (window-of vp))) do (setf (bounds-of sv-vp) vp) (add-viewport sv sv-vp vp)))) ) #| testing (setq s (scatterplot :data squids :x "weight" :y "width")) |#
12,538
Common Lisp
.l
256
35.429688
112
0.521598
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3a71532081e217555bc46919081dfd7a2626a059135fd845c92ed6d299513609
33,156
[ -1 ]