3 ;;; Time-stamp: <2010-01-22 07:54:51 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: dataframe-array.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
9 ;;; Purpose: real dataframe class using lisp-arrays as storage.
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;;; This organization and structure is new to the 21st Century
16 ;;; version.. Think, "21st Century Schizoid Man".
18 (in-package :cls-dataframe
)
22 (defclass dataframe-array
(dataframe-like)
27 :documentation
"Data storage: typed as array.")
28 (store-class :initform
'array
30 :documentation
"Storage class is ARRAY."))
31 (:documentation
"example implementation of dataframe-like using storage
32 based on lisp arrays. An obvious alternative could be a
33 dataframe-matrix-like which uses the lisp-matrix classes."))
35 (defmethod nrows ((df dataframe-array
))
36 "specializes on inheritance from matrix-like in lisp-matrix."
37 (array-dimension (dataset df
) 0))
39 (defmethod ncols ((df dataframe-array
))
40 "specializes on inheritance from matrix-like in lisp-matrix."
41 (array-dimension (dataset df
) 1))
43 (defmethod xref ((df dataframe-array
) &rest subscripts
)
44 "Returns a scalar in array, in the same vein as aref, mref, vref, etc.
45 idx1/2 is row/col or case/var."
46 (assert (>= 2 (length subscripts
)))
48 (assert (typep (elt subscripts
0) integer
))
49 (assert (typep (elt subscripts
1) integer
))
51 (aref (dataset df
) (elt subscripts
0) (elt subscripts
1)))
53 (defmethod (setf xref
) (value (df dataframe-array
) &rest subscripts
)
54 "set value for df-ar."
55 ;; (check-type val (elt (var-type df) index2))
56 (setf (aref (dataset df
) (elt subscripts
0) (elt subscripts
1)) value
))
58 (defparameter *default-dataframe-class
* 'dataframe-array
)
60 (defmethod dfselect ((df dataframe-array
)
61 &optional cases vars indices
)
62 "Extract the OR of cases, vars, or have a list of indices to extract"
63 (if indices
(error "Indicies not used yet"))
64 (let ((newdf (make-instance *default-dataframe-class
*
65 :storage
(make-array (list (length cases
) (length vars
)))
69 :case-labels
(select-list caselist
(case-labels df
))
70 :var-labels
(select-list varlist
(var-labels df
))
71 :var-types
(select-list varlist
(vartypes df
))
74 (dotimes (i (length cases
))
75 (dotimes (j (length vars
))
76 (setf (xref newdf i j
)
78 (position (elt cases i
) (case-labels df
))
79 (position (elt vars j
) (var-labels df
))))))))