[lisplab-cvs] r103 - src/matrix
Jørn Inge Vestgården
jivestgarden at common-lisp.net
Fri Oct 16 18:53:31 UTC 2009
Author: jivestgarden
Date: Fri Oct 16 14:53:31 2009
New Revision: 103
Log:
minor fixes
Modified:
src/matrix/level1-sparse.lisp
Modified: src/matrix/level1-sparse.lisp
==============================================================================
--- src/matrix/level1-sparse.lisp (original)
+++ src/matrix/level1-sparse.lisp Fri Oct 16 14:53:31 2009
@@ -17,10 +17,10 @@
;;; with this program; if not, write to the Free Software Foundation, Inc.,
;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-;;; Note that there is probably not much to save using this on most operations
+;;; Purpose of the sparse matrices is to save space.
+;;; Currently you won't save much time on most operations
;;; since they by default go through all elements.
-
(in-package :lisplab)
(defclass matrix-sparse
@@ -39,11 +39,13 @@
(with-slots (rows cols size hash-store default-element ) m
(setf size (* rows cols))
(unless hash-store
- (setf hash-store (make-hash-table :test 'eq)))
+ ;; Uses eq as test. It should be safe since the keys are matrix indices
+ ;; and they should be fixnum (or fixnum size) on most platforms.
+ (setf hash-store (make-hash-table :test 'eq)))
(unless default-element
(setf default-element value))))
-;;; Add clases to the description system
+;;; Adds classes to the description system
(add-matrix-class 'matrix-sparse :any :sparse :any)
(defmethod mref ((matrix matrix-sparse) row col)
@@ -55,9 +57,11 @@
(slot-value matrix 'default-element))))
(defmethod (setf mref) (value (matrix matrix-sparse) row col)
- (setf (gethash (column-major-idx row col (slot-value matrix 'rows))
- (slot-value matrix 'hash-store))
- value))
+ (if (eql value (slot-value matrix 'default-element))
+ value
+ (setf (gethash (column-major-idx row col (slot-value matrix 'rows))
+ (slot-value matrix 'hash-store))
+ value)))
(defmethod vref ((matrix matrix-sparse) idx)
(multiple-value-bind (val ok)
More information about the lisplab-cvs
mailing list