-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlapack.ijt
More file actions
168 lines (133 loc) · 5.56 KB
/
lapack.ijt
File metadata and controls
168 lines (133 loc) · 5.56 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
LABTITLE=: 'LAPACK'
LABDEPENDS=: 'math/lapack'
NB. =========================================================
Lab Section LAPACK
LAPACK (Linear Algebra Package) is a set of routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems.
The associated matrix factorizations, LU, Cholesky, QR, SVD, Schur, generalized Schur, are also provided, as are related computations such as reordering of the Schur factorizations and estimating condition numbers.
)
NB. =========================================================
Lab Section
The LAPACK routines are accessed through the dll call mechanism as documented in User Manual chapter "Dlls and Memory Management".
)
NB. =========================================================
Lab Section
All definitions for LAPACK are in locale jlapack.
The scripts and other files for LAPACK are in directory:
)
jpath '~addons/math/lapack'
NB. =========================================================
Lab Section
The first step in using LAPACK is to load the lapack.ijs script to define the jlapack locale.
)
load 'math/lapack'
NB. =========================================================
Lab Section
There are hundreds of LAPACK routines but you only load interfaces for the ones you need. The interface is defined in a script with the name of the routine.
geev is a LAPACK routine for computing eigenvalues of a real or complex matrix.
If you want to use geev you need to load the geev script to make the necessary definitions in the jlapack locale.
)
load 'math/lapack/geev'
NB. =========================================================
Lab Section
)
m=: ?4 4$100
geev_jlapack_ m NB. compute eigenvalues and eigenvectors
NB. =========================================================
Lab Section
)
>1{geev_jlapack_ m NB. just the eigenvalues
NB. =========================================================
Lab Section
If you are going to be using geev a lot, you could define it in the base locale so that you do not have to use the full name.
)
geev=: geev_jlapack_
>1{geev m
NB. =========================================================
Lab Section
The LAPACK routines are documented in the doc subdirectory with a file with the same name, but a "lap" suffix.
This documentation is directly from the LAPACK library and is for both the mathematician and the programmer. Unfortunately the programmer is assumed to be a Fortran programmer. This means you will have to put in some extra effort to understand the programming interface details.
docs_jlapack_ shows a window with a list of the lap files.
)
PREPARE
3 : 0''
if. 0 e. $ 1!:0 <jpath '~addons/math/lapack/doc' do.
smoutput 'Note: on this machine, the LAPACK documentation has not'
smoutput 'been found in the doc subdirectory.'
end.
)
PREPARE
NB. =========================================================
Lab Section
)
docs_jlapack_ '' NB. display list of lap files
NB. =========================================================
Lab Section
)
load 'math/lapack/geev'
>1{geev_jlapack_ 1j3+m NB. eigenvalues of complex array
NB. =========================================================
Lab Section
gesvd computes the singular value decomposition (SVD) and left and right singular vectors of a real or complex matrix,
)
load 'math/lapack/gesvd'
gesvd_jlapack_ m NB. SVD
NB. =========================================================
Lab Section
The LAPACK routines are quite fast. For example:
)
PREPARE
3 : 0''
smoutput ' mat=: ?100 100$1000'
mat__=: ?100 100$1000
)
PREPARE
time=: 6!:2
NB. time in seconds to compute SVD:
time 'gesvd_jlapack_ mat'
NB. =========================================================
Lab Section
)
load 'math/lapack/potrf'
mp=: +/ . *
potrf_jlapack_ m mp |: m NB. Cholesky decomposition
NB. =========================================================
Lab Section
)
load 'math/lapack/geqrf'
geqrf_jlapack_ m NB. QR factorization
NB. =========================================================
Lab Section
)
load 'math/lapack/gesv'
m1=: ?.4 3$30
gesv_jlapack_ m;m1 NB. solves m * x = m1
NB. =========================================================
Lab Section
)
load 'math/lapack/getrf'
getrf_jlapack_ m NB. LU decomposition
NB. =========================================================
Lab Section
routines_jlapack_ lists all the scripts in the lapack directory.
)
NB. =========================================================
Lab Section
)
routines_jlapack_ ''
NB. =========================================================
Lab Section
As you can see, interfaces are defined for only a few LAPACK routines.
Compare the list of available routines in docs_jlapack_ with the list of implemented interfaces in routines_jlapack_ .
With a little effort you should be able to add an interface for the LAPACK routine you require. You need to study the lap documentation for interfaces already provided, and by following the pattern in their interfaces, write a script for the interface you want.
If you write LAPACK interfaces, please send them to us so they can be included in the package.
)
NB. =========================================================
Lab Section
The calculation of eigenvalues using LAPACK is an integral part of the math/eigenpic demo. This shows the action of a matrix on unit vectors, and highlight the eigenvalues, which appear as a scaling factor times the eigenvectors.
Install the math/eigenpic package, and load as:
load 'math/eigenpic'
)
NB. =========================================================
Lab Section
For more information on LAPACK: http://www.netlib.org
)