3 ;;; Time-stamp: <2009-09-21 17:02: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 (:documentation
"example implementation of dataframe-like using storage
29 based on lisp arrays. An obvious alternative could be a
30 dataframe-matrix-like which uses the lisp-matrix classes."))
32 (defmethod nrows ((df dataframe-array
))
33 "specializes on inheritance from matrix-like in lisp-matrix."
34 (array-dimension (dataset df
) 0))
36 (defmethod ncols ((df dataframe-array
))
37 "specializes on inheritance from matrix-like in lisp-matrix."
38 (array-dimension (dataset df
) 1))
40 (defmethod xref ((df dataframe-array
) &rest subscripts
)
41 "Returns a scalar in array, in the same vein as aref, mref, vref, etc.
42 idx1/2 is row/col or case/var."
43 (assert (>= 2 (length subscripts
)))
45 (assert (typep (elt subscripts
0) integer
))
46 (assert (typep (elt subscripts
1) integer
))
48 (aref (dataset df
) (elt subscripts
0) (elt subscripts
1)))
50 (defmethod (setf xref
) (value (df dataframe-array
) &rest subscripts
)
51 "set value for df-ar."
52 ;; (check-type val (elt (var-type df) index2))
53 (setf (aref (dataset df
) (elt subscripts
0) (elt subscripts
1)) value
))
55 (defparameter *default-dataframe-class
* 'dataframe-array
)
57 (defmethod dfselect ((df dataframe-array
)
58 &optional cases vars indices
)
59 "Extract the OR of cases, vars, or have a list of indices to extract"
60 (if indices
(error "Indicies not used yet"))
61 (let ((newdf (make-instance *default-dataframe-class
*
62 :storage
(make-array (list (length cases
) (length vars
)))
66 :case-labels
(select-list caselist
(case-labels df
))
67 :var-labels
(select-list varlist
(var-labels df
))
68 :var-types
(select-list varlist
(vartypes df
))
71 (dotimes (i (length cases
))
72 (dotimes (j (length vars
))
73 (setf (xref newdf i j
)
75 (position (elt cases i
) (case-labels df
))
76 (position (elt vars j
) (var-labels df
))))))))