From c049f5a2bfd6788b310c3d0026b6929b2a127634 Mon Sep 17 00:00:00 2001 From: tony Date: Wed, 30 Apr 2008 17:50:36 +0200 Subject: [PATCH] test clean up improved printing start for data reshaping tools --- data-clos.lisp | 69 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/data-clos.lisp b/data-clos.lisp index 834bff2..eb734b2 100644 --- a/data-clos.lisp +++ b/data-clos.lisp @@ -190,45 +190,76 @@ Ensure that dims of stored data are same as case and var labels." ;;; Printing methods and support. +(defun print-as-row (seq) + "Print a sequence formated as a row in a table." + (format t "~{~D~T~}" seq)) + +;; (print-as-row (list 1 2 3)) + (defun print-structure-table (ds) "example of what we want the methods to look like. Should be sort of like a spreadsheet if the storage is a table." (print-as-row (var-labels ds)) (let ((j -1)) (dolist (i (case-labels ds)) - (princ (format "%i %v" i (extract-row (dataset ds) (incr j))))))) + (print-as-row (append (list i) + (extract-row (dataset ds) (incf j))))))) (defun print-structure-relational (ds) "example of what we want the methods to look like. Should be sort of like a graph of spreadsheets if the storage is a relational structure." (dolist (k (relations ds)) - (print-as-row (var-labels ds)) - (let ((j -1)) - (dolist (i (case-labels ds)) - (princ "%i %v" i (extract-row (dataset ds) (incr j))))))) + (let ((currentRelationSet (getRelation ds k))) + (print-as-row (var-labels currentRelationSet)) + (let ((j -1)) + (dolist (i (case-labels currentRelationSet)) + (print-as-row + (append (list i) + (extract-row (dataset currentRelationSet) + (incf j))))))))) - +;;; Shaping for computation (defgeneric reshapeData (dataform into-form as-copy) (:documentation "pulling data into a new form")) -(defmethod reshapeData ((ds statistical-dataset) what into-form) - (reshape (get ds what) into-form)) +(defmethod reshapeData ((sds statistical-dataset) what into-form)) (defmethod reshapeData ((ds array) (sp list) copy-p) "Array via specList specialization: similar to the common R -approaches to redistribution." - (let ((widep (getf sp :toWide)) - (primaryKey (getf sp :primaryKey))) - )) - +approaches to redistribution.") (defclass data-format () ()) -(defun transpose (x) - "map NxM to MxN.") +(defun row-order-as-list (ary) + "Pull out data in row order into a list." + (let ((result (list)) + (nrows (nth 0 (array-dimensions ary))) + (ncols (nth 1 (array-dimensions ary)))) + (dotimes (i (0 ncols)) + (dotimes (j (0 nrows)) + (nappend list (aref ary i j)))))) + +(defun col-order-as-list (ary) + "Pull out data in row order into a list." + (let ((result (list)) + (nrows (nth 0 (array-dimensions ary))) + (ncols (nth 1 (array-dimensions ary)))) + (dotimes (i (0 nrows)) + (dotimes (j (0 ncols)) + (nappend list (aref ary i j)))))) + + +(nth 1 (list 1 2 3)) + +(defun transpose (ary) + "map NxM to MxN." + (make-array (reverse (array-dimensions ary)) + :storage (col-order-as-list ary))) + + (defun reorder-by-rank (x order &key (by-row t)) " .") @@ -386,8 +417,10 @@ Usually used by: (addtest (lisp-stat-dataclos) equaltestnameData (ensure-error - (eql (dataset (list 'a 'b 'c 'd) :form (list 2 2)) - #2A(('a 'b) ('c 'd))))) + (equal (lisp-stat-data-clos::dataset + (make-instance 'statistical-dataset + :storage #2A(('a 'b) ('c 'd)))) + #2A(('a 'b) ('c 'd))))) (defvar my-ds-1 nil "test ds for experiment.") @@ -422,7 +455,7 @@ my-ds-2 (addtest (lisp-stat-dataclos) badAccess3 (ensure-error - (dataset my-ds-2))) + (lisp-stat-data-clos::dataset my-ds-2))) (addtest (lisp-stat-dataclos) badAccess4 (ensure -- 2.11.4.GIT