dataframe refactoring into core and storage-specific components.
[CommonLispStat.git] / src / data / dataframe-array.lisp
bloba7f53759d43ead9b7e69cf370a230604bf3dcfdd
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-09-19 23:13:00 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".
19 ;;;;; DATAFRAME-ARRAY
21 (defclass dataframe-array (dataframe-like)
22 ((store :initform nil
23 :initarg :storage
24 :type (array * *)
25 :accessor dataset
26 :documentation "Data storage: typed as array."))
27 (:documentation "example implementation of dataframe-like using storage
28 based on lisp arrays. An obvious alternative could be a
29 dataframe-matrix-like which uses the lisp-matrix classes."))
31 (defmethod nrows ((df dataframe-array))
32 "specializes on inheritance from matrix-like in lisp-matrix."
33 (array-dimension (dataset df) 0))
35 (defmethod ncols ((df dataframe-array))
36 "specializes on inheritance from matrix-like in lisp-matrix."
37 (array-dimension (dataset df) 1))
39 (defmethod xref ((df dataframe-array) &rest subscripts)
40 "Returns a scalar in array, in the same vein as aref, mref, vref, etc.
41 idx1/2 is row/col or case/var."
42 (assert (>= 2 (length subscripts)))
43 #| ;; needed?
44 (assert (typep (elt subscripts 0) integer))
45 (assert (typep (elt subscripts 1) integer))
47 (aref (dataset df) (elt subscripts 0) (elt subscripts 1)))
49 (defmethod (setf xref) (value (df dataframe-array) &rest subscripts)
50 "set value for df-ar."
51 ;; (check-type val (elt (var-type df) index2))
52 (setf (aref (dataset df) (elt subscripts 0) (elt subscripts 1)) value))
54 (defparameter *default-dataframe-class* 'dataframe-array)
56 (defmethod dfselect ((df dataframe-array)
57 &optional cases vars indices)
58 "Extract the OR of cases, vars, or have a list of indices to extract"
59 (if indices (error "Indicies not used yet"))
60 (let ((newdf (make-instance *default-dataframe-class*
61 :storage (make-array (list (length cases) (length vars)))
62 :nrows (length cases)
63 :ncols (length vars)
65 :case-labels (select-list caselist (case-labels df))
66 :var-labels (select-list varlist (var-labels df))
67 :var-types (select-list varlist (vartypes df))
69 )))
70 (dotimes (i (length cases))
71 (dotimes (j (length vars))
72 (setf (xref newdf i j)
73 (xref df
74 (position (elt cases i) (case-labels df))
75 (position (elt vars j) (var-labels df))))))))