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 / matrix-classes.lisp
blob3c3ec7182b9dd310f612eb85591fe12a38869fd8
2 (in-package :clem)
4 ;;; taken from KMR's clsql package
5 (declaim (inline delistify))
6 (defun delistify (list)
7 "Some MOPs, like openmcl 0.14.2, cons attribute values in a list."
8 (if (and (listp list) (null (cdr list)))
9 (car list)
10 list))
12 (defmacro defmatrixclass (type direct-superclasses &key
13 (element-type)
14 (accumulator-type)
15 (initial-element)
16 minval maxval
17 (val-format))
18 (unless direct-superclasses (setf direct-superclasses '(matrix)))
19 `(progn
20 (defclass ,type ,direct-superclasses
21 ((initial-element :accessor initial-element
22 :initarg :initial-element :initform ,initial-element))
23 (:metaclass standard-matrix-class)
24 ,@(when element-type `((:element-type ,(delistify element-type))))
25 ,@(when accumulator-type `((:accumulator-type ,(delistify accumulator-type))))
26 ,@(when val-format `((:val-format ,(delistify val-format))))
27 ,@(when minval `((:minval ,(if (symbolp minval) (symbol-value minval) minval))))
28 ,@(when maxval `((:maxval ,(if (symbolp maxval) (symbol-value minval) maxval)))))))
30 (defmatrixclass t-matrix ()
31 :element-type t
32 :accumulator-type t)
34 (defmatrixclass number-matrix (t-matrix)
35 :element-type number
36 :accumulator-type number)
38 (defmatrixclass real-matrix (number-matrix)
39 :element-type real
40 :accumulator-type real)
42 (defmatrixclass complex-matrix (number-matrix)
43 :element-type complex
44 :accumulator-type complex)
46 (defmatrixclass float-matrix (real-matrix)
47 :element-type float
48 :accumulator-type float
49 :val-format "~4,9F")
51 (defmatrixclass integer-matrix (real-matrix)
52 :element-type integer
53 :accumulator-type integer
54 :val-format "~d")
56 (defmatrixclass unsigned-byte-matrix (integer-matrix)
57 :element-type (unsigned-byte *)
58 :accumulator-type (unsigned-byte *)
59 :val-format "~d")
61 (defmatrixclass bit-matrix (integer-matrix) :element-type (unsigned-byte 1)
62 :accumulator-type (signed-byte 32)
63 :minval 0
64 :maxval 1
65 :val-format "~b")
67 (defmatrixclass ub8-matrix (unsigned-byte-matrix)
68 :element-type (unsigned-byte 8)
69 :accumulator-type (unsigned-byte 32)
70 :minval 0
71 :maxval #.(- (expt 2 8) 1))
73 (defmatrixclass ub16-matrix (unsigned-byte-matrix)
74 :element-type (unsigned-byte 16)
75 :accumulator-type (unsigned-byte 32)
76 :minval 0
77 :maxval #.(- (expt 2 16) 1))
79 (defmatrixclass ub32-matrix (unsigned-byte-matrix)
80 :element-type (unsigned-byte 32)
81 :accumulator-type (unsigned-byte 32)
82 :minval 0
83 :maxval #.(- (expt 2 32) 1))
85 (defmatrixclass sb8-matrix (integer-matrix)
86 :element-type (signed-byte 8)
87 :accumulator-type (signed-byte 32)
88 :minval #.(- (expt 2 7))
89 :maxval #.(- (expt 2 7) 1))
91 (defmatrixclass sb16-matrix (integer-matrix)
92 :element-type (signed-byte 16)
93 :accumulator-type (signed-byte 32)
94 :minval #.(- (expt 2 15))
95 :maxval #.(- (expt 2 15) 1))
97 (defmatrixclass sb32-matrix (integer-matrix)
98 :element-type (signed-byte 32)
99 :accumulator-type (signed-byte 32)
100 :minval #.(- (expt 2 31))
101 :maxval #.(- (expt 2 31) 1))
103 (defmatrixclass fixnum-matrix (integer-matrix)
104 :element-type fixnum
105 :accumulator-type (unsigned-byte 32)
106 :minval most-negative-fixnum
107 :maxval most-positive-fixnum)
109 (defmatrixclass single-float-matrix (float-matrix)
110 :element-type single-float
111 :accumulator-type single-float
112 :initial-element 0f0
113 :minval most-negative-single-float
114 :maxval most-positive-single-float)
116 (defmatrixclass double-float-matrix (float-matrix)
117 :element-type double-float
118 :accumulator-type double-float
119 :initial-element 0d0
120 :minval most-negative-double-float
121 :maxval most-positive-double-float)