;;; Lisplab, level1-ub8.lisp ;;; General, unsigned-byte 1 matrices ;;; Copyright (C) 2012 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-ub1 (structure-general vector-ub1 implementation-base) () (:documentation "Matrix (rows x cols) with unsigned-byte 1.")) (defmethod initialize-instance :after ((m matrix-ub1) &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-ub1-store size value))))) (defmethod make-matrix-class ((a (eql :ub1)) (b (eql :ge)) (c (eql :any))) (find-class 'matrix-ub1)) ;;; All leve1 methods spcialized for dge (defmethod mref ((matrix matrix-ub1) row col) (ref-ub1-store (slot-value matrix 'store) row col (slot-value matrix 'rows))) (defmethod (setf mref) (value (matrix matrix-ub1) row col) (let ((val2 (mod value 2))) (declare (type (unsigned-byte 1) val2)) (setf (ref-ub1-store (slot-value matrix 'store) row col (slot-value matrix 'rows)) val2) val2)) (defmethod print-object ((matrix matrix-ub1) stream) (if (not *lisplab-print-size*) (call-next-method) (progn (format stream "~&#mub1(" ) (print-matrix-contents matrix :stream stream :pr (if *lisplab-element-printer* *lisplab-element-printer* (lambda (x stream) (format stream "~1d" 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 6 :braket-p t) (format stream ")" ))))