3 ;;; Time-stamp: <2012-10-06 08:56:53 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."))
35 (defmethod nrows ((df dataframe-listoflist
))
36 "specializes on inheritance from listoflist in lisp-matrix."
37 (length (dataset df
)))
39 (defmethod ncols ((df dataframe-listoflist
))
40 "specializes on inheritance from listoflist. This approach assumes
41 that the list of list is in a coherent form, that is that it maps
42 naturally to a rectangular array."
43 (length (elt (dataset df
) 0)))
45 (defmethod xref ((df dataframe-listoflist
) &rest subscripts
)
46 "Returns a scalar in array, in the same vein as aref, mref, vref,
47 etc. idx1/2 is row/col or case/var."
48 (elt (elt (dataset df
) (elt subscripts
0)) (elt subscripts
1))) ;; ??
50 (defmethod (setf xref
) (value (df dataframe-listoflist
) &rest subscripts
)
51 "Sets a value for df-ml."
52 ;; NEED TO CHECK TYPE!
53 ;; (check-type val (elt (vartype df) index2))
54 (setf (elt (elt (dataset df
) (elt subscripts
1)) (elt subscripts
0)) value
))
56 ;;;;;; IMPLEMENTATION INDEPENDENT FUNCTIONS AND METHODS
57 ;;;;;; (use only xref, nrows, ncols and similar dataframe-like
58 ;;;;;; components as core).
60 (defun xref-var (df index return-type
)
61 "Returns the data in a single variable as type.
62 type = sequence, vector, vector-like (if valid numeric type) or dataframe."
66 #'(lambda (x) (xref df index x
))
67 (gen-seq (nth 2 (array-dimensions (dataset df
))))))
73 (defun xref-case (df index return-type
)
74 "Returns row as sequence."
78 #'(lambda (x) (xref df x index
))
79 (gen-seq (nth 1 (array-dimensions (dataset df
))))))
86 (defun xref-2indexlist (df indexlist1 indexlist2
&key
(return-type :array
))
87 "return an array, row X col dims. FIXME TESTME"
90 (let ((my-pre-array (list)))
91 (dolist (x indexlist1
)
92 (dolist (y indexlist2
)
93 (append my-pre-array
(xref df x y
))))
94 (make-array (list (length indexlist1
)
96 :initial-contents my-pre-array
)))
98 (make-instance 'dataframe-array
100 (list (length indexlist1
)
102 :initial-contents
(dataset df
))
103 ;; ensure copy for this and following
105 ;; the following 2 need to be subseted based on
106 ;; the values of indexlist1 and indexlist2
107 :case-labels
(case-labels df
)
108 :var-labels
(var-labels df
)))))