3 ;;; Time-stamp: <2012-10-09 03:18:49 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--2012, 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 (in-package :cls-dataframe
)
21 ;;; DATAFRAME-LISTOFLIST
23 ;;; example/implementatin of using listoflist datastructures for
24 ;;; dataframe storage.
26 (defclass dataframe-listoflist
(dataframe-like)
31 :documentation
"Data storage: typed as listoflist."))
32 (:documentation
"example implementation of dataframe-like objects
33 using list-of-list data storage."))
36 (defmethod make-dataframe2 ((data dataframe-listoflist
)
37 &key vartypes varlabels caselabels doc
38 ;; (vartypes sequence) (varlabels sequence) (caselabels sequence) (doc string)
40 (check-dataframe-params data vartypes varlabels caselabels doc
)
41 (build-dataframe 'dataframe-listoflist
))
44 (defmethod nrows ((df dataframe-listoflist
))
45 "specializes on inheritance from listoflist in lisp-matrix."
46 (length (dataset df
)))
49 (defmethod ncols ((df dataframe-listoflist
))
50 "specializes on inheritance from listoflist. This approach assumes
51 that the list of list is in a coherent form, that is that it maps
52 naturally to a rectangular array."
53 (length (elt (dataset df
) 0)))
55 (defmethod xref ((df dataframe-listoflist
) &rest subscripts
)
56 "Returns a scalar in array, in the same vein as aref, mref, vref,
57 etc. idx1/2 is row/col or case/var."
58 (elt (elt (dataset df
) (elt subscripts
0)) (elt subscripts
1))) ;; ??
60 (defmethod (setf xref
) (value (df dataframe-listoflist
) &rest subscripts
)
61 "Sets a value for df-ml."
62 ;; NEED TO CHECK TYPE!
63 ;; (check-type val (elt (vartype df) index2))
64 (setf (elt (elt (dataset df
) (elt subscripts
1)) (elt subscripts
0)) value
))
66 ;;;;;; IMPLEMENTATION INDEPENDENT FUNCTIONS AND METHODS
67 ;;;;;; (use only xref, nrows, ncols and similar dataframe-like
68 ;;;;;; components as core).
70 (defun xref-var (df index return-type
)
71 "Returns the data in a single variable as type.
72 type = sequence, vector, vector-like (if valid numeric type) or dataframe."
76 #'(lambda (x) (xref df index x
))
77 (gen-seq (nth 2 (array-dimensions (dataset df
))))))
83 (defun xref-case (df index return-type
)
84 "Returns row as sequence."
88 #'(lambda (x) (xref df x index
))
89 (gen-seq (nth 1 (array-dimensions (dataset df
))))))
96 (defun xref-2indexlist (df indexlist1 indexlist2
&key
(return-type :array
))
97 "return an array, row X col dims. FIXME TESTME"
100 (let ((my-pre-array (list)))
101 (dolist (x indexlist1
)
102 (dolist (y indexlist2
)
103 (append my-pre-array
(xref df x y
))))
104 (make-array (list (length indexlist1
)
106 :initial-contents my-pre-array
)))
108 (make-instance 'dataframe-array
110 (list (length indexlist1
)
112 :initial-contents
(dataset df
))
113 ;; ensure copy for this and following
115 ;; the following 2 need to be subseted based on
116 ;; the values of indexlist1 and indexlist2
117 :case-labels
(case-labels df
)
118 :var-labels
(var-labels df
)))))