documentation cleanup, to fast forward to current practices.
[CommonLispStat.git] / src / data / dataframe-listoflist.lisp
blob6e6f254152ba7686a7be2b2248cfd37ad94b8fbf
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2012-07-01 12:02:55 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
8 ;;; on how it arrives.
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
22 ;;;
23 ;;; example/implementatin of using lisp-matrix datastructures for
24 ;;; dataframe storage.
26 (defclass dataframe-listoflist (dataframe-like)
27 ((store :initform nil
28 :initarg :storage
29 :type list
30 :accessor dataset
31 :documentation "Data storage: typed as matrix-like
32 (numerical only)."))
33 (:documentation "example implementation of dataframe-like using
34 storage 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,
46 etc. 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."
62 (ecase return-type
63 (('list)
64 (map 'list
65 #'(lambda (x) (xref df index x))
66 (gen-seq (nth 2 (array-dimensions (dataset df))))))
67 (('vector) t)
68 (:vector-like t)
69 (:matrix-like t)
70 (:dataframe t)))
72 (defun xref-case (df index return-type)
73 "Returns row as sequence."
74 (ecase return-type
75 (:list
76 (map 'list
77 #'(lambda (x) (xref df x index))
78 (gen-seq (nth 1 (array-dimensions (dataset df))))))
79 (:vector t)
80 (:vector-like t)
81 (:matrix-like t)
82 (:dataframe t)))
84 ;; FIXME
85 (defun xref-2indexlist (df indexlist1 indexlist2 &key (return-type :array))
86 "return an array, row X col dims. FIXME TESTME"
87 (case return-type
88 (:array
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)
94 (length indexlist2))
95 :initial-contents my-pre-array)))
96 (:dataframe
97 (make-instance 'dataframe-array
98 :storage (make-array
99 (list (length indexlist1)
100 (length indexlist2))
101 :initial-contents (dataset df))
102 ;; ensure copy for this and following
103 :doc (doc-string df)
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)))))