27e9a78f89491a3026c8563bf36693e21bc28c4f
[CommonLispStat.git] / src / data / dataframe-array.lisp
blob27e9a78f89491a3026c8563bf36693e21bc28c4f
1 ;;; -*- mode: lisp -*-
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
8 ;;; on how it arrives.
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)
20 ;;;;; DATAFRAME-ARRAY
22 (defclass dataframe-array (dataframe-like)
23 ((store :initform nil
24 :initarg :storage
25 :type (array * *)
26 :accessor dataset
27 :documentation "Data storage: typed as array.")
28 (store-class :initform 'array
29 :accessor store
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)))
47 #| ;; needed?
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)))
66 :nrows (length cases)
67 :ncols (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))
73 )))
74 (dotimes (i (length cases))
75 (dotimes (j (length vars))
76 (setf (xref newdf i j)
77 (xref df
78 (position (elt cases i) (case-labels df))
79 (position (elt vars j) (var-labels df))))))))