From: Akshay S. <ak...@us...> - 2013-02-19 04:13:00
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "matlisp". The branch, tensor has been updated via 7338eb40c61c8fcab6a6180f68c0db7e013ad9ee (commit) from 039adc9fd4f65be5beea4d7f077a54892c3310ca (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7338eb40c61c8fcab6a6180f68c0db7e013ad9ee Author: Akshay Srinivasan <aks...@gm...> Date: Mon Feb 18 20:12:29 2013 -0800 First stab at getting gnuplot to work. diff --git a/lib-src/gnuplot/gnuplot.lisp b/lib-src/gnuplot/gnuplot.lisp index a329ccb..906a981 100644 --- a/lib-src/gnuplot/gnuplot.lisp +++ b/lib-src/gnuplot/gnuplot.lisp @@ -1,60 +1,71 @@ +(in-package :matlisp) (defvar *current-gnuplot-stream* nil) - -(defvar *gnuplot-binary* "gnuplot") - -(defclass gnuplot-plot-info () - ((title - :initform "GNU PLOT" - :accessor gnuplot-title) - (x-label - :initform "X" - :accessor gnuplot-x-label) - (y-label - :initform "Y" - :accessor gnuplot-y-label) - (x-data - :accessor gnuplot-x-data) - (y-data - :accessor gnuplot-y-data) - (z-data - :accessor gnuplot-z-data))) +(defvar *gnuplot-binary* "/usr/bin/gnuplot") (defun open-gnuplot-stream () - (#-:sbcl - ext:run-program - #+:sbcl + (#+:sbcl sb-ext:run-program *gnuplot-binary* nil :input :stream :wait nil :output t)) -(defun gnuplot-plot (info &key (stream (#-:sbcl - ext:process-input - #+:sbcl - sb-ext:process-input - *current-gnuplot-stream*))) - (with-accessors ((title gnuplot-title) - (x-label gnuplot-x-label) - (y-label gnuplot-y-label) - (x-data gnuplot-x-data) - (y-data gnuplot-y-data) - (z-data gnuplot-z-data)) - info - (format stream "~&set title '~S'~%" title) - (format stream "~&set xlabel '~S'~%" x-label) - (format stream "~&set ylabel '~S'~%" y-label) - (finish-output stream) - (map nil #'(lambda (x y z) - (with-open-file (s "/tmp/gnuplot.out" :direction :output - :if-exists :overwrite) - (map nil #'(lambda (xs ys zs) - (if zs - (format s "~A ~A ~A~%" xs ys zs) - (format s "~A ~A~%" xs ys))) - x y z) - (format stream "~A '/tmp/gnuplot.out'~%" - (if z "splot" "plot")) - (finish-output stream) - (sleep 5))) - x-data y-data z-data) - )) - - +(defun plot2d (data &key (color (list "#FF0000")) (stream (#+:sbcl + sb-ext:process-input + *current-gnuplot-stream*))) + (with-open-file (s "/tmp/matlisp-gnuplot.out" :direction :output :if-exists :supersede :if-does-not-exist :create) + (loop :for i :from 0 :below (loop :for x :in data :minimizing (number-of-elements x)) + :do (loop :for x :in data :do (format s "~a " (tensor-ref x i)) :finally (format s "~%")))) + (format stream "plot '/tmp/matlisp-gnuplot.out' with lines linecolor rgb ~s~%" color) + (finish-output stream)) + +(defun gnuplot-send (str &key (stream (#+:sbcl + sb-ext:process-input + *current-gnuplot-stream*))) + (format stream "~a~%" str) + (finish-output stream)) + + +;; (defclass gnuplot-plot-info () +;; ((title +;; :initform "GNU PLOT" +;; :accessor gnuplot-title) +;; (x-label +;; :initform "X" +;; :accessor gnuplot-x-label) +;; (y-label +;; :initform "Y" +;; :accessor gnuplot-y-label) +;; (x-data +;; :accessor gnuplot-x-data) +;; (y-data +;; :accessor gnuplot-y-data) +;; (z-data +;; :accessor gnuplot-z-data))) + + +;; (defun gnuplot-plot (info &key (stream (#+:sbcl +;; sb-ext:process-input +;; *current-gnuplot-stream*))) +;; (with-accessors ((title gnuplot-title) +;; (x-label gnuplot-x-label) +;; (y-label gnuplot-y-label) +;; (x-data gnuplot-x-data) +;; (y-data gnuplot-y-data) +;; (z-data gnuplot-z-data)) +;; info +;; (format stream "~&set title '~S'~%" title) +;; (format stream "~&set xlabel '~S'~%" x-label) +;; (format stream "~&set ylabel '~S'~%" y-label) +;; (finish-output stream) +;; (map nil #'(lambda (x y z) +;; (with-open-file (s "/tmp/gnuplot.out" :direction :output +;; :if-exists :overwrite) +;; (map nil #'(lambda (xs ys zs) +;; (if zs +;; (format s "~A ~A ~A~%" xs ys zs) +;; (format s "~A ~A~%" xs ys))) +;; x y z) +;; (format stream "~A '/tmp/gnuplot.out'~%" +;; (if z "splot" "plot")) +;; (finish-output stream) +;; (sleep 5))) +;; x-data y-data z-data) +;; )) diff --git a/src/base/print.lisp b/src/base/print.lisp index 7200306..f8ad402 100644 --- a/src/base/print.lisp +++ b/src/base/print.lisp @@ -90,7 +90,7 @@ of a matrix (default 0) (1 (format stream (format-to-string "~~~AT" *print-indent*)) (dotimes (i (aref dims 0)) - (if (< i *print-max-len*) + (if (or (eq *print-max-len* t) (< i *print-max-len*)) (progn (print-element tensor (tensor-ref tensor `(,i)) stream) (format stream "~,4T")) diff --git a/src/old/seq.lisp b/src/sugar/seq.lisp similarity index 67% rename from src/old/seq.lisp rename to src/sugar/seq.lisp index 96eb780..9da94ca 100644 --- a/src/old/seq.lisp +++ b/src/sugar/seq.lisp @@ -25,41 +25,22 @@ ;;; ENHANCEMENTS, OR MODIFICATIONS. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; -;;; Originally written by Tunc Simsek, Univ. of California, Berkeley, -;;; 2000, si...@ee... -;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; -;;; $Id: seq.lisp,v 1.5 2004/12/03 18:01:38 rtoy Exp $ -;;; -;;; $Log: seq.lisp,v $ -;;; Revision 1.5 2004/12/03 18:01:38 rtoy -;;; We were doing (type-of step) and doing (coerce x type). But (type-of -;;; 1) can be (integer 1 1), and that doesn't work so well with coerce. -;;; So make type be either integer or rational, as appropriate. -;;; -;;; But the real question is why we need to do this at all. -;;; -;;; Revision 1.4 2002/06/24 18:05:30 rtoy -;;; Modified SEQ to run much faster by pushing the values onto the -;;; beginning of the list and reversing the result instead of -;;; destructively appending to the end, for an O(n^2) process instead of -;;; O(n). -;;; -;;; Revision 1.3 2000/07/11 18:02:03 simsek -;;; o Added credits -;;; -;;; Revision 1.2 2000/07/11 02:11:56 simsek -;;; o Added support for Allegro CL -;;; -;;; Revision 1.1 2000/04/14 00:12:48 simsek -;;; Initial revision. -;;; -;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(in-package #:matlisp) + +(defun arange (start end &optional (h 1d0)) + (let ((quo (ceiling (if (> start end) (- start end) (- end start)) h))) + (if (= quo 0) nil + (let*-typed ((ret (real-typed-zeros (idxv quo)) :type real-tensor) + (sto-r (store ret) :type real-store-vector) + (h (coerce-real-unforgiving (if (> start end) (- h) h)) :type real-type)) + (loop :for i :from 0 :below quo + :for ori := (coerce-real-unforgiving start) :then (+ ori h) + :do (setf (aref sto-r i) ori)) + ret)))) -(in-package "MATLISP") +(defun linspace (start end &optional (num-points (1+ (abs (- start end))))) + (let ((h (/ (- end start) (1- num-points)))) + (arange start (+ h end) (abs h)))) #+nil (export '(seq)) ----------------------------------------------------------------------- Summary of changes: lib-src/gnuplot/gnuplot.lisp | 119 +++++++++++++++++++++++------------------- src/base/print.lisp | 2 +- src/{old => sugar}/seq.lisp | 49 +++++------------ 3 files changed, 81 insertions(+), 89 deletions(-) rename src/{old => sugar}/seq.lisp (67%) hooks/post-receive -- matlisp |