dataframe refactoring into core and storage-specific components.
[CommonLispStat.git] / src / data / dataframe-matrixlike.lisp
blob2ce57869e182c76edd42fc5ea32f1627b81a20ae
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-09-19 23:21:30 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: dataframe-matrixlike.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: Uses the lisp-matrix dataframe instance for storage.
10 ;;; Useful if we only have numerical data and no missing
11 ;;; data, strings, or categorical stuff...
13 ;;; What is this talk of 'release'? Klingons do not make software
14 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
15 ;;; designers and quality assurance people in its wake.
17 ;;; This organization and structure is new to the 21st Century
18 ;;; version.. Think, "21st Century Schizoid Man".
19 ;;; DATAFRAME-MATRIXLIKE
20 ;;;
21 ;;; example/implementatin of using lisp-matrix datastructures for
22 ;;; dataframe storage.
24 (defclass dataframe-matrixlike (dataframe-like)
25 ((store :initform nil
26 :initarg :storage
27 :type matrix-like
28 :accessor dataset
29 :documentation "Data storage: typed as matrix-like
30 (numerical only)."))
31 (:documentation "example implementation of dataframe-like using storage
32 based on lisp-matrix structures."))
34 (defmethod nrows ((df dataframe-matrixlike))
35 "specializes on inheritance from matrix-like in lisp-matrix."
36 (matrix-dimension (dataset df) 0))
38 (defmethod ncols ((df dataframe-matrixlike))
39 "specializes on inheritance from matrix-like in lisp-matrix."
40 (matrix-dimension (dataset df) 1))
42 ;;; *** FIXME: change mref to xref when we establish lisp-matrix
43 ;;; change to use xarray access facility. Need to dummy-proof the
44 ;;; following.
45 (defmethod xref ((df dataframe-matrixlike) &rest subscripts)
46 "Returns a scalar in array, in the same vein as aref, mref, vref, etc.
47 idx1/2 is row/col or case/var."
48 (mref (dataset df) (elt subscripts 0) (elt subscripts 1)))
50 (defmethod (setf xref) (value (df dataframe-matrixlike) &rest subscripts)
51 "Sets a value for df-ml."
52 ;; NEED TO CHECK TYPE!
53 ;; (check-type val (elt (vartype df) index2))
54 (setf (mref (dataset df) (elt subscripts 0) (elt subscripts 1)) value))