doc cleanup, the file was obviously copied from dataframe-matrixlike.
[CommonLispStat.git] / src / data / dataframe-listoflist.lisp
blobce23e2a449d63033710bff519bb1971f30905a0e
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2012-10-06 08:56:53 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--2012, 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 listoflist 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 listoflist."))
32 (:documentation "example implementation of dataframe-like objects
33 using list-of-list data storage."))
35 (defmethod nrows ((df dataframe-listoflist))
36 "specializes on inheritance from listoflist in lisp-matrix."
37 (length (dataset df)))
39 (defmethod ncols ((df dataframe-listoflist))
40 "specializes on inheritance from listoflist. This approach assumes
41 that the list of list is in a coherent form, that is that it maps
42 naturally to a rectangular array."
43 (length (elt (dataset df) 0)))
45 (defmethod xref ((df dataframe-listoflist) &rest subscripts)
46 "Returns a scalar in array, in the same vein as aref, mref, vref,
47 etc. idx1/2 is row/col or case/var."
48 (elt (elt (dataset df) (elt subscripts 0)) (elt subscripts 1))) ;; ??
50 (defmethod (setf xref) (value (df dataframe-listoflist) &rest subscripts)
51 "Sets a value for df-ml."
52 ;; NEED TO CHECK TYPE!
53 ;; (check-type val (elt (vartype df) index2))
54 (setf (elt (elt (dataset df) (elt subscripts 1)) (elt subscripts 0)) value))
56 ;;;;;; IMPLEMENTATION INDEPENDENT FUNCTIONS AND METHODS
57 ;;;;;; (use only xref, nrows, ncols and similar dataframe-like
58 ;;;;;; components as core).
60 (defun xref-var (df index return-type)
61 "Returns the data in a single variable as type.
62 type = sequence, vector, vector-like (if valid numeric type) or dataframe."
63 (ecase return-type
64 (('list)
65 (map 'list
66 #'(lambda (x) (xref df index x))
67 (gen-seq (nth 2 (array-dimensions (dataset df))))))
68 (('vector) t)
69 (:vector-like t)
70 (:matrix-like t)
71 (:dataframe t)))
73 (defun xref-case (df index return-type)
74 "Returns row as sequence."
75 (ecase return-type
76 (:list
77 (map 'list
78 #'(lambda (x) (xref df x index))
79 (gen-seq (nth 1 (array-dimensions (dataset df))))))
80 (:vector t)
81 (:vector-like t)
82 (:matrix-like t)
83 (:dataframe t)))
85 ;; FIXME
86 (defun xref-2indexlist (df indexlist1 indexlist2 &key (return-type :array))
87 "return an array, row X col dims. FIXME TESTME"
88 (case return-type
89 (:array
90 (let ((my-pre-array (list)))
91 (dolist (x indexlist1)
92 (dolist (y indexlist2)
93 (append my-pre-array (xref df x y))))
94 (make-array (list (length indexlist1)
95 (length indexlist2))
96 :initial-contents my-pre-array)))
97 (:dataframe
98 (make-instance 'dataframe-array
99 :storage (make-array
100 (list (length indexlist1)
101 (length indexlist2))
102 :initial-contents (dataset df))
103 ;; ensure copy for this and following
104 :doc (doc-string df)
105 ;; the following 2 need to be subseted based on
106 ;; the values of indexlist1 and indexlist2
107 :case-labels (case-labels df)
108 :var-labels (var-labels df)))))