3 ;;; Time-stamp: <2009-09-21 17:03:03 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 (in-package :cls-dataframe
)
21 ;;; DATAFRAME-LISTOFLIST
23 ;;; example/implementatin of using lisp-matrix datastructures for
24 ;;; dataframe storage.
26 (defclass dataframe-listoflist
(dataframe-like)
31 :documentation
"Data storage: typed as matrix-like
33 (:documentation
"example implementation of dataframe-like using storage
34 based on lisp-matrix structures."))
36 (defmethod nrows ((df dataframe-listoflist
))
37 "specializes on inheritance from listoflist in lisp-matrix."
38 (length (dataset df
)))
40 (defmethod ncols ((df dataframe-listoflist
))
41 "specializes on inheritance from matrix-like in lisp-matrix."
42 (length (elt (dataset df
) 0)))
44 (defmethod xref ((df dataframe-listoflist
) &rest subscripts
)
45 "Returns a scalar in array, in the same vein as aref, mref, vref, etc.
46 idx1/2 is row/col or case/var."
47 (elt (elt (dataset df
) (elt subscripts
0)) (elt subscripts
1))) ;; ??
49 (defmethod (setf xref
) (value (df dataframe-listoflist
) &rest subscripts
)
50 "Sets a value for df-ml."
51 ;; NEED TO CHECK TYPE!
52 ;; (check-type val (elt (vartype df) index2))
53 (setf (elt (elt (dataset df
) (elt subscripts
1)) (elt subscripts
0)) value
))
55 ;;;;;; IMPLEMENTATION INDEPENDENT FUNCTIONS AND METHODS
56 ;;;;;; (use only xref, nrows, ncols and similar dataframe-like
57 ;;;;;; components as core).
59 (defun xref-var (df index return-type
)
60 "Returns the data in a single variable as type.
61 type = sequence, vector, vector-like (if valid numeric type) or dataframe."
65 #'(lambda (x) (xref df index x
))
66 (gen-seq (nth 2 (array-dimensions (dataset df
))))))
72 (defun xref-case (df index return-type
)
73 "Returns row as sequence."
77 #'(lambda (x) (xref df x index
))
78 (gen-seq (nth 1 (array-dimensions (dataset df
))))))
85 (defun xref-2indexlist (df indexlist1 indexlist2
&key
(return-type :array
))
86 "return an array, row X col dims. FIXME TESTME"
89 (let ((my-pre-array (list)))
90 (dolist (x indexlist1
)
91 (dolist (y indexlist2
)
92 (append my-pre-array
(xref df x y
))))
93 (make-array (list (length indexlist1
)
95 :initial-contents my-pre-array
)))
97 (make-instance 'dataframe-array
99 (list (length indexlist1
)
101 :initial-contents
(dataset df
))
102 ;; ensure copy for this and following
104 ;; the following 2 need to be subseted based on
105 ;; the values of indexlist1 and indexlist2
106 :case-labels
(case-labels df
)
107 :var-labels
(var-labels df
)))))