From 5cf4e1a11438bcea48b07b97ac88e8a0092adf3c Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Fri, 25 Sep 2009 08:05:12 +0200 Subject: [PATCH] migrate all listoflist support with matrix/array/dataframe type objects to the resulting types, and any core support into xarray. Signed-off-by: AJ Rossini --- src/data/dataframe-matrixlike.lisp | 36 ++++++++++++++++++- src/data/dataframe.lisp | 20 ++++++++++- src/data/listoflist.lisp | 71 -------------------------------------- 3 files changed, 54 insertions(+), 73 deletions(-) delete mode 100644 src/data/listoflist.lisp diff --git a/src/data/dataframe-matrixlike.lisp b/src/data/dataframe-matrixlike.lisp index b49014e..6839f76 100644 --- a/src/data/dataframe-matrixlike.lisp +++ b/src/data/dataframe-matrixlike.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2009-09-21 17:03:20 tony> +;;; Time-stamp: <2009-09-25 08:02:52 tony> ;;; Creation: <2009-03-12 17:14:56 tony> ;;; File: dataframe-matrixlike.lisp ;;; Author: AJ Rossini @@ -58,3 +58,37 @@ idx1/2 is row/col or case/var." (setf (mref (dataset df) (elt subscripts 0) (elt subscripts 1)) value)) +;;; matrix-like <-> listoflist +;; See XARRAY's listoflist example for more details and support +;; functions (migrated from here to there). +(defun listoflist->matrix-like (lol &key + (orientation :row-major) + (coerce-to 'double-float)) + "From a listoflists structure of numbers, return a matrix-like. + +FIXME: need to verify that the listoflists is a valid structure (same +size rows, typing if required, etc. + +FIXME: need to grep special variables to make the right kind of +matrix-like. + + + (defparameter *lol-ml-test* + (list (list 1d0 1d0 2.1d0) + (list 2d0 2d0 1.1d0))) + (length *lol-ml-test*) + (length (elt *lol-ml-test* 0)) + + (defparameter *lol-ml-result* (listoflist->matrix-like *lol-ml-test*)) + (matrix-dimensions *lol-ml-result*) +" + (declare (ignorable coerce-to)) + (let ((n (length lol)) + (p (length (elt lol 0)))) + (let ((result (make-matrix n p :initial-element 0d0))) + (dotimes (i n) + (dotimes (j p) + (if (equal orientation :row-major) + (setf (mref result i j) (coerce (elt (elt lol i) j) coerce-to)) + (setf (mref result i j) (coerce (elt (elt lol j) i) coerce-to))))) + result))) diff --git a/src/data/dataframe.lisp b/src/data/dataframe.lisp index cd6182d..18ed656 100644 --- a/src/data/dataframe.lisp +++ b/src/data/dataframe.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2009-09-24 10:49:17 tony> +;;; Time-stamp: <2009-09-25 08:01:46 tony> ;;; Creation: <2008-03-12 17:18:42 blindglobe@gmail.com> ;;; File: dataframe.lisp ;;; Author: AJ Rossini @@ -411,11 +411,28 @@ structure." ;;; Need to implement views, i.e. dataframe-view-like, ;;; observation-view-like, variable-view-like. + + ;;; Need to consider read-only variants, leveraging the xref ;;; strategy. +;;; Dataframe <-> Listoflist support +;; the following will be handy to help out folks adjust. It should +;; provide a means to write code faster and better. +;; +;; leverages listoflist support in our version of xarray +(defun listoflist->dataframe (lol) ; &key (type :row-major)) + "Create a cases-by-variables data frame consisting of numeric data, +from a ROW-MAJOR list-of-lists representation. A COLUMN-MAJOR +representation should be handled using the transpose-listoflists +function." + (check-type lol list) ; imperfect -- must verify all list elements are also lists. + (if (lists-of-same-size lol) + (make-dataframe (listoflist->array lol)) + (error "make-data-set-from-lists: no combining different length lists")) + (error "make-data-set-from-lists: proposed name exists")) ;;;;;;;; from dataframe-xarray experiment @@ -454,3 +471,4 @@ structure." (defmethod carray ()) |# + diff --git a/src/data/listoflist.lisp b/src/data/listoflist.lisp deleted file mode 100644 index 5811046..0000000 --- a/src/data/listoflist.lisp +++ /dev/null @@ -1,71 +0,0 @@ -;;; -*- mode: lisp -*- - -;;; Time-stamp: <2009-08-27 08:36:35 tony> -;;; Creation: <2008-09-08 08:06:30 tony> -;;; File: listoflist.lisp -;;; Author: AJ Rossini -;;; Copyright: (c) 2007-2008, AJ Rossini . BSD. -;;; Purpose: Manipulating structures which are lists of lists -;;; with matrix-likes and dataframe-likes. - -;;; What is this talk of 'release'? Klingons do not make software -;;; 'releases'. Our software 'escapes', leaving a bloody trail of -;;; designers and quality assurance people in its wake. - -(in-package :cls-data) - -;; We currently assume that the list-of-list representation is in -;; row-major form, i.e. that lists represent rows and not columns. -;; The original lisp-stat had the other way around. We could augment -;; the top-level list with a property to check orientation -;; (row-major/column-major), but this hasn't been done yet. - -;; See XARRAY's listoflist example for more details and support -;; functions (migrated from here to there). - -(defun listoflist->matrix-like (lol &key - (orientation :row-major) - (coerce-to 'double-float)) - "From a listoflists structure of numbers, return a matrix-like. - -FIXME: need to verify that the listoflists is a valid structure (same -size rows, typing if required, etc. - -FIXME: need to grep special variables to make the right kind of -matrix-like. - - - (defparameter *lol-ml-test* - (list (list 1d0 1d0 2.1d0) - (list 2d0 2d0 1.1d0))) - (length *lol-ml-test*) - (length (elt *lol-ml-test* 0)) - - (defparameter *lol-ml-result* (listoflist->matrix-like *lol-ml-test*)) - (matrix-dimensions *lol-ml-result*) -" - (declare (ignorable coerce-to)) - (let ((n (length lol)) - (p (length (elt lol 0)))) - (let ((result (make-matrix n p :initial-element 0d0))) - (dotimes (i n) - (dotimes (j p) - (if (equal orientation :row-major) - (setf (mref result i j) (coerce (elt (elt lol i) j) coerce-to)) - (setf (mref result i j) (coerce (elt (elt lol j) i) coerce-to))))) - result))) - - -;; the following will be handy to help out folks adjust. It should -;; provide a means to write code faster and better. -(defun listoflist->dataframe (lol) ; &key (type :row-major)) - "Create a cases-by-variables data frame consisting of numeric data, -from a ROW-MAJOR list-of-lists representation. A COLUMN-MAJOR -representation should be handled using the transpose-listoflists -function." - (if (lists-of-same-size lol) - (make-dataframe (listoflist->array lol)) - (error "make-data-set-from-lists: no combining different length lists")) - (error "make-data-set-from-lists: proposed name exists")) - - -- 2.11.4.GIT