-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
132 lines (104 loc) · 4.99 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
More bogus changes.
Common-Lisp Egregious Matrices (CLEM)
This is Cyrus Harmon's matrix package for common-lisp. Documentation
should one day be found in doc/index.html.
Background
This was going to be called Common-Lisp Efficient Matrices (CLEM), but
since efficiency is relative, I've decided to back off of that claim
and call it Common-Lisp Egregious Matrices. It is a goal of the
project that one day the intended meaning of egregious in this context
will evolve from the "outstandingly bad" meaning to the "remarkably
good" sense. Unfortunately, we're probably closer to outstandingly bad
at this point.
Why are the matrices egregious?
Well, the main problem is a lack of efficeincy. Through relatively
profuse use of declarations, many of the main matrix operations are
efficient in the lisp-sense in that they are non-consing. It does not,
however, mean that they are particularly fast. This package has only
been tested on SBCL and SBCL's floating point performance is at least
decent. In theory, further tuning of the lisp matrix code and perhaps
the output of the compiler may help increase the performance here. As
it stands, matrix multiplication is an order of magnitude (base 10)
slower here than in BLAS. This performance is actually reasonably good
for a high-level language, in my opinion, and can hopefully be
improved upon. As informal benchmarks for comparison, I used BLAS and
a slightly hand-tuned matrix multiply written in C. Interestingly, I
could make the C version run about three times faster than the lisp
version, while the BLAS matrix multiply was another 3x faster than
that, yielding a roughly 10x speedup for BLAS relative to the CLEM
matrix multiply. It seems as though the performance hit is largely a
memory-access penalty. (Oh, I'll undoubtedly mention this again, but
at the moment this has only been tested on SBCL on PPC. It would be
interesting to see what the results on other processor families are,
but I would imagine they would be fairly similar.) Smarter memory
access patterns through the matrices to be multiplied and to
accumulate the results may help performance here.
But clearly there is more to life than matrix multiplication. One of
the goals of building this package in lisp is to get access to the
nice features of high-level languages. It's all well and good to write
matrix-intensive code in fortran, but I really wouldn't to write code
for interacting with databases, or for processing XML documents or for
serving web-applications in fortran. I hope that CLEM can be used in
contexts such as these.
Why not just use Matlab or R?
This is a very good question. First and foremost, I like the features
of the lisp language and miss them greatly when I go into those
environments. The editing and debugging tools of a modern common lisp
(Emacs/SLIME today and perhaps CLIMACS/SLIME in the not-too-distant
future) are a major win in my eyes. Yes, there are amazing libraries
for doing just about everything under the sun in both Matlab and R,
but they strike me as less-good for general purpose computing than
common lisp. These really should be treated as the pros and cons for
each are in fact quite different.
Matlab
One major problem with Matlab is the licensing model. Ensuring that
Matlab is on every computer to run Matlab software is quite
annoying. A second problem is that the language, while very nice for
building quick and dirty scripts and prototypes, doesn't seem to be
nearly as nice for building large systems as common lisp. More on this
later.
R
R is great, but it's interpreted language leads to performance
problems. It is true that the core math routines in general are
implemented in fast fortran down "under the covers", but for
higher-level processing, one is stuck with a mediocre interpreted
language. It's true that the R language is essentially a scheme
variant, but it is a scheme variant with a C-like syntax on top that,
in my opinion, leaves much to be desired in comparison with common
lisp.
What about Matlisp?
Yes, matlisp is very nice and interfaces with fortran libraries for
fast math performance. In fact, I have started working on tying CLEM
into matlisp. This will probably be more important for floating point
and complex matrices than for integer matrices. Integer matrices are
important to me as one of the main data types I will be working with
are images, so I wanted an efficient package for dealing with integer
matrices.
Anyway, we'll see if this ever proves to be useful. In the meantime,
it has been a fun exercise in trying to build a lisp-based system for
matrix math.
What does CLEM do?
Typed methods for matrix math
* mat-add
* mat-subtr
* mat-mult
* mat-mult-block (to replace mat-mult when fully debugged)
* mat-hprod (hadamard product (C_ij = A_ij * B_ij for all i,j))
* scalar-mult
* scalar-divide
* sum
* sum-range
* max-val
* min-val
Matrix type conversions
Convolution
Morphological Operations
* gaussian-blur
* dilate
* erode
Derivatives
* x-derivative
* y-derivative
* gradmag
Examples
Check out test for now. Hope to have more of this in the near future.