;;; Lisplab, level1-dge.lisp ;;; General, double-float 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) ;;; Double float general classes (defclass matrix-base-dge (structure-general vector-d implementation-base) ()) (defmethod initialize-instance :after ((m matrix-base-dge) &key dim (value 0)) (with-slots (rows cols size store) m (setf rows (car dim) cols (cadr dim) size (* rows cols)) (unless store (setf store (allocate-real-store size value))))) (defclass matrix-lisp-dge (implementation-lisp matrix-base-dge) () (:documentation "A full matrix (rows x cols) with double float elements. Executes in lisp only.")) (defclass matrix-foreign-dge (implementation-foreign matrix-lisp-dge) () (:documentation "A full matrix (rows x cols) with double float matrix elements. Executes in FFI if possible. If not it executes in lisp.")) (defclass matrix-dge (matrix-foreign-dge) () (:documentation "A full matrix (rows x cols) with double float matrix elements. Executes in FFI if possible. If not it executes in lisp.")) (defmethod make-matrix-class ((a (eql :d)) (b (eql :ge)) (c (eql :base))) (find-class 'matrix-base-dge)) (defmethod make-matrix-class ((a (eql :d)) (b (eql :ge)) (c (eql :lisp))) (find-class 'matrix-lisp-dge)) (defmethod make-matrix-class ((a (eql :d)) (b (eql :ge)) (c (eql :foreign))) (find-class 'matrix-dge)) (defmethod make-matrix-class ((a (eql :d)) (b (eql :ge)) (c (eql :any))) (find-class 'matrix-dge)) ;;; All leve1 methods spcialized for dge (defmethod print-object ((matrix matrix-base-dge) stream) (if (not *lisplab-print-size*) (call-next-method) (progn (format stream "~&#md(" ) (print-matrix-contents matrix :stream stream :pr (if *lisplab-element-printer* *lisplab-element-printer* (lambda (x stream) (format stream "~10,4g" x))) :rmax (if (eq *lisplab-print-size* t) (rows matrix) *lisplab-print-size*) :cmax (if (eq *lisplab-print-size* t) (cols matrix) *lisplab-print-size*) :indent 4 :braket-p t) (format stream ")" )))) (defmethod mref ((matrix matrix-base-dge) row col) (ref-blas-real-store (slot-value matrix 'store) row col (slot-value matrix 'rows))) (defmethod (setf mref) (value (matrix matrix-base-dge) row col) (let ((val2 (coerce value 'double-float))) (declare (type double-float val2)) (setf (ref-blas-real-store (slot-value matrix 'store) row col (slot-value matrix 'rows)) val2) val2))