From jivestgarden at common-lisp.net Sat Oct 2 15:29:26 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sat, 02 Oct 2010 11:29:26 -0400 Subject: [lisplab-cvs] r185 - in trunk/src: core specfunc vector1 Message-ID: Author: jivestgarden Date: Sat Oct 2 11:29:26 2010 New Revision: 185 Log: minor cleanup Modified: trunk/src/core/level0-basic.lisp trunk/src/specfunc/level0-specfunc.lisp trunk/src/vector1/level1-vector.lisp Modified: trunk/src/core/level0-basic.lisp ============================================================================== --- trunk/src/core/level0-basic.lisp (original) +++ trunk/src/core/level0-basic.lisp Sat Oct 2 11:29:26 2010 @@ -28,13 +28,6 @@ ;; Help, not tested #-sbcl(defmacro truely-the (type val) `(the ,type ,val)) -;; (setf *READ-DEFAULT-FLOAT-FORMAT* 'double-float) ; TODO make part of pacakge import? - -(defmacro with-gensyms ((&rest names) . body) - ;; TODO remove? Is it used at all? - `(let ,(loop for n in names collect `(,n (gensym))) - , at body)) - (defmacro define-constant (name value &optional doc) "Works as defconstant. Made to avoid trouble with sbcl's strict interpretation of the ansi standard." @@ -52,7 +45,7 @@ "Coerce x to double float." (coerce x 'double-float)) -(defun dvec (n) +(defun make-dvec (n) "Creates a double vector with n elements." (make-array n :element-type 'double-float :initial-element 0d0)) Modified: trunk/src/specfunc/level0-specfunc.lisp ============================================================================== --- trunk/src/specfunc/level0-specfunc.lisp (original) +++ trunk/src/specfunc/level0-specfunc.lisp Sat Oct 2 11:29:26 2010 @@ -27,15 +27,15 @@ (typecase x (complex (let ((rx (to-df (realpart x))) (cx (to-df (imagpart x))) - (ry (dvec 1)) - (cy (dvec 1))) + (ry (make-dvec 1)) + (cy (make-dvec 1))) (slatec:zbesj rx cx (to-df n) 1 1 ry cy 0 0) (complex (aref ry 0) (aref cy 0)))) (t (let ((x (to-df x))) (case n (0 (slatec:dbesj0 x)) (1 (slatec:dbesj1 x)) - (t (let ((y (dvec 1))) + (t (let ((y (make-dvec 1))) (slatec:dbesj x (to-df n) 1 y 0) (aref y 0)))))))) @@ -46,17 +46,17 @@ (typecase x (complex (let ((rx (to-df (realpart x))) (cx (to-df (imagpart x))) - (ry (dvec 1)) - (cy (dvec 1)) - (rw (dvec 1)) - (cw (dvec 1))) + (ry (make-dvec 1)) + (cy (make-dvec 1)) + (rw (make-dvec 1)) + (cw (make-dvec 1))) (slatec:zbesy rx cx (to-df n) 1 1 ry cy 0 rw cw 0) (complex (aref ry 0) (aref cy 0)))) (t (let ((x (to-df x))) (case n (0 (slatec:dbesy0 x)) (1 (slatec:dbesy1 x)) - (t (let ((y (dvec 1))) + (t (let ((y (make-dvec 1))) (slatec:dbesy x (to-df n) 1 y) (aref y 0)))))))) @@ -67,15 +67,15 @@ (typecase x (complex (let ((rx (to-df (realpart x))) (cx (to-df (imagpart x))) - (ry (dvec 1)) - (cy (dvec 1))) + (ry (make-dvec 1)) + (cy (make-dvec 1))) (slatec:zbesi rx cx (to-df n) 1 1 ry cy 0 0) (complex (aref ry 0) (aref cy 0)))) (t (let ((x (to-df x))) (case n (0 (slatec:dbesi0 x)) (1 (slatec:dbesi1 x)) - (t (let ((y (dvec 1))) + (t (let ((y (make-dvec 1))) (slatec:dbesi x (to-df n) 1 1 y 0) (aref y 0)))))))) @@ -86,15 +86,15 @@ (typecase x (complex (let ((rx (to-df (realpart x))) (cx (to-df (imagpart x))) - (ry (dvec 1)) - (cy (dvec 1))) + (ry (make-dvec 1)) + (cy (make-dvec 1))) (slatec:zbesk rx cx (to-df n) 1 1 ry cy 0 0) (complex (aref ry 0) (aref cy 0)))) (t (let ((x (to-df x))) (case n (0 (slatec:dbesk0 x)) (1 (slatec:dbesk1 x)) - (t (let ((y (dvec 1))) + (t (let ((y (make-dvec 1))) (slatec:dbesk x (to-df n) 1 1 y 0) (aref y 0)))))))) @@ -104,8 +104,8 @@ ;; TODO: what about negaive n, negative x and complex n? (let ((rx (to-df (realpart x))) (cx (to-df (imagpart x))) - (ry (dvec 1)) - (cy (dvec 1))) + (ry (make-dvec 1)) + (cy (make-dvec 1))) (slatec:zbesh rx cx (to-df n) 1 1 1 ry cy 0 0 ) (complex (aref ry 0) (aref cy 0)))) @@ -115,8 +115,8 @@ ;; TODO: what about negaive n, negative x and complex n? (let ((rx (to-df (realpart x))) (cx (to-df (imagpart x))) - (ry (dvec 1)) - (cy (dvec 1))) + (ry (make-dvec 1)) + (cy (make-dvec 1))) (slatec:zbesh rx cx (to-df n) 1 2 1 ry cy 0 0 ) (complex (aref ry 0) (aref cy 0)))) Modified: trunk/src/vector1/level1-vector.lisp ============================================================================== --- trunk/src/vector1/level1-vector.lisp (original) +++ trunk/src/vector1/level1-vector.lisp Sat Oct 2 11:29:26 2010 @@ -48,6 +48,11 @@ ;;; General +(defmethod print-object ((v vector-base) stream) + (print-unreadable-object (v stream :type t :identity t) + (dotimes (i (min (size v) *lisplab-print-size*)) + (format stream "~a " (vref v i))))) + (defmethod vector-p ((x vector-base)) t) (defmethod rank ((x vector-base)) From jivestgarden at common-lisp.net Sun Oct 24 08:49:57 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 04:49:57 -0400 Subject: [lisplab-cvs] r186 - in trunk/src: fft matrix1 util vector1 Message-ID: Author: jivestgarden Date: Sun Oct 24 04:49:56 2010 New Revision: 186 Log: Cleaning + matrix slices Added: trunk/src/util/ref.lisp trunk/src/util/type.lisp trunk/src/vector1/level1-matrix-slice.lisp Modified: trunk/src/fft/level3-fft-zge.lisp trunk/src/matrix1/level1-classes.lisp trunk/src/util/ext-store-operators.lisp trunk/src/util/level1-util.lisp trunk/src/vector1/level1-vector.lisp Modified: trunk/src/fft/level3-fft-zge.lisp ============================================================================== --- trunk/src/fft/level3-fft-zge.lisp (original) +++ trunk/src/fft/level3-fft-zge.lisp Sun Oct 24 04:49:56 2010 @@ -97,54 +97,6 @@ (fft-radix-2-blas-complex-store! :r (vector-store x) (cols x) i (rows x))) x) -(declaim (ftype (function - (type-blas-store - type-blas-idx - type-blas-idx - type-blas-idx) - (complex double-float)) - ref-blas-complex-store2)) - -(declaim (ftype (function - ((complex double-float) - type-blas-store - type-blas-idx - type-blas-idx - type-blas-idx - ) - (complex double-float)) - (setf ref-blas-complex-store2))) - -(declaim (inline ref-blas-complex-store2 (setf ref-blas-complex-store2))) - -(defun ref-blas-complex-store2 (store i start step) - "Accessor for the complex blas store" - (declare (type-blas-idx i start step) - (type-blas-store store)) - (let* ((idx (truly-the type-blas-idx - (* 2 (+ (truly-the type-blas-idx (* step i)) - start)))) - (val (complex (aref store idx) - (aref store (1+ idx))))) - (declare (type type-blas-idx idx) - (type (complex double-float) val)) - val)) - -(defun (setf ref-blas-complex-store2) (value store i start step) - (declare (type-blas-idx i start step) - (type-blas-store store) - ((complex double-float) value) ) - (let ((idx (truly-the type-blas-idx - (* 2 - (truly-the type-blas-idx - (+ - (truly-the type-blas-idx (* step i)) - start)))))) - (declare (type-blas-idx idx)) - (setf (aref store idx) (realpart value) - (aref store (1+ idx)) (imagpart value)) - value)) - (defun fft-radix-2-blas-complex-store! (direction x n start step) "Destrutive, radix 2 fast fourier transform. Direction is either :f for forward or :r for reverse transform. Input must be a Modified: trunk/src/matrix1/level1-classes.lisp ============================================================================== --- trunk/src/matrix1/level1-classes.lisp (original) +++ trunk/src/matrix1/level1-classes.lisp Sun Oct 24 04:49:56 2010 @@ -189,9 +189,7 @@ (cols :initarg :cols :initform 0 :reader cols - :type type-blas-idx) - (size :reader size - :type type-blas-idx))) + :type type-blas-idx))) (defclass structure-square (structure-base) ((structure-class-name :allocation :class Modified: trunk/src/util/ext-store-operators.lisp ============================================================================== --- trunk/src/util/ext-store-operators.lisp (original) +++ trunk/src/util/ext-store-operators.lisp Sun Oct 24 04:49:56 2010 @@ -58,6 +58,7 @@ ;;; number only + and - (*, / and expt mix the real and complex parts) + (declaim (inline double-float-simple-array-ref-ext)) (declaim (ftype (function (type-blas-store @@ -69,10 +70,7 @@ (defun double-float-simple-array-ref-ext (a i off step) (declare (type type-blas-idx i off step) (type type-blas-store a)) - (aref a (truly-the type-blas-idx - (+ off - (truly-the type-blas-idx - (* i step)))))) + (aref a (column-major-idx off i step))) (declaim (inline (setf double-float-simple-array-ref-ext))) (declaim (ftype (function @@ -87,10 +85,7 @@ (declare (type type-blas-idx i off step) (type double-float value) (type type-blas-store a)) - (setf (aref a (truly-the type-blas-idx - (+ off - (truly-the type-blas-idx - (* i step))))) + (setf (aref a (column-major-idx off i step)) value) value) Modified: trunk/src/util/level1-util.lisp ============================================================================== --- trunk/src/util/level1-util.lisp (original) +++ trunk/src/util/level1-util.lisp Sun Oct 24 04:49:56 2010 @@ -30,77 +30,6 @@ (in-package :lisplab) -;;; Things that are common both for real and complex stores - -(deftype type-blas-store () - '(simple-array double-float (*))) - -#+(and :sbcl :x86) (deftype type-blas-idx () - '(MOD #x1FFFFFFF)) -#+(and :sbcl :x86-64) (deftype type-blas-idx () - '(MOD #xFFFFFFFFFFFFFFD)) -#-:sbcl (deftype type-blas-idx () - 'fixnum) - -(declaim (inline column-major-idx)) - -(declaim (ftype (function - (type-blas-idx - type-blas-idx - type-blas-idx) - type-blas-idx) - column-major-idx)) - -(defun column-major-idx (i j rows) - (truly-the type-blas-idx (+ i (truly-the type-blas-idx (* j rows))))) - -(defun copy-matrix-stores (a b) - (let ((len (length a))) - (declare (type type-blas-store a b) - (type type-blas-idx len)) - (dotimes (i len) - (setf (aref b i) (aref a i)))) - b) - -;;;; The real store - -(declaim (inline ref-blas-real-store (setf ref-blas-real-store))) - -(declaim (ftype (function - (type-blas-store - type-blas-idx - type-blas-idx - type-blas-idx) - double-float) - ref-blas-real-store)) - -(defun ref-blas-real-store (store row col rows) - "Matrix accessor for the real blas store" - (aref (truly-the type-blas-store store) - (truly-the type-blas-idx - (column-major-idx (truly-the type-blas-idx row) - (truly-the type-blas-idx col) - rows)))) - -(declaim (ftype (function - (double-float - type-blas-store - type-blas-idx - type-blas-idx - type-blas-idx - ) - double-float) - (setf ref-blas-real-store))) - -(defun (setf ref-blas-real-store) (value store row col rows) - (setf (aref (truly-the type-blas-store store) - (truly-the type-blas-idx - (column-major-idx (truly-the type-blas-idx row) - (truly-the type-blas-idx col) - rows))) - value) - value) - (defun allocate-real-store (size &optional (initial-element 0d0)) ;; All matrix double and complex double constructors ;; should call this one @@ -153,71 +82,4 @@ (setf (aref store i) rv))) store)) -(declaim (inline ref-blas-complex-store (setf ref-blas-complex-store))) - -(declaim (ftype (function - (type-blas-store - type-blas-idx - type-blas-idx - type-blas-idx) - (complex double-float)) - ref-blas-complex-store)) - -(defun ref-blas-complex-store (store row col rows) - "Matrix accessor for the complet blas store" - (let ((idx (truly-the type-blas-idx - (* 2 (column-major-idx (truly-the type-blas-idx row) - (truly-the type-blas-idx col) - rows))))) - (declare (type-blas-idx idx)) - (complex (aref store idx) - (aref store (1+ idx))))) - -(declaim (ftype (function - ((complex double-float) - type-blas-store - type-blas-idx - type-blas-idx - type-blas-idx - ) - (complex double-float)) - (setf ref-blas-complex-store))) - -(defun (setf ref-blas-complex-store) (value store row col rows) - (let ((idx (truly-the type-blas-idx - (* 2 (column-major-idx (truly-the type-blas-idx row) - (truly-the type-blas-idx col) - rows))))) - (declare (type-blas-idx idx)) - (setf (aref store idx) (realpart value) - (aref store (1+ idx)) (imagpart value)) - value)) - -(declaim (ftype (function - (type-blas-store - type-blas-idx) - (complex double-float)) - vref-blas-complex-store)) - -(defun vref-blas-complex-store (store idx) - "Matrix accessor for the complex blas store" - (let ((idx2 (truly-the type-blas-idx (* 2 idx)))) - (declare (type-blas-idx idx2)) - (complex (aref store idx2) - (aref store (1+ idx2))))) - -(declaim (ftype (function - ((complex double-float) - type-blas-store - type-blas-idx - ) - (complex double-float)) - (setf vref-blas-complex-store))) - -(defun (setf vref-blas-complex-store) (value store idx) - (let ((idx2 (truly-the type-blas-idx (* 2 idx)))) - (declare (type-blas-idx idx2)) - (setf (aref store idx2) (realpart value) - (aref store (1+ idx2)) (imagpart value)) - value)) Added: trunk/src/util/ref.lisp ============================================================================== --- (empty file) +++ trunk/src/util/ref.lisp Sun Oct 24 04:49:56 2010 @@ -0,0 +1,211 @@ +;;; Lisplab, ref.lisp +;;; Array reference functions. +;;; Note, most other files depends on this one ! +;;; +;;; Copyright (C) 2010 Joern Inge Vestgaarden +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 2 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License along +;;; with this program; if not, write to the Free Software Foundation, Inc., +;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +;;; TODO: change name of this to something about blas store +;;; +;;; This file contains manipulations of simple double-float arrays +;;; and should be called by the spesialized matrix methods. +;;; The purpose of this layer is that it can be used by +;;; many classes such as matrix-base-dge and matrix-base-ddi, etc. +;;; +;;; The content of this file must be highly optimized +;;; and should not depend anything exept Common Lisp itself. + +(in-package :lisplab) + +(declaim (inline column-major-idx)) + +(declaim (ftype (function + (type-blas-idx + type-blas-idx + type-blas-idx) + type-blas-idx) + column-major-idx)) + +(defun column-major-idx (i j rows) + (truly-the type-blas-idx (+ i (truly-the type-blas-idx (* j rows))))) + +(defun copy-matrix-stores (a b) + (let ((len (length a))) + (declare (type type-blas-store a b) + (type type-blas-idx len)) + (dotimes (i len) + (setf (aref b i) (aref a i)))) + b) + +;;;; The real store + +(declaim (inline ref-blas-real-store (setf ref-blas-real-store))) + +(declaim (ftype (function + (type-blas-store + type-blas-idx + type-blas-idx + type-blas-idx) + double-float) + ref-blas-real-store)) + +(defun ref-blas-real-store (store row col rows) + "Matrix accessor for the real blas store" + (aref (truly-the type-blas-store store) + (truly-the type-blas-idx + (column-major-idx (truly-the type-blas-idx row) + (truly-the type-blas-idx col) + rows)))) + +(declaim (ftype (function + (double-float + type-blas-store + type-blas-idx + type-blas-idx + type-blas-idx + ) + double-float) + (setf ref-blas-real-store))) + +(defun (setf ref-blas-real-store) (value store row col rows) + (setf (aref (truly-the type-blas-store store) + (truly-the type-blas-idx + (column-major-idx (truly-the type-blas-idx row) + (truly-the type-blas-idx col) + rows))) + value) + value) + +(declaim (inline ref-blas-complex-store (setf ref-blas-complex-store))) + +(declaim (ftype (function + (type-blas-store + type-blas-idx + type-blas-idx + type-blas-idx) + (complex double-float)) + ref-blas-complex-store)) + +(defun ref-blas-complex-store (store row col rows) + "Matrix accessor for the complet blas store" + (let ((idx (truly-the type-blas-idx + (* 2 (column-major-idx (truly-the type-blas-idx row) + (truly-the type-blas-idx col) + rows))))) + (declare (type-blas-idx idx)) + (complex (aref store idx) + (aref store (1+ idx))))) + +(declaim (ftype (function + ((complex double-float) + type-blas-store + type-blas-idx + type-blas-idx + type-blas-idx + ) + (complex double-float)) + (setf ref-blas-complex-store))) + +(defun (setf ref-blas-complex-store) (value store row col rows) + (let ((idx (truly-the type-blas-idx + (* 2 (column-major-idx (truly-the type-blas-idx row) + (truly-the type-blas-idx col) + rows))))) + (declare (type-blas-idx idx)) + (setf (aref store idx) (realpart value) + (aref store (1+ idx)) (imagpart value)) + value)) + +(declaim (ftype (function + (type-blas-store + type-blas-idx) + (complex double-float)) + vref-blas-complex-store)) + +(defun vref-blas-complex-store (store idx) + "Matrix accessor for the complex blas store" + (let ((idx2 (truly-the type-blas-idx (* 2 idx)))) + (declare (type-blas-idx idx2)) + (complex (aref store idx2) + (aref store (1+ idx2))))) + +(declaim (ftype (function + ((complex double-float) + type-blas-store + type-blas-idx + ) + (complex double-float)) + (setf vref-blas-complex-store))) + +(defun (setf vref-blas-complex-store) (value store idx) + (let ((idx2 (truly-the type-blas-idx (* 2 idx)))) + (declare (type-blas-idx idx2)) + (setf (aref store idx2) (realpart value) + (aref store (1+ idx2)) (imagpart value)) + value)) + + +;;; Alternative references used by fft + +(declaim (ftype (function + (type-blas-store + type-blas-idx + type-blas-idx + type-blas-idx) + (complex double-float)) + ref-blas-complex-store2)) + +(declaim (inline ref-blas-complex-store2)) + +(defun ref-blas-complex-store2 (store i start step) + "Accessor for the complex blas store" + (declare (type-blas-idx i start step) + (type-blas-store store)) + (let* ((idx (truly-the type-blas-idx + (* 2 (+ (truly-the type-blas-idx (* step i)) + start)))) + (val (complex (aref store idx) + (aref store (1+ idx))))) + (declare (type type-blas-idx idx) + (type (complex double-float) val)) + val)) + +(declaim (inline ref-blas-complex-store2 (setf ref-blas-complex-store2))) + +(declaim (ftype (function + ((complex double-float) + type-blas-store + type-blas-idx + type-blas-idx + type-blas-idx + ) + (complex double-float)) + (setf ref-blas-complex-store2))) + +(defun (setf ref-blas-complex-store2) (value store i start step) + (declare (type-blas-idx i start step) + (type-blas-store store) + ((complex double-float) value) ) + (let ((idx (truly-the type-blas-idx + (* 2 + (truly-the type-blas-idx + (+ + (truly-the type-blas-idx (* step i)) + start)))))) + (declare (type-blas-idx idx)) + (setf (aref store idx) (realpart value) + (aref store (1+ idx)) (imagpart value)) + value)) Added: trunk/src/util/type.lisp ============================================================================== --- (empty file) +++ trunk/src/util/type.lisp Sun Oct 24 04:49:56 2010 @@ -0,0 +1,43 @@ +;;; Lisplab, type.lisp +;;; Type definition for double float arrays and vector index +;;; Note, most other files depends on this one ! +;;; +;;; Copyright (C) 2010 Joern Inge Vestgaarden +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 2 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License along +;;; with this program; if not, write to the Free Software Foundation, Inc., +;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +;;; TODO: change name of this to something about blas store +;;; +;;; This file contains manipulations of simple double-float arrays +;;; and should be called by the spesialized matrix methods. +;;; The purpose of this layer is that it can be used by +;;; many classes such as matrix-base-dge and matrix-base-ddi, etc. +;;; +;;; The content of this file must be highly optimized +;;; and should not depend anything exept Common Lisp itself. + +(in-package :lisplab) + +;;; Things that are common both for real and complex stores + +(deftype type-blas-store () + '(simple-array double-float (*))) + +#+(and :sbcl :x86) (deftype type-blas-idx () + '(MOD #x1FFFFFFF)) +#+(and :sbcl :x86-64) (deftype type-blas-idx () + '(MOD #xFFFFFFFFFFFFFFD)) +#-:sbcl (deftype type-blas-idx () + 'fixnum) Added: trunk/src/vector1/level1-matrix-slice.lisp ============================================================================== --- (empty file) +++ trunk/src/vector1/level1-matrix-slice.lisp Sun Oct 24 04:49:56 2010 @@ -0,0 +1,61 @@ +;;; Lisplab, level1-matrix-slice.lisp +;;; Vectors that are slice of matrices, i.e. row or column vectors. + +;;; Copyright (C) 2009 Joern Inge Vestgaarden +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 2 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License along +;;; with this program; if not, write to the Free Software Foundation, Inc., +;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +(in-package :lisplab) + +(defclass matrix-slice-base (vector-base) + ((off :initarg :off :initform 0) + (step :initarg :step :initform 0) + (size :initarg :size :initform 0))) + +(defclass matrix-slice-any (matrix-slice-base) + ((store :initarg :store + :initform nil + :reader vector-store))) + +(defclass matrix-slice-dge (matrix-slice-base) + ((store :initarg :store + :initform nil + :reader type-blas-store))) + +;;; Untyped matrix slices + +(defmethod vref ((vector matrix-slice-any) idx) + (with-slots (store off step size) vector + (aref store (column-major-idx off idx step)))) + +(defmethod (setf vref) (value (vector matrix-slice-any) idx) + (with-slots (store off step size) vector + (setf (aref store (column-major-idx off idx step)) + value)) + value) + +;;; Double float matrix slices + +(defmethod vref ((vector matrix-slice-dge) idx) + (with-slots (store off step size) vector + (declare (type type-blas-store store)) + (aref store (column-major-idx off idx step)))) + +(defmethod (setf vref) (value (vector matrix-slice-dge) idx) + (with-slots (store off step size) vector + (declare (type type-blas-store store)) + (setf (aref store (column-major-idx off idx step)) + value)) + value) \ No newline at end of file Modified: trunk/src/vector1/level1-vector.lisp ============================================================================== --- trunk/src/vector1/level1-vector.lisp (original) +++ trunk/src/vector1/level1-vector.lisp Sun Oct 24 04:49:56 2010 @@ -26,7 +26,10 @@ (in-package :lisplab) (defclass vector-base () - ((size :initform 0 :initarg size :accessor size))) + ((size :initarg :size + :initform 0 + :reader size + :type type-blas-idx))) (defclass vector-any (vector-base element-base) ((store :initarg :store From jivestgarden at common-lisp.net Sun Oct 24 08:57:12 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 04:57:12 -0400 Subject: [lisplab-cvs] r187 - trunk Message-ID: Author: jivestgarden Date: Sun Oct 24 04:57:12 2010 New Revision: 187 Log: The build file from last commit Modified: trunk/lisplab.asd Modified: trunk/lisplab.asd ============================================================================== --- trunk/lisplab.asd (original) +++ trunk/lisplab.asd Sun Oct 24 04:57:12 2010 @@ -66,7 +66,9 @@ :depends-on () :serial t :components - ((:file "level1-util") + ((:file "type") + (:file "ref") + (:file "level1-util") (:file "store-operators") (:file "store-ordinary-functions") (:file "permutation") From jivestgarden at common-lisp.net Sun Oct 24 09:03:06 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 05:03:06 -0400 Subject: [lisplab-cvs] r188 - trunk Message-ID: Author: jivestgarden Date: Sun Oct 24 05:03:05 2010 New Revision: 188 Log: Fix to last commit Modified: trunk/lisplab.asd Modified: trunk/lisplab.asd ============================================================================== --- trunk/lisplab.asd (original) +++ trunk/lisplab.asd Sun Oct 24 05:03:05 2010 @@ -63,7 +63,7 @@ )) (:module :src/util - :depends-on () + :depends-on ("package") :serial t :components ((:file "type") From jivestgarden at common-lisp.net Sun Oct 24 09:05:35 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 05:05:35 -0400 Subject: [lisplab-cvs] r189 - trunk Message-ID: Author: jivestgarden Date: Sun Oct 24 05:05:35 2010 New Revision: 189 Log: Fix to last commit Modified: trunk/lisplab.asd Modified: trunk/lisplab.asd ============================================================================== --- trunk/lisplab.asd (original) +++ trunk/lisplab.asd Sun Oct 24 05:05:35 2010 @@ -63,7 +63,7 @@ )) (:module :src/util - :depends-on ("package") + :depends-on (src/core) ; Fixit: it only needs package and define-constant :serial t :components ((:file "type") From jivestgarden at common-lisp.net Sun Oct 24 10:17:43 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 06:17:43 -0400 Subject: [lisplab-cvs] r190 - in trunk/src: matrix1 test Message-ID: Author: jivestgarden Date: Sun Oct 24 06:17:43 2010 New Revision: 190 Log: bugfix Modified: trunk/src/matrix1/level1-funmat.lisp trunk/src/matrix1/level1-sparse.lisp trunk/src/test/scaling-test.lisp trunk/src/test/test-methods.lisp Modified: trunk/src/matrix1/level1-funmat.lisp ============================================================================== --- trunk/src/matrix1/level1-funmat.lisp (original) +++ trunk/src/matrix1/level1-funmat.lisp Sun Oct 24 06:17:43 2010 @@ -22,7 +22,7 @@ ;;; Function matrices (matrices without a store) (defclass function-matrix - (structure-general element-base implementation-base) + (structure-general element-base implementation-base vector-base) ((mref :initarg :mref :initform (constantly 0) Modified: trunk/src/matrix1/level1-sparse.lisp ============================================================================== --- trunk/src/matrix1/level1-sparse.lisp (original) +++ trunk/src/matrix1/level1-sparse.lisp Sun Oct 24 06:17:43 2010 @@ -24,7 +24,7 @@ (in-package :lisplab) (defclass matrix-sparse - (structure-general element-base implementation-lisp) + (structure-general element-base implementation-lisp vector-base) ((hash-store :initarg :store :initform nil Modified: trunk/src/test/scaling-test.lisp ============================================================================== --- trunk/src/test/scaling-test.lisp (original) +++ trunk/src/test/scaling-test.lisp Sun Oct 24 06:17:43 2010 @@ -1,6 +1,8 @@ -;;; Test the scaling of various lisplab methods -;;; by creating a gnuplot script -;;; The purpose is to see if the performance is ok. +;;; Test the scaling of various lisplab methods to see +;;; if performance is OK. +;;; +;;; Outputs a gnuplot script. +;;; Open gnuplot and load the file. ;;; Findings: ;;; o The complex functions are very slow @@ -28,6 +30,7 @@ (with-open-file (out file :direction :output :if-exists :supersede) (format out "set logscale x~%") (format out "set logscale y~%") + (format out "set key left~%") (format out "plot ") (mapc (lambda (title next) (format out " '-' ti '~a' w lp, " title)) @@ -62,9 +65,9 @@ '(mmax mmin mabsmax mabsmin ll::mminmax)) (defun report-function-times (filename &key - (ns '(1 2 3 4 5 10 20 50 100 150 200 300 400 500)) + (ns '(10 20 50 100 250 500)) (avg 10) - (funs (ordinary-functions)) + (funs (ordinary-functions)) (titles (mapcar #'symbol-name funs)) (mats (mapcar (lambda (n) (drandom N N)) ns))) (let* ((times (time-functions funs (mapcar #'list mats) avg))) @@ -78,12 +81,12 @@ '(.+ .- .* ./ .^ .max .min .= ./= .< .> .<= .>=)) (defun report-operator-times (filename &key - (ns '(1 2 3 4 5 10 20 50 100 150 200 300 400 500)) + (ns '(10 20 50 100 250 500)) (avg 10) (funs (ordinary-operators-real)) (titles (mapcar #'symbol-name funs)) (lmats (mapcar (lambda (n) (drandom N N)) ns)) - (rmats lmats)) + (rmats (mapcar (lambda (n) (drandom N N)) ns))) (let* ((times (time-functions funs (mapcar #'list lmats rmats) avg))) (write-gnuplot-scaling filename ns times titles) :end)) Modified: trunk/src/test/test-methods.lisp ============================================================================== --- trunk/src/test/test-methods.lisp (original) +++ trunk/src/test/test-methods.lisp Sun Oct 24 06:17:43 2010 @@ -24,7 +24,7 @@ (c %i) (x #md((1 2 ) (3 4))) (y #md((1 2 3) (3 4 3))) - (w #mm((1 2 2) (3 4 3) (1 100000 1000000)) + (w #mm((1 2 2) (3 4 3) (1 100000 1000000))) (args (list a b c x y w))) (mapc (lambda (fun) (mapc (lambda (x) @@ -60,6 +60,7 @@ (mapc (lambda (x) (simple-non-nil-check '.besk (list 7.1 x))) args) (mapc (lambda (x) (simple-non-nil-check '.besh1 (list 7.1 x))) args) (mapc (lambda (x) (simple-non-nil-check '.besh2 (list 7.1 x))) args) + 'done)) From jivestgarden at common-lisp.net Sun Oct 24 10:23:03 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 06:23:03 -0400 Subject: [lisplab-cvs] r191 - trunk Message-ID: Author: jivestgarden Date: Sun Oct 24 06:23:02 2010 New Revision: 191 Log: build dependencies Modified: trunk/lisplab.asd Modified: trunk/lisplab.asd ============================================================================== --- trunk/lisplab.asd (original) +++ trunk/lisplab.asd Sun Oct 24 06:23:02 2010 @@ -83,7 +83,7 @@ )) (:module :src/matrix1 - :depends-on (:src/core :src/vector1) + :depends-on (:src/core :src/vector1 :src/util) :serial t :components ((:file "level1-classes") @@ -102,7 +102,7 @@ )) (:module :src/vector2 - :depends-on (:src/core :src/vector1) + :depends-on (:src/core :src/vector1 :src/util) :serial t :components ((:file "level2-interface") @@ -119,7 +119,7 @@ )) (:module :src/matrix2 - :depends-on (:src/core :src/vector1 :src/matrix1) + :depends-on (:src/core :src/vector1 :src/matrix1 :src/util) :serial t :components ((:file "level2-constructors") @@ -140,7 +140,7 @@ ;; Linear algebra lisp implementation (Level 3) ;; (:module :src/linalg - :depends-on (:src/matrix2) + :depends-on (:src/matrix2 :src/util) :serial t :components ((:file "level3-linalg-interface") @@ -151,7 +151,7 @@ ;; Fast Fourier transform (Level 3) ;; (:module :src/fft - :depends-on (:src/matrix2) + :depends-on (:src/matrix2 :src/util) :serial t :components ( From jivestgarden at common-lisp.net Sun Oct 24 12:59:57 2010 From: jivestgarden at common-lisp.net (=?UTF-8?Q?J=C3=B8rn_Inge_Vestg=C3=A5rden?=) Date: Sun, 24 Oct 2010 08:59:57 -0400 Subject: [lisplab-cvs] r192 - trunk/doc/manual Message-ID: Author: jivestgarden Date: Sun Oct 24 08:59:56 2010 New Revision: 192 Log: fixed doc Modified: trunk/doc/manual/lisplab.texi Modified: trunk/doc/manual/lisplab.texi ============================================================================== --- trunk/doc/manual/lisplab.texi (original) +++ trunk/doc/manual/lisplab.texi Sun Oct 24 08:59:56 2010 @@ -50,19 +50,20 @@ infix notation, and interfaces to BLAS, LAPACK, FFTW, SLATEC and QUADPACK. -The name Lisplab is inspired by Matlab and Lisplab offers -much of the same kind of programming-style as Matlab, with high level -manipulation of matrices, but contrary to Matlab, Lisplab -benefits from being a part of Common Lisp. Hence, you have +The name Lisplab is inspired by Matlab and a purpose of Lisplab +is to add the Matlab programming style to Common Lisp. +Hence you can do high level manipulation of matrices, while +still benefitting from being a part of Common Lisp, with lexical scope, dynamic scope, macros, first class -functions, iterations, CLOS, fast execution, -and working in an free general purpose programming language. And -best of all: you can enjoy you favorite data-types in addition +functions, iterations, CLOS, fast execution, +and fast open source implementations. And +best of all, you can enjoy you favorite Common Lisp +data types in addition to the matrices: functions, hash tables, structures, classes, arbitrary precision integers, rationals, and lists. Lisplab is not unique in building Matlab-like -syntax on top of Common Lisp. Other similar framweorks are +syntax on top of Common Lisp, please consults also Matlisp, Femlisp, NLISP and GSLL. Lisplab itself was started as a branch of Matlisp, but there is now only little of the original code left. @@ -90,14 +91,14 @@ @item The Matlisp FFI should in theory be portable to other lisps and Windows, but it has not yet been tested. @item The @code{*READ-DEFAULT-FLOAT-FORMAT*} must be @code{double-float} -when compiling Slatec. This is a minor problem. +when compiling Slatec. (This should be is a minor problem.) @end itemize Except from this, Lisplab should be self-contained and not depend on any other projects. @section Installing -Lisplab is ASDF installable, but before you come so far you need to +Lisplab is installed by ASDF, but before you come so far you need to specify the location of the foreign libraries. You specify these in three special variables, @itemize @@ -105,7 +106,7 @@ @item @code{*lisplab-liblapack-path*} @item @code{*lisplab-libfftw-path*} @end itemize -that live their lives in the Common-Lisp-User package. +living in the Common-Lisp-User package. You can either assign them on the top-level, in you Common Lisp installation file, in @code{start.lisp}, or probably the easiest: directly in @code{lisplab.asd}. @@ -131,9 +132,9 @@ If you have problems loading, first look at @code{start.lisp} and see if you can hack it. Then look at @code{lisplab.asd}. -To install BLAS, LAPACK, and FFTW, if you are too lazy to do a custom build, -and is lucky enough to administer a Debian or Ubuntu machine, -you typically write +If you are too lazy to do a custom build, +and lucky enough to administer a Debian or Ubuntu machine, +you typically install BLAS, LAPACK and FFTW as @example # aptitude install libatlas3gf-base # aptitude install libfftw3-3 @@ -142,25 +143,23 @@ @section Naming conventions @itemize @item -The matrix classes and constructors follow the naming convention -from BLAS where you give names based on element type and -matrix structure. +Matrix names follow the BLAS naming convention of +(element type, matrix structure). The most used types are @i{f - float}, @i{d - double}, - at i{c - complex float}, @i{z - complex double float}, -while for matrix structure @i{ge - general}, @i{di - diagonal}, -and many more. So @i{matrix-dge} is a general matrix + at i{c - complex float}, @i{z - complex double float}. +The most used matrix structures are @i{ge - general} and @i{di - diagonal}. +For example, @i{matrix-dge} is a general matrix with double float elements, while @i{matrix-zge} is a general matrix with complex double float elements. @item -The generic functions of the basic algebra start with a dot: +Functions starting with @code{.} act elementwise on matrices. +For example @code{.+}, @code{.-}, @code{.*}, @code{./}, @code{.^}, @code{.sin} @code{.cos}, @code{.tan}, @code{.besj}, @code{.re}, etc. -On numbers these functions work as the non-dotted Common Lisp functions -and on matrices they work elementwise. @item Linear algebra functions tend to start with @i{m}: @code{m*}, @code{minv}, @code{mmax}, @code{mtp}, etc., -but this conventions is not strictly followed. +(This conventions is not followed strictly.) @item The naming convention of files follow the layered structure of Lisplab, with level0 to level3. @@ -201,14 +200,18 @@ Hence, the list in this section must be read as non-systematic gathering of problem features. @itemize - at item Lisplab runs only on SBCL. + at item +Lisplab runs only on SBCL. Lisplab is mainly ANSI Common Lisp, so just minor changes in the build-system should make it run on other lisps, but the problem is that it will most probably be slow. It should be fast on CMUCL, though. - at item Lacks a formal spec. - at item Poorly tested. - at item Lacks error checks (but these should not be made before a spec!) + at item +Lacks a formal spec. + at item +Poorly tested. + at item +Lacks error checks (but these should not be made before a spec!) @end itemize @@ -469,6 +472,9 @@ The output matrix takes the structure from the first arguments, but ignores in general matrix structure. If first argument @code{t} output type is same as type of first matrix argument. +If type is @code{t} the output matrix has type equals the +first matrix argument, +if it is @code{nil} nothing is returned. @section Ordinary functions @@ -506,28 +512,41 @@ @section Design principles High level principles @itemize - at item Lisplab will be a @i{homogeneous platform} for mathematics. - at item Lisplab is free software. - at item User applications should need to stay only in Common Lisp. + at item +Lisplab is free software. + at item +Lisplab is a high-level homogeneous platform for mathematics. + at item +User applications should need to stay only in Common Lisp. (There should be no need for optimized math in FFIs or special languages like Maxima) - at item Lisplab will steal as much code as possible from as many as possible. + at item +Lisplab steals as much code as possible from as many as possible. @end itemize General design principles @itemize - at item Every common mathematical operator and function + at item +Every common mathematical operator and function is represented by a @i{CLOS generic function}. - at item Modular structure (Inspired by GSL). - at item Trust the Lisp virtual machine (Avoid use of FFIs and destructive functions). - at item Avoid mathematical algorithms in macros. - at item Error checks is primarily caller's responsibility. + at item +Modular structure (Inspired by GSL). + at item +Trust the Lisp virtual machine +(E.g. avoid manual memory management and destructive functions). + at item +Avoid mathematical algorithms in macros. + at item +Error checks is primarily caller's responsibility. @end itemize Design principles for the matrix code @itemize - at item Layered structure where dependencies are + at item +Layered structure where dependencies are primarily to the layer below -- not vertical within the layer. + at item +All matrix optimization should be in level 2. @end itemize @@ -543,19 +562,23 @@ has a layered structure with four levels, 0 -- 3, where @itemize - at item @b{Level 0} is matrix independent and contains + at item + at b{Level 0} is matrix independent and contains generic functions for mathematics. In this level only specialization for numbers and non-matrix objects. - at item @b{Level 1} defines matrices and implements + at item + at b{Level 1} defines matrices and implements @code{mref}, @code{vref}, at code{cols}, @code{rows}, @code{size} and @code{make-matrix-instance}. - at item @b{Level 2} Implements level 0 for matrices and + at item + at b{Level 2} Implements level 0 for matrices and defines core functionality related to matrices such as matrix constructors @code{dnew}, @code{dcol}, etc. and other matrix helper functions, such as @code{mmax}, @code{mmin}, @code{circ-shift}, etc. Optimizations are mainly in level 2. - at item @b{Level 3} is everything else that uses matrices, + at item + at b{Level 3} is everything else that uses matrices, including linear algebra, FFTs, solvers, etc. @end itemize The levels are unequal in size: level 0 is potentially large, @@ -563,27 +586,34 @@ The intention with the structure are the following @itemize - at item To minimize the work needed to add new matrices implementations. + at item +To minimize the work needed to add new matrices implementations. Actually, you need only to implement level 1, provided you inherit from matrix base. Otherwise you need also to implement level 2. - at item To encourage code reuse. For example, if you add + at item +To encourage code reuse. For example, if you add a new type to the dotted algebra, such as polynomials, symbolic expressions, or arbitrary precision floats, you can immediately perform matrix operations on them without write one single extra line of code. - at item To manage optimizations and special implementations by + at item +To manage optimizations and special implementations by overloading for specialized matrix types, mainly at level 2, but also at level 3. - at item To make foreign libraries available in Common Lisp. - at item To create a closed, constant and extensible system of operations. + at item +To make foreign libraries available in Common Lisp. + at item +To create a closed, constant and extensible system of operations. @end itemize -The filenames often also denote the levels. If a filename does not +The filenames often denote the levels. If a filename does not denote the level, it is most probably level 3, or outside the level system -(non matrix code). +(utilities or non matrix code). @section Matrix class hierarchy +Note first that all matrices are also vectors and have a 1D store. + All matrices are subclasses of @code{matrix-base}, and as far as possible the generic functions specialize on one or many of its subclasses. @@ -604,9 +634,9 @@ special properties the matrix has. Two matrix classes @itemize - at item @code{matrix-structure-general}, where the matrix + at item @code{structure-general}, where the matrix has no known symmetries. - at item @code{matrix-structure-diagonal}, where only + at item @code{structure-diagonal}, where only diagonal elements are non-zero. @item Other types to come. @end itemize @@ -615,9 +645,9 @@ The element type classes has no other purpose than to be represents a Common Lisp types. @itemize - at item @code{matrix-element-base}, represents @code{t} - at item @code{matrix-element-double-float}, represents @code{double-float} - at item @code{matrix-element-complex-double-float}, represents @code{complex double-float} + at item @code{element-base}, represents @code{t} + at item @code{element-double-float}, represents @code{double-float} + at item @code{element-complex-double-float}, represents @code{complex double-float} @end itemize @@ -627,9 +657,9 @@ one too choose. There are currently four classes in a straight line of inheritance @itemize - at item @code{matrix-implementation-base} - at item @code{matrix-implementation-lisp}, use native Common Lisp if possible. - at item @code{matrix-implementation-blas}, use foreign libraries if possible. + at item @code{implementation-base} + at item @code{implementation-lisp}, use native Common Lisp if possible. + at item @code{implementation-blas}, use foreign libraries if possible. @end itemize This standard method dispatch ensures foreign library methods are chosen before native lisp. @i{It is the responsibility of the