3 ;;; Time-stamp: <2009-09-19 23:17:25 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: dataframe-listoflist.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
9 ;;; Purpose: Instance of dataframe with the storage done using
10 ;;; LISTOFLIST data storage.
12 ;;; What is this talk of 'release'? Klingons do not make software
13 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
14 ;;; designers and quality assurance people in its wake.
16 ;;; This organization and structure is new to the 21st Century
17 ;;; version.. Think, "21st Century Schizoid Man".
19 ;;; DATAFRAME-LISTOFLIST
21 ;;; example/implementatin of using lisp-matrix datastructures for
22 ;;; dataframe storage.
24 (defclass dataframe-listoflist
(dataframe-like)
29 :documentation
"Data storage: typed as matrix-like
31 (:documentation
"example implementation of dataframe-like using storage
32 based on lisp-matrix structures."))
34 (defmethod nrows ((df dataframe-listoflist
))
35 "specializes on inheritance from listoflist in lisp-matrix."
36 (length (dataset df
)))
38 (defmethod ncols ((df dataframe-listoflist
))
39 "specializes on inheritance from matrix-like in lisp-matrix."
40 (length (elt (dataset df
) 0)))
42 (defmethod xref ((df dataframe-listoflist
) &rest subscripts
)
43 "Returns a scalar in array, in the same vein as aref, mref, vref, etc.
44 idx1/2 is row/col or case/var."
45 (elt (elt (dataset df
) (elt subscripts
0)) (elt subscripts
1))) ;; ??
47 (defmethod (setf xref
) (value (df dataframe-listoflist
) &rest subscripts
)
48 "Sets a value for df-ml."
49 ;; NEED TO CHECK TYPE!
50 ;; (check-type val (elt (vartype df) index2))
51 (setf (elt (elt (dataset df
) (elt subscripts
1)) (elt subscripts
0)) value
))
53 ;;;;;; IMPLEMENTATION INDEPENDENT FUNCTIONS AND METHODS
54 ;;;;;; (use only xref, nrows, ncols and similar dataframe-like
55 ;;;;;; components as core).
57 (defun xref-var (df index return-type
)
58 "Returns the data in a single variable as type.
59 type = sequence, vector, vector-like (if valid numeric type) or dataframe."
63 #'(lambda (x) (xref df index x
))
64 (gen-seq (nth 2 (array-dimensions (dataset df
))))))
70 (defun xref-case (df index return-type
)
71 "Returns row as sequence."
75 #'(lambda (x) (xref df x index
))
76 (gen-seq (nth 1 (array-dimensions (dataset df
))))))
83 (defun xref-2indexlist (df indexlist1 indexlist2
&key
(return-type :array
))
84 "return an array, row X col dims. FIXME TESTME"
87 (let ((my-pre-array (list)))
88 (dolist (x indexlist1
)
89 (dolist (y indexlist2
)
90 (append my-pre-array
(xref df x y
))))
91 (make-array (list (length indexlist1
)
93 :initial-contents my-pre-array
)))
95 (make-instance 'dataframe-array
97 (list (length indexlist1
)
99 :initial-contents
(dataset df
))
100 ;; ensure copy for this and following
102 ;; the following 2 need to be subseted based on
103 ;; the values of indexlist1 and indexlist2
104 :case-labels
(case-labels df
)
105 :var-labels
(var-labels df
)))))