[lisplab-cvs] r201 - in trunk: . src/matrix2 src/vector2
jivestgarden at common-lisp.net
jivestgarden at common-lisp.net
Sun Oct 9 12:38:47 UTC 2011
Author: jivestgarden
Date: Sun Oct 9 05:38:46 2011
New Revision: 201
Log:
Moved matrix generic function out to new interface. Added two optimizations for dge
Added:
trunk/src/matrix2/matrix2-dge.lisp
trunk/src/matrix2/matrix2-interface.lisp
Modified:
trunk/lisplab.asd
trunk/src/vector2/level2-interface.lisp
Modified: trunk/lisplab.asd
==============================================================================
--- trunk/lisplab.asd Sat Jul 2 10:55:33 2011 (r200)
+++ trunk/lisplab.asd Sun Oct 9 05:38:46 2011 (r201)
@@ -123,9 +123,11 @@
:depends-on (:src/core :src/vector1 :src/matrix1 :src/util)
:serial t
:components
- ((:file "level2-constructors")
+ ((:file "matrix2-interface")
+ (:file "level2-constructors")
(:file "matrix2-generic")
(:file "level2-view")
+ (:file "matrix2-dge")
))
;;
Added: trunk/src/matrix2/matrix2-dge.lisp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/src/matrix2/matrix2-dge.lisp Sun Oct 9 05:38:46 2011 (r201)
@@ -0,0 +1,60 @@
+;;; Level two optimizations for double matrices
+
+;;; 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)
+
+(defmethod circ-shift ((A matrix-base-dge) shift)
+ (let* ((rows (rows A))
+ (cols (cols A))
+ (A-store (vector-store A))
+ (B (mcreate A))
+ (B-store (vector-store B))
+ (dr (first shift))
+ (dc (second shift)))
+ (declare (type type-blas-store A-store B-store)
+ (type type-blas-idx rows cols)
+ (fixnum dr dc))
+ (dotimes (i rows)
+ (dotimes (j cols)
+ (setf (aref B-store (column-major-idx
+ (mod (+ i dr) rows)
+ (mod (+ j dc) cols)
+ rows))
+ (aref A-store (column-major-idx i j rows)))))
+ B))
+
+(defmethod pad-shift ((A matrix-base-dge) shift &optional (value 0d0))
+ (let* ((rows (rows A))
+ (cols (cols A))
+ (A-store (vector-store A))
+ (B (mcreate A value))
+ (B-store (vector-store B))
+ (dr (first shift))
+ (dc (second shift)))
+ (declare (type type-blas-store A-store B-store)
+ (type type-blas-idx rows cols)
+ (fixnum dr dc))
+ (loop for i from (max 0 dr) below (min rows (+ rows dr)) do
+ (loop for j from (max 0 dc) below (min cols (+ cols dc)) do
+ (setf (aref B-store
+ (column-major-idx i j rows))
+ (aref A-store
+ (column-major-idx (- i dr)
+ (- j dc)
+ rows)))))
+ B))
Added: trunk/src/matrix2/matrix2-interface.lisp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/src/matrix2/matrix2-interface.lisp Sun Oct 9 05:38:46 2011 (r201)
@@ -0,0 +1,98 @@
+;;; 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-user)
+
+(defgeneric sub-matrix (m rr cc)
+ (:documentation "Copies a sub matrix of m. The format of rr = (start stop)
+or rr = (start step stop) and the same for the columns."))
+
+(defgeneric mnew (class value rows &optional cols)
+ (:documentation "General matrix constructor. Creates a new matrix
+filled with numeric arguments."))
+
+(defgeneric mcreate (a &optional value dim)
+ (:documentation "Creates a new matrix of the same type and with
+the same value as the other, but with all elements set to value."))
+
+(defgeneric mcreate* (a &key value dim element-type structure implementation)
+ (:documentation "Extended version of mcreate. Creates a new matrix of the same type
+and with the same value as the other, but with all elements set to value."))
+
+(defgeneric diag (v)
+ (:documentation "Creates a diagnoal matrix from the vector."))
+
+(defgeneric to-vector! (a)
+ (:documentation "Reshape the object to 1D. Destructive"))
+
+(defgeneric to-vector (a)
+ (:documentation "Reshape the object to 1D"))
+
+(defgeneric to-matrix! (a rows)
+ (:documentation "Reshape the object to 2D. Destructive"))
+
+(defgeneric to-matrix (a rows)
+ (:documentation "Reshape the object to 2D"))
+
+(defgeneric reshape! (a shape)
+ (:documentation "Reshapes the object. Detructive"))
+
+(defgeneric reshape (a shape)
+ (:documentation "Reshapes the object"))
+
+(defgeneric get-row! (matrix row)
+ (:documentation "Gets rows. Destructive"))
+
+(defgeneric get-row (matrix row)
+ (:documentation "Gets rows. Destructive"))
+
+(defgeneric get-col! (matrix col)
+ (:documentation "Gets rows. Destructive"))
+
+(defgeneric get-col (matrix col)
+ (:documentation "Gets rows. Destructive"))
+
+;;; Row operations
+
+(defgeneric row-swap! (matrix i j)
+ (:documentation "Swaps row i and j of matrix. Destructive."))
+
+(defgeneric row-mul! (matrix i number)
+ (:documentation "Multiplies row i with number. Destructive."))
+
+(defgeneric row-add! (matrix i j number)
+ (:documentation "Adds a multiplicum of row j to row i. A_ic=A_ic+number*A_jc. Destructive."))
+
+
+;;;; Views
+
+(defgeneric view-row (matrix row)
+ (:documentation "Returns a shared structure view of the row"))
+
+(defgeneric view-col (matrix col)
+ (:documentation "Returns a shared structure view of the row"))
+
+(defgeneric view-matrix (matrix dim &optional (type))
+ (:documentation "Returns a shared structure view of the matrix"))
+
+(defgeneric view-transpose (a)
+ (:documentation "Returns a transposed matrix with same (shared) elements"))
+
+(defgeneric circ-shift (m shifts)
+ (:documentation "Shifts the matrix with periodic indices"))
+
+(defgeneric pad-shift (m shifts &optional value)
+ (:documentation "Shifts the matrix and pads results"))
Modified: trunk/src/vector2/level2-interface.lisp
==============================================================================
--- trunk/src/vector2/level2-interface.lisp Sat Jul 2 10:55:33 2011 (r200)
+++ trunk/src/vector2/level2-interface.lisp Sun Oct 9 05:38:46 2011 (r201)
@@ -33,83 +33,10 @@
(defgeneric .every (pred a &rest matrices)
(:documentation "Generalizes every."))
-(defgeneric sub-matrix (m rr cc)
- (:documentation "Copies a sub matrix of m. The format of rr = (start stop)
-or rr = (start step stop) and the same for the columns."))
-
(defgeneric copy-contents (a b &optional converter)
(:documentation "Copies all elements from a to b."))
-(defgeneric mnew (class value rows &optional cols)
- (:documentation "General matrix constructor. Creates a new matrix
-filled with numeric arguments."))
-
-(defgeneric mcreate (a &optional value dim)
- (:documentation "Creates a new matrix of the same type and with
-the same value as the other, but with all elements set to value."))
-
-(defgeneric mcreate* (a &key value dim element-type structure implementation)
- (:documentation "Extended version of mcreate. Creates a new matrix of the same type
-and with the same value as the other, but with all elements set to value."))
-
-(defgeneric diag (v)
- (:documentation "Creates a diagnoal matrix from the vector."))
-
-(defgeneric to-vector! (a)
- (:documentation "Reshape the object to 1D. Destructive"))
-
-(defgeneric to-vector (a)
- (:documentation "Reshape the object to 1D"))
-
-(defgeneric to-matrix! (a rows)
- (:documentation "Reshape the object to 2D. Destructive"))
-
-(defgeneric to-matrix (a rows)
- (:documentation "Reshape the object to 2D"))
-
-(defgeneric reshape! (a shape)
- (:documentation "Reshapes the object. Detructive"))
-
-(defgeneric reshape (a shape)
- (:documentation "Reshapes the object"))
-
-(defgeneric get-row! (matrix row)
- (:documentation "Gets rows. Destructive"))
-
-(defgeneric get-row (matrix row)
- (:documentation "Gets rows. Destructive"))
-(defgeneric get-col! (matrix col)
- (:documentation "Gets rows. Destructive"))
-
-(defgeneric get-col (matrix col)
- (:documentation "Gets rows. Destructive"))
-
-;;; Row operations
-
-(defgeneric row-swap! (matrix i j)
- (:documentation "Swaps row i and j of matrix. Destructive."))
-
-(defgeneric row-mul! (matrix i number)
- (:documentation "Multiplies row i with number. Destructive."))
-
-(defgeneric row-add! (matrix i j number)
- (:documentation "Adds a multiplicum of row j to row i. A_ic=A_ic+number*A_jc. Destructive."))
-
-
-;;;; Views
-
-(defgeneric view-row (matrix row)
- (:documentation "Returns a shared structure view of the row"))
-
-(defgeneric view-col (matrix col)
- (:documentation "Returns a shared structure view of the row"))
-
-(defgeneric view-matrix (matrix dim &optional (type))
- (:documentation "Returns a shared structure view of the matrix"))
-
-(defgeneric view-transpose (a)
- (:documentation "Returns a transposed matrix with same (shared) elements"))
;;;; Single-element operations
@@ -147,11 +74,6 @@
(defgeneric mminmax (m)
(:documentation "Returns a list with (minimum maximum)"))
-(defgeneric circ-shift (m shifts)
- (:documentation "Shifts the matrix with periodic indices"))
-
-(defgeneric pad-shift (m shifts &optional value)
- (:documentation "Shifts the matrix and pads results"))
(defgeneric mreverse (m)
(:documentation "Reverts elements of matrix or vector. Similar to cl:reverse"))
More information about the lisplab-cvs
mailing list