clem 0.4.1, ch-asdf 0.2.8, ch-util 0.2.2, lift 1.3.1, darcs ignored, smarkup 0.3.3
[CommonLispStat.git] / external / clem / src / defmatrix-types.lisp
blob78c7569f09f0bc6de472f44a3ce58a9bb7adfb32
1 ;;; defmatrix-types.lisp
2 ;;;
3 ;;; Copyright (c) 2004-2006 Cyrus Harmon (ch-lisp@bobobeach.com)
4 ;;; All rights reserved.
5 ;;;
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
9 ;;;
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12 ;;;
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
17 ;;;
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ;;;
31 (in-package :clem)
33 (defmatrixfuncs t-matrix
34 :element-type t
35 :accumulator-type t)
37 (defmatrixfuncs number-matrix
38 :element-type number
39 :accumulator-type number)
41 (defmatrixfuncs real-matrix
42 :element-type real
43 :accumulator-type real)
45 (defmatrixfuncs complex-matrix
46 :element-type complex
47 :accumulator-type complex)
49 (defmatrixfuncs float-matrix
50 :element-type float
51 :accumulator-type float)
53 (defmatrixfuncs unsigned-byte-matrix
54 :element-type unsigned-byte
55 :accumulator-type unsigned-byte)
57 (defmatrixfuncs integer-matrix
58 :element-type integer
59 :accumulator-type integer)
61 (defmatrixfuncs bit-matrix
62 :element-type (unsigned-byte 1)
63 :accumulator-type (signed-byte 32)
64 :minval 0
65 :maxval 1)
67 (defmatrixfuncs sb8-matrix
68 :element-type (signed-byte 8)
69 :accumulator-type (signed-byte 32)
70 :minval #.(- (expt 2 7))
71 :maxval #.(- (expt 2 7) 1))
73 (defmatrixfuncs ub8-matrix
74 :element-type (unsigned-byte 8)
75 :accumulator-type (unsigned-byte 32)
76 :minval 0
77 :maxval #.(- (expt 2 8) 1))
79 (defmatrixfuncs sb16-matrix
80 :element-type (signed-byte 16)
81 :accumulator-type (signed-byte 32)
82 :minval #.(- (expt 2 15))
83 :maxval #.(- (expt 2 15) 1))
85 (defmatrixfuncs ub16-matrix
86 :element-type (unsigned-byte 16)
87 :accumulator-type (unsigned-byte 32)
88 :minval 0
89 :maxval #.(- (expt 2 16) 1))
91 (defmatrixfuncs sb32-matrix
92 :element-type (signed-byte 32)
93 :accumulator-type (signed-byte 32)
94 :minval #.(- (expt 2 31))
95 :maxval #.(- (expt 2 31) 1))
97 (defmatrixfuncs ub32-matrix
98 :element-type (unsigned-byte 32)
99 :accumulator-type (unsigned-byte 32)
100 :minval 0
101 :maxval #.(- (expt 2 32) 1))
103 (defmatrixfuncs fixnum-matrix
104 :element-type fixnum
105 :accumulator-type (unsigned-byte 32)
106 :minval most-negative-fixnum
107 :maxval most-positive-fixnum)
109 (defmatrixfuncs single-float-matrix
110 :element-type single-float
111 :accumulator-type single-float
112 :minval most-negative-single-float
113 :maxval most-positive-single-float)
115 (defmatrixfuncs double-float-matrix
116 :element-type double-float
117 :accumulator-type double-float
118 :minval most-negative-double-float
119 :maxval most-positive-double-float)
121 (defparameter *typed-matrix-types*
122 '((double-float-matrix double-float "double-float")
123 (single-float-matrix single-float "single-float")
124 (fixnum-matrix fixnum "fixnum")
125 (sb8-matrix (signed-byte 8) "sb8")
126 (sb16-matrix (signed-byte 16) "sb16")
127 (sb32-matrix (signed-byte 32) "sb32")
128 (ub8-matrix (unsigned-byte 8) "ub8")
129 (ub16-matrix (unsigned-byte 16) "ub16")
130 (ub32-matrix (unsigned-byte 32) "ub32")
131 (bit-matrix (unsigned-byte 1) "bit")))
133 (defparameter *typed-matrix-types-hash* (make-hash-table :test 'equal))
134 (defparameter *typed-matrix-names-hash* (make-hash-table :test 'equal))
136 (mapc #'(lambda (l)
137 (destructuring-bind (matrix-type element-type type-name) l
138 ;;; (print (list matrix-type element-type type-name))
139 (setf (gethash element-type *typed-matrix-types-hash*) matrix-type)
140 (setf (gethash element-type *typed-matrix-names-hash*) type-name)))
141 *typed-matrix-types*)
143 (defun get-matrix-type-for-type (type)
144 (gethash type *typed-matrix-types-hash*))
146 (defun get-matrix-name-for-type (type)
147 (gethash type *typed-matrix-names-hash*))