5164
|
1 @c Copyright (C) 2004, 2005 David Bateman |
|
2 @c This is part of the Octave manual. |
|
3 @c For copying conditions, see the file gpl.texi. |
|
4 |
|
5 @node Sparse Matrices |
|
6 @chapter Sparse Matrices |
|
7 |
|
8 @menu |
|
9 * Basics:: The Creation and Manipulation of Sparse Matrices |
|
10 * Graph Theory:: Graphs are their use with Sparse Matrices |
|
11 * Sparse Linear Algebra:: Linear Algebra on Sparse Matrices |
|
12 * Iterative Techniques:: Iterative Techniques applied to Sparse Matrices |
|
13 * Oct-Files:: Using Sparse Matrices in Oct-files |
|
14 * Function Reference:: Documentation from the Specific Sparse Functions |
|
15 @end menu |
|
16 |
|
17 @node Basics, Graph Theory, Sparse Matrices, Sparse Matrices |
|
18 @section The Creation and Manipulation of Sparse Matrices |
|
19 |
|
20 The size of mathematical problems that can be treated at any particular |
|
21 time is generally limited by the available computing resources. Both, |
|
22 the speed of the computer and its available memory place limitation on |
|
23 the problem size. |
|
24 |
5506
|
25 There are many classes of mathematical problems which give rise to |
5164
|
26 matrices, where a large number of the elements are zero. In this case |
|
27 it makes sense to have a special matrix type to handle this class of |
|
28 problems where only the non-zero elements of the matrix are |
5506
|
29 stored. Not only does this reduce the amount of memory to store the |
5164
|
30 matrix, but it also means that operations on this type of matrix can |
|
31 take advantage of the a-priori knowledge of the positions of the |
|
32 non-zero elements to accelerate their calculations. |
|
33 |
|
34 A matrix type that stores only the non-zero elements is generally called |
|
35 sparse. It is the purpose of this document to discuss the basics of the |
|
36 storage and creation of sparse matrices and the fundamental operations |
|
37 on them. |
|
38 |
|
39 THIS DOCUMENT STILL HAS LARGE BLANKS. PLEASE FILL THEM IN. LOOK FOR |
|
40 THE TAG "WRITE ME" |
|
41 |
|
42 @menu |
|
43 * Storage:: Storage of Sparse Matrices |
|
44 * Creation:: Creating Sparse Matrices |
|
45 * Operators and Functions:: Basic Operators and Functions on Sparse Matrices |
|
46 * Information:: Finding out Information about Sparse Matrices |
|
47 @end menu |
|
48 |
|
49 @node Storage, Creation, Basics, Basics |
|
50 @subsection Storage of Sparse Matrices |
|
51 |
|
52 It is not strictly speaking necessary for the user to understand how |
|
53 sparse matrices are stored. However, such an understanding will help |
|
54 to get an understanding of the size of sparse matrices. Understanding |
|
55 the storage technique is also necessary for those users wishing to |
|
56 create their own oct-files. |
|
57 |
|
58 There are many different means of storing sparse matrix data. What all |
|
59 of the methods have in common is that they attempt to reduce the compelxity |
|
60 and storage given a-priori knowledge of the particular class of problems |
|
61 that will be solved. A good summary of the available techniques for storing |
|
62 sparse matrix is given by Saad @footnote{Youcef Saad "SPARSKIT: A basic toolkit |
|
63 for sparse matrix computation", 1994, |
|
64 @url{ftp://ftp.cs.umn.edu/dept/sparse/SPARSKIT2/DOC/paper.ps}}. |
|
65 With full matrices, knowledge of the point of an element of the matrix |
|
66 within the matrix is implied by its position in the computers memory. |
|
67 However, this is not the case for sparse matrices, and so the positions |
|
68 of the non-zero elements of the matrix must equally be stored. |
|
69 |
|
70 An obvious way to do this is by storing the elements of the matrix as |
5506
|
71 triplets, with two elements being their position in the array |
5164
|
72 (rows and column) and the third being the data itself. This is conceptually |
|
73 easy to grasp, but requires more storage than is strictly needed. |
|
74 |
5324
|
75 The storage technique used within Octave is compressed column |
5164
|
76 format. In this format the position of each element in a row and the |
|
77 data are stored as previously. However, if we assume that all elements |
|
78 in the same column are stored adjacent in the computers memory, then |
|
79 we only need to store information on the number of non-zero elements |
|
80 in each column, rather than their positions. Thus assuming that the |
|
81 matrix has more non-zero elements than there are columns in the |
|
82 matrix, we win in terms of the amount of memory used. |
|
83 |
|
84 In fact, the column index contains one more element than the number of |
|
85 columns, with the first element always being zero. The advantage of |
|
86 this is a simplication in the code, in that their is no special case |
|
87 for the first or last columns. A short example, demonstrating this in |
|
88 C is. |
|
89 |
|
90 @example |
|
91 for (j = 0; j < nc; j++) |
|
92 for (i = cidx (j); i < cidx(j+1); i++) |
|
93 printf ("non-zero element (%i,%i) is %d\n", ridx(i), j, data(i)); |
|
94 @end example |
|
95 |
|
96 A clear understanding might be had by considering an example of how the |
|
97 above applies to an example matrix. Consider the matrix |
|
98 |
|
99 @example |
|
100 @group |
|
101 1 2 0 0 |
|
102 0 0 0 3 |
|
103 0 0 0 4 |
|
104 @end group |
|
105 @end example |
|
106 |
|
107 The non-zero elements of this matrix are |
|
108 |
|
109 @example |
|
110 @group |
|
111 (1, 1) @result{} 1 |
|
112 (1, 2) @result{} 2 |
|
113 (2, 4) @result{} 3 |
|
114 (3, 4) @result{} 4 |
|
115 @end group |
|
116 @end example |
|
117 |
|
118 This will be stored as three vectors @var{cidx}, @var{ridx} and @var{data}, |
|
119 representing the column indexing, row indexing and data respectively. The |
|
120 contents of these three vectors for the above matrix will be |
|
121 |
|
122 @example |
|
123 @group |
5506
|
124 @var{cidx} = [0, 1, 2, 2, 4] |
5164
|
125 @var{ridx} = [0, 0, 1, 2] |
|
126 @var{data} = [1, 2, 3, 4] |
|
127 @end group |
|
128 @end example |
|
129 |
|
130 Note that this is the representation of these elements with the first row |
5506
|
131 and column assumed to start at zero. Thus the number of elements in the |
5164
|
132 @var{i}-th column is given by @code{@var{cidx} (@var{i} + 1) - |
|
133 @var{cidx} (@var{i})}. |
|
134 |
|
135 It should be noted that compressed row formats are equally possible. However, |
|
136 in the context of mixed operations between mixed sparse and dense matrices, |
|
137 it makes sense that the elements of the sparse matrices are in the same |
5324
|
138 order as the dense matrices. Octave stores dense matrices in column |
5164
|
139 major ordering, and so sparse matrices are equally stored in this manner. |
|
140 |
5324
|
141 A further constraint on the sparse matrix storage used by Octave is that |
5164
|
142 all elements in the rows are stored in increasing order of their row |
5506
|
143 index, which makes certain operations faster. However, it imposes |
5164
|
144 the need to sort the elements on the creation of sparse matrices. Having |
|
145 dis-ordered elements is potentially an advantage in that it makes operations |
|
146 such as concatenating two sparse matrices together easier and faster, however |
|
147 it adds complexity and speed problems elsewhere. |
|
148 |
|
149 @node Creation, Operators and Functions, Storage, Basics |
|
150 @subsection Creating Sparse Matrices |
|
151 |
|
152 There are several means to create sparse matrix. |
|
153 |
|
154 @table @asis |
|
155 @item Returned from a function |
|
156 There are many functions that directly return sparse matrices. These include |
|
157 @dfn{speye}, @dfn{sprand}, @dfn{spdiag}, etc. |
|
158 @item Constructed from matrices or vectors |
|
159 The function @dfn{sparse} allows a sparse matrix to be constructed from |
5506
|
160 three vectors representing the row, column and data. Alternatively, the |
5164
|
161 function @dfn{spconvert} uses a three column matrix format to allow easy |
|
162 importation of data from elsewhere. |
|
163 @item Created and then filled |
|
164 The function @dfn{sparse} or @dfn{spalloc} can be used to create an empty |
|
165 matrix that is then filled by the user |
|
166 @item From a user binary program |
|
167 The user can directly create the sparse matrix within an oct-file. |
|
168 @end table |
|
169 |
|
170 There are several basic functions to return specific sparse |
|
171 matrices. For example the sparse identity matrix, is a matrix that is |
|
172 often needed. It therefore has its own function to create it as |
|
173 @code{speye (@var{n})} or @code{speye (@var{r}, @var{c})}, which |
|
174 creates an @var{n}-by-@var{n} or @var{r}-by-@var{c} sparse identity |
|
175 matrix. |
|
176 |
|
177 Another typical sparse matrix that is often needed is a random distribution |
|
178 of random elements. The functions @dfn{sprand} and @dfn{sprandn} perform |
5506
|
179 this for uniform and normal random distributions of elements. They have exactly |
|
180 the same calling convention, where @code{sprand (@var{r}, @var{c}, @var{d})}, |
|
181 creates an @var{r}-by-@var{c} sparse matrix with a density of filled |
5164
|
182 elements of @var{d}. |
|
183 |
5506
|
184 Other functions of interest that directly creates a sparse matrices, are |
5164
|
185 @dfn{spdiag} or its generalization @dfn{spdiags}, that can take the |
|
186 definition of the diagonals of the matrix and create the sparse matrix |
|
187 that corresponds to this. For example |
|
188 |
|
189 @example |
5506
|
190 s = diag (sparse(randn(1,n)), -1); |
5164
|
191 @end example |
|
192 |
|
193 creates a sparse (@var{n}+1)-by-(@var{n}+1) sparse matrix with a single |
|
194 diagonal defined. |
|
195 |
|
196 The recommended way for the user to create a sparse matrix, is to create |
|
197 two vectors contain the row and column index of the data and a third |
|
198 vector of the same size containing the data to be stored. For example |
|
199 |
|
200 @example |
|
201 function x = foo (r, j) |
|
202 idx = randperm (r); |
|
203 x = ([zeros(r-2,1); rand(2,1)])(idx); |
|
204 endfunction |
|
205 |
|
206 ri = []; |
|
207 ci = []; |
|
208 d = []; |
|
209 |
|
210 for j=1:c |
|
211 dtmp = foo (r, j); # Returns vector of length r with (:,j) values |
|
212 idx = find (dtmp != 0.); |
|
213 ri = [ri; idx]; |
|
214 ci = [ci; j*ones(length(idx),1)]; |
|
215 d = [d; dtmp(idx)]; |
|
216 endfor |
|
217 s = sparse (ri, ci, d, r, c); |
|
218 @end example |
|
219 |
|
220 creates an @var{r}-by-@var{c} sparse matrix with a random distribution of |
|
221 2 elements per row. The elements of the vectors do not need to be sorted in |
5506
|
222 any particular order as Octave will sort them prior to storing the |
|
223 data. However, pre-sorting the data will make the creation of the sparse |
5164
|
224 matrix faster. |
|
225 |
|
226 The function @dfn{spconvert} takes a three or four column real matrix. |
|
227 The first two columns represent the row and column index respectively and |
|
228 the third and four columns, the real and imaginary parts of the sparse |
|
229 matrix. The matrix can contain zero elements and the elements can be |
|
230 sorted in any order. Adding zero elements is a convenient way to define |
|
231 the size of the sparse matrix. For example |
|
232 |
|
233 @example |
|
234 s = spconvert ([1 2 3 4; 1 3 4 4; 1 2 3 0]') |
|
235 @result{} Compressed Column Sparse (rows=4, cols=4, nnz=3) |
|
236 (1 , 1) -> 1 |
|
237 (2 , 3) -> 2 |
|
238 (3 , 4) -> 3 |
|
239 @end example |
|
240 |
|
241 An example of creating and filling a matrix might be |
|
242 |
|
243 @example |
|
244 k = 5; |
|
245 nz = r * k; |
|
246 s = spalloc (r, c, nz) |
|
247 for j = 1:c |
|
248 idx = randperm (r); |
|
249 s (:, j) = [zeros(r - k, 1); rand(k, 1)] (idx); |
|
250 endfor |
|
251 @end example |
|
252 |
5324
|
253 It should be noted, that due to the way that the Octave |
5164
|
254 assignment functions are written that the assignment will reallocate |
5506
|
255 the memory used by the sparse matrix at each iteration of the above loop. |
|
256 Therefore the @dfn{spalloc} function ignores the @var{nz} argument and |
|
257 does not preassign the memory for the matrix. Therefore, it is vitally |
5164
|
258 important that code using to above structure should be as vectorized |
5506
|
259 much as possible to minimize the number of assignments and reduce the |
5164
|
260 number of memory allocations. |
|
261 |
|
262 The above problem can be avoided in oct-files. However, the |
|
263 construction of a sparse matrix from an oct-file is more complex than |
|
264 can be discussed in this brief introduction, and you are referred to |
|
265 section @ref{Oct-Files}, to have a full description of the techniques |
|
266 involved. |
|
267 |
|
268 @node Operators and Functions, Information, Creation, Basics |
|
269 @subsection Basic Operators and Functions on Sparse Matrices |
|
270 |
|
271 @menu |
|
272 * Functions:: Operators and Functions |
|
273 * ReturnType:: The Return Types of Operators and Functions |
|
274 * MathConsiderations:: Mathematical Considerations |
|
275 @end menu |
|
276 |
|
277 @node Functions, ReturnType, Operators and Functions, Operators and Functions |
|
278 @subsubsection Operators and Functions |
|
279 |
|
280 WRITE ME |
|
281 |
|
282 @node ReturnType, MathConsiderations, Functions, Operators and Functions |
|
283 @subsubsection The Return Types of Operators and Functions |
|
284 |
5506
|
285 The two basic reasons to use sparse matrices are to reduce the memory |
5164
|
286 usage and to not have to do calculations on zero elements. The two are |
|
287 closely related in that the computation time on a sparse matrix operator |
5506
|
288 or function is roughly linear with the number of non-zero elements. |
5164
|
289 |
|
290 Therefore, there is a certain density of non-zero elements of a matrix |
|
291 where it no longer makes sense to store it as a sparse matrix, but rather |
|
292 as a full matrix. For this reason operators and functions that have a |
|
293 high probability of returning a full matrix will always return one. For |
|
294 example adding a scalar constant to a sparse matrix will almost always |
|
295 make it a full matrix, and so the example |
|
296 |
|
297 @example |
|
298 speye(3) + 0 |
|
299 @result{} 1 0 0 |
|
300 0 1 0 |
|
301 0 0 1 |
|
302 @end example |
|
303 |
|
304 returns a full matrix as can be seen. Additionally all sparse functions |
|
305 test the amount of memory occupied by the sparse matrix to see if the |
|
306 amount of storage used is larger than the amount used by the full |
|
307 equivalent. Therefore @code{speye (2) * 1} will return a full matrix as |
|
308 the memory used is smaller for the full version than the sparse version. |
|
309 |
|
310 As all of the mixed operators and functions between full and sparse |
|
311 matrices exist, in general this does not cause any problems. However, |
|
312 one area where it does cause a problem is where a sparse matrix is |
|
313 promoted to a full matrix, where subsequent operations would resparsify |
|
314 the matrix. Such cases as rare, but can be artificially created, for |
|
315 example @code{(fliplr(speye(3)) + speye(3)) - speye(3)} gives a full |
|
316 matrix when it should give a sparse one. In general, where such cases |
|
317 occur, they impose only a small memory penalty. |
|
318 |
5324
|
319 There is however one known case where this behaviour of Octave's |
5164
|
320 sparse matrices will cause a problem. That is in the handling of the |
|
321 @dfn{diag} function. Whether @dfn{diag} returns a sparse or full matrix |
|
322 depending on the type of its input arguments. So |
|
323 |
|
324 @example |
|
325 a = diag (sparse([1,2,3]), -1); |
|
326 @end example |
|
327 |
|
328 should return a sparse matrix. To ensure this actually happens, the |
|
329 @dfn{sparse} function, and other functions based on it like @dfn{speye}, |
|
330 always returns a sparse matrix, even if the memory used will be larger |
|
331 than its full representation. |
|
332 |
|
333 @node MathConsiderations, , ReturnType, Operators and Functions |
|
334 @subsubsection Mathematical Considerations |
|
335 |
|
336 The attempt has been made to make sparse matrices behave in exactly the |
|
337 same manner as there full counterparts. However, there are certain differences |
|
338 and especially differences with other products sparse implementations. |
|
339 |
|
340 Firstly, the "./" and ".^" operators must be used with care. Consider what |
|
341 the examples |
|
342 |
|
343 @example |
|
344 s = speye (4); |
|
345 a1 = s .^ 2; |
|
346 a2 = s .^ s; |
|
347 a3 = s .^ -2; |
|
348 a4 = s ./ 2; |
|
349 a5 = 2 ./ s; |
|
350 a6 = s ./ s; |
|
351 @end example |
|
352 |
|
353 will give. The first example of @var{s} raised to the power of 2 causes |
|
354 no problems. However @var{s} raised element-wise to itself involves a |
|
355 a large number of terms @code{0 .^ 0} which is 1. There @code{@var{s} .^ |
|
356 @var{s}} is a full matrix. |
|
357 |
|
358 Likewise @code{@var{s} .^ -2} involves terms terms like @code{0 .^ -2} which |
|
359 is infinity, and so @code{@var{s} .^ -2} is equally a full matrix. |
|
360 |
|
361 For the "./" operator @code{@var{s} ./ 2} has no problems, but |
|
362 @code{2 ./ @var{s}} involves a large number of infinity terms as well |
|
363 and is equally a full matrix. The case of @code{@var{s} ./ @var{s}} |
|
364 involves terms like @code{0 ./ 0} which is a @code{NaN} and so this |
|
365 is equally a full matrix with the zero elements of @var{s} filled with |
|
366 @code{NaN} values. |
|
367 |
|
368 The above behaviour is consistent with full matrices, but is not |
|
369 consistent with sparse implementations in other products. |
|
370 |
|
371 A particular problem of sparse matrices comes about due to the fact that |
|
372 as the zeros are not stored, the sign-bit of these zeros is equally not |
5506
|
373 stored. In certain cases the sign-bit of zero is important. For example |
5164
|
374 |
|
375 @example |
|
376 a = 0 ./ [-1, 1; 1, -1]; |
|
377 b = 1 ./ a |
|
378 @result{} -Inf Inf |
|
379 Inf -Inf |
|
380 c = 1 ./ sparse (a) |
|
381 @result{} Inf Inf |
|
382 Inf Inf |
|
383 @end example |
|
384 |
|
385 To correct this behaviour would mean that zero elements with a negative |
|
386 sign-bit would need to be stored in the matrix to ensure that their |
|
387 sign-bit was respected. This is not done at this time, for reasons of |
|
388 efficient, and so the user is warned that calculations where the sign-bit |
|
389 of zero is important must not be done using sparse matrices. |
|
390 |
5506
|
391 In general any function or operator used on a sparse matrix will result |
|
392 in a sparse matrix with the same or a larger number of non-zero elements |
|
393 than the original matrix. This is particularly true for the important |
|
394 case of sparse matrix factorizations. |
|
395 |
|
396 |
5164
|
397 Also discuss issues of fill-in. Discuss symamd etc, and mention randperm |
|
398 that is included elsewhere in the docs... |
|
399 |
|
400 WRITE ME |
|
401 |
|
402 @node Information, , Operators and Functions, Basics |
|
403 @subsection Finding out Information about Sparse Matrices |
|
404 |
|
405 Talk about the spy, spstats, nnz, spparms, etc function |
|
406 |
|
407 WRITE ME |
|
408 |
|
409 @node Graph Theory, Sparse Linear Algebra, Basics, Sparse Matrices |
|
410 @section Graphs are their use with Sparse Matrices |
|
411 |
|
412 Someone who knows more about this than me should write this... |
|
413 |
|
414 WRITE ME |
|
415 |
|
416 @node Sparse Linear Algebra, Iterative Techniques, Graph Theory, Sparse Matrices |
|
417 @section Linear Algebra on Sparse Matrices |
|
418 |
5324
|
419 Octave includes a poly-morphic solver for sparse matrices, where |
5164
|
420 the exact solver used to factorize the matrix, depends on the properties |
5506
|
421 of the sparse matrix itself. The cost of determining the matrix type |
5322
|
422 is small relative to the cost of factorizing the matrix itself, but in any |
|
423 case the matrix type is cached once it is calculated, so that it is not |
|
424 re-determined each time it is used in a linear equation. |
5164
|
425 |
|
426 The selection tree for how the linear equation is solve is |
|
427 |
|
428 @enumerate 1 |
|
429 @item If the matrix is not square go to 9. |
|
430 |
|
431 @item If the matrix is diagonal, solve directly and goto 9 |
|
432 |
|
433 @item If the matrix is a permuted diagonal, solve directly taking into |
|
434 account the permutations. Goto 9 |
|
435 |
|
436 @item If the matrix is banded and if the band density is less than that |
|
437 given by @code{spparms ("bandden")} continue, else goto 5. |
|
438 |
|
439 @enumerate a |
|
440 @item If the matrix is tridiagonal and the right-hand side is not sparse |
|
441 continue, else goto 4b. |
|
442 |
|
443 @enumerate |
|
444 @item If the matrix is hermitian, with a positive real diagonal, attempt |
|
445 Cholesky factorization using @sc{Lapack} xPTSV. |
|
446 |
|
447 @item If the above failed or the matrix is not hermitian with a positive |
|
448 real diagonal use Gaussian elimination with pivoting using |
|
449 @sc{Lapack} xGTSV, and goto 9. |
|
450 @end enumerate |
|
451 |
|
452 @item If the matrix is hermitian with a positive real diagonal, attempt |
|
453 Cholesky factorization using @sc{Lapack} xPBTRF. |
|
454 |
|
455 @item if the above failed or the matrix is not hermitian with a positive |
|
456 real diagonal use Gaussian elimination with pivoting using |
|
457 @sc{Lapack} xGBTRF, and goto 9. |
|
458 @end enumerate |
|
459 |
|
460 @item If the matrix is upper or lower triangular perform a sparse forward |
|
461 or backward subsitution, and goto 9 |
|
462 |
5322
|
463 @item If the matrix is a upper triangular matrix with column permutations |
|
464 or lower triangular matrix with row permutations, perform a sparse forward |
|
465 or backward subsitution, and goto 9 |
5164
|
466 |
|
467 @item If the matrix is hermitian with a real positive diagonal, attempt |
5506
|
468 sparse Cholesky factorization using CHOLMOD. |
5164
|
469 |
|
470 @item If the sparse Cholesky factorization failed or the matrix is not |
|
471 hermitian with a real positive diagonal, factorize using UMFPACK. |
|
472 |
|
473 @item If the matrix is not square, or any of the previous solvers flags |
|
474 a singular or near singular matrix, find a minimum norm solution |
|
475 |
|
476 FIXME: QR solvers not yet written. |
|
477 |
|
478 @end enumerate |
|
479 |
|
480 The band density is defined as the number of non-zero values in the matrix |
|
481 divided by the number of non-zero values in the matrix. The banded matrix |
|
482 solvers can be entirely disabled by using @dfn{spparms} to set @code{bandden} |
|
483 to 1 (i.e. @code{spparms ("bandden", 1)}). |
|
484 |
|
485 All of the solvers above, expect the banded solvers, calculate an |
|
486 estimate of the condition number. This can be used to detect numerical |
|
487 stability problems in the solution and force a minimum norm solution |
|
488 to be used. However, for narrow banded matrices, the cost of |
|
489 calculating the condition number is significant, and can in fact exceed |
|
490 the cost of factoring the matrix. Therefore the condition number is |
|
491 not calculated for banded matrices, and therefore unless the factorization |
|
492 is exactly singular, these numerical instabilities won't be detected. |
|
493 In cases where, this might be a problem the user is recommended to disable |
|
494 the banded solvers as above, at a significant cost in terms of speed. |
|
495 |
5322
|
496 The user can force the type of the matrix with the @code{matrix_type} |
|
497 function. This overcomes the cost of discovering the type of the matrix. |
|
498 However, it should be noted incorrectly identifying the type of the matrix |
|
499 will lead to unpredictable results, and so @code{matrix_type} should be |
5506
|
500 used with care. |
5322
|
501 |
5164
|
502 @node Iterative Techniques, Oct-Files, Sparse Linear Algebra, Sparse Matrices |
|
503 @section Iterative Techniques applied to sparse matrices |
|
504 |
|
505 WRITE ME |
|
506 |
5506
|
507 @node Oct-Files, Function Reference, Iterative Techniques, Sparse Matrices |
5164
|
508 @section Using Sparse Matrices in Oct-files |
|
509 |
5324
|
510 An oct-file is a means of writing an Octave function in a compilable |
5164
|
511 language like C++, rather than as a script file. This results in a |
|
512 significant acceleration in the code. It is not the purpose of this |
|
513 section to discuss how to write an oct-file, or discuss what they |
|
514 are. There are already two @footnote{Paul Thomas "Dal Segno al Coda |
|
515 - The octave dynamically linked function cookbook", |
|
516 @url{http://perso.wanadoo.fr/prthomas/intro.html}, and Cristophe Spiel |
|
517 "Del Coda Al Fine - Pushing Octave's Limits", |
|
518 @url{http://octave.sourceforge.net/coda/coda.pdf}} very good |
|
519 references on oct-files themselves. Users who are not familiar with |
|
520 oct-files are urged to read these references to fully understand this |
|
521 chapter. The examples discussed here assume that the oct-file is written |
|
522 entirely in C++. |
|
523 |
|
524 There are three classes of sparse objects that are of interest to the |
|
525 user. |
|
526 |
|
527 @table @asis |
|
528 @item SparseMatrix |
|
529 A double precision sparse matrix class |
|
530 @item SparseComplexMatrix |
|
531 A Complex sparse matrix class |
|
532 @item SparseBoolMatrix |
|
533 A boolen sparse matrix class |
|
534 @end table |
|
535 |
|
536 All of these classes inherit from the @code{Sparse<T>} template class, |
|
537 and so all have similar capabilities and usage. The @code{Sparse<T>} |
5324
|
538 class was based on Octave @code{Array<T>} class, and so users familar |
|
539 with Octave's Array classes will be comfortable with the use of |
5164
|
540 the sparse classes. |
|
541 |
|
542 The sparse classes will not be entirely described in this section, due |
|
543 to their similar with the existing Array classes. However, there are a |
|
544 few differences due the different nature of sparse objects, and these |
|
545 will be described. Firstly, although it is fundamentally possible to |
5324
|
546 have N-dimensional sparse objects, the Octave sparse classes do |
5164
|
547 not allow them at this time. So all operations of the sparse classes |
|
548 must be 2-dimensional. This means that in fact @code{SparseMatrix} is |
5324
|
549 similar to Octave's @code{Matrix} class rather than its |
5164
|
550 @code{NDArray} class. |
|
551 |
|
552 @menu |
|
553 * OctDifferences:: The Differences between the Array and Sparse Classes |
|
554 * OctCreation:: Creating Spare Matrices in Oct-Files |
|
555 * OctUse:: Using Sparse Matrices in Oct-Files |
|
556 @end menu |
|
557 |
|
558 @node OctDifferences, OctCreation, Oct-Files, Oct-Files |
|
559 @subsection The Differences between the Array and Sparse Classes |
|
560 |
|
561 The number of elements in a sparse matrix is considered to be the number |
|
562 of non-zero elements rather than the product of the dimensions. Therefore |
|
563 |
|
564 @example |
|
565 SparseMatrix sm; |
|
566 @dots{} |
|
567 int nel = sm.nelem (); |
|
568 @end example |
|
569 |
|
570 returns the number of non-zero elements. If the user really requires the |
|
571 number of elements in the matrix, including the non-zero elements, they |
|
572 should use @code{numel} rather than @code{nelem}. Note that for very |
|
573 large matrices, where the product of the two dimensions is large that |
|
574 the representation of the an unsigned int, then @code{numel} can overflow. |
|
575 An example is @code{speye(1e6)} which will create a matrix with a million |
|
576 rows and columns, but only a million non-zero elements. Therefore the |
|
577 number of rows by the number of columns in this case is more than two |
|
578 hundred times the maximum value that can be represented by an unsigned int. |
|
579 The use of @code{numel} should therefore be avoided useless it is known |
|
580 it won't overflow. |
|
581 |
|
582 Extreme care must be take with the elem method and the "()" operator, |
|
583 which perform basically the same function. The reason is that if a |
5324
|
584 sparse object is non-const, then Octave will assume that a |
5164
|
585 request for a zero element in a sparse matrix is in fact a request |
|
586 to create this element so it can be filled. Therefore a piece of |
|
587 code like |
|
588 |
|
589 @example |
|
590 SparseMatrix sm; |
|
591 @dots{} |
|
592 for (int j = 0; j < nc; j++) |
|
593 for (int i = 0; i < nr; i++) |
|
594 std::cerr << " (" << i << "," << j << "): " << sm(i,j) |
|
595 << std::endl; |
|
596 @end example |
|
597 |
|
598 is a great way of turning the sparse matrix into a dense one, and a |
|
599 very slow way at that since it reallocates the sparse object at each |
|
600 zero element in the matrix. |
|
601 |
|
602 An easy way of preventing the above from hapening is to create a temporary |
|
603 constant version of the sparse matrix. Note that only the container for |
|
604 the sparse matrix will be copied, while the actual representation of the |
|
605 data will be shared between the two versions of the sparse matrix. So this |
|
606 is not a costly operation. For example, the above would become |
|
607 |
|
608 @example |
|
609 SparseMatrix sm; |
|
610 @dots{} |
|
611 const SparseMatrix tmp (sm); |
|
612 for (int j = 0; j < nc; j++) |
|
613 for (int i = 0; i < nr; i++) |
|
614 std::cerr << " (" << i << "," << j << "): " << tmp(i,j) |
|
615 << std::endl; |
|
616 @end example |
|
617 |
|
618 Finally, as the sparse types aren't just represented as a contiguous |
|
619 block of memory, the @code{fortran_vec} method of the @code{Array<T>} |
|
620 is not available. It is however replaced by three seperate methods |
|
621 @code{ridx}, @code{cidx} and @code{data}, that access the raw compressed |
5324
|
622 column format that the Octave sparse matrices are stored in. |
5164
|
623 Additionally, these methods can be used in a manner similar to @code{elem}, |
|
624 to allow the matrix to be accessed or filled. However, in that case it is |
|
625 up to the user to repect the sparse matrix compressed column format |
|
626 discussed previous. |
|
627 |
|
628 @node OctCreation, OctUse, OctDifferences, Oct-Files |
|
629 @subsection Creating Spare Matrices in Oct-Files |
|
630 |
|
631 The user has several alternatives in how to create a sparse matrix. |
|
632 They can first create the data as three vectors representing the |
|
633 row and column indexes and the data, and from those create the matrix. |
|
634 Or alternatively, they can create a sparse matrix with the appropriate |
|
635 amount of space and then fill in the values. Both techniques have their |
|
636 advantages and disadvantages. |
|
637 |
|
638 An example of how to create a small sparse matrix with the first technique |
|
639 might be seen the example |
|
640 |
|
641 @example |
|
642 int nz = 4, nr = 3, nc = 4; |
|
643 ColumnVector ridx (nz); |
|
644 ColumnVector cidx (nz); |
|
645 ColumnVector data (nz); |
|
646 |
|
647 ridx(0) = 0; ridx(1) = 0; ridx(2) = 1; ridx(3) = 2; |
|
648 cidx(0) = 0; cidx(1) = 1; cidx(2) = 3; cidx(3) = 3; |
|
649 data(0) = 1; data(1) = 2; data(2) = 3; data(3) = 4; |
|
650 |
|
651 SparseMatrix sm (data, ridx, cidx, nr, nc); |
|
652 @end example |
|
653 |
|
654 which creates the matrix given in section @ref{Storage}. Note that |
|
655 the compressed matrix format is not used at the time of the creation |
|
656 of the matrix itself, however it is used internally. |
|
657 |
|
658 As previously mentioned, the values of the sparse matrix are stored |
|
659 in increasing column-major ordering. Although the data passed by the |
|
660 user does not need to respect this requirement, the pre-sorting the |
|
661 data significantly speeds up the creation of the sparse matrix. |
|
662 |
|
663 The disadvantage of this technique of creating a sparse matrix is |
|
664 that there is a brief time where two copies of the data exists. Therefore |
|
665 for extremely memory constrained problems this might not be the right |
|
666 technique to create the sparse matrix. |
|
667 |
|
668 The alternative is to first create the sparse matrix with the desired |
|
669 number of non-zero elements and then later fill those elements in. The |
|
670 easiest way to do this is |
|
671 |
|
672 @example |
|
673 int nz = 4, nr = 3, nc = 4; |
|
674 SparseMatrix sm (nr, nc, nz); |
|
675 sm(0,0) = 1; sm(0,1) = 2; sm(1,3) = 3; sm(2,3) = 4; |
|
676 @end example |
|
677 |
|
678 That creates the same matrix as previously. Again, although it is not |
|
679 strictly necessary, it is significantly faster if the sparse matrix is |
|
680 created in this manner that the elements are added in column-major |
|
681 ordering. The reason for this is that if the elements are inserted |
|
682 at the end of the current list of known elements then no element |
|
683 in the matrix needs to be moved to allow the new element to be |
|
684 inserted. Only the column indexes need to be updated. |
|
685 |
|
686 There are a few further points to note about this technique of creating |
|
687 a sparse matrix. Firstly, it is not illegal to create a sparse matrix |
|
688 with fewer elements than are actually inserted in the matrix. Therefore |
|
689 |
|
690 @example |
|
691 int nz = 4, nr = 3, nc = 4; |
|
692 SparseMatrix sm (nr, nc, 0); |
|
693 sm(0,0) = 1; sm(0,1) = 2; sm(1,3) = 3; sm(2,3) = 4; |
|
694 @end example |
|
695 |
|
696 is perfectly legal. However it is a very bad idea. The reason is that |
|
697 as each new element is added to the sparse matrix the space allocated |
|
698 to it is increased by reallocating the memory. This is an expensive |
|
699 operation, that will significantly slow this means of creating a sparse |
|
700 matrix. Furthermore, it is not illegal to create a sparse matrix with |
|
701 too much storage, so having @var{nz} above equaling 6 is also legal. |
|
702 The disadvantage is that the matrix occupies more memory than strictly |
|
703 needed. |
|
704 |
|
705 It is not always easy to known the number of non-zero elements prior |
|
706 to filling a matrix. For this reason the additional storage for the |
|
707 sparse matrix can be removed after its creation with the |
|
708 @dfn{maybe_compress} function. Furthermore, the maybe_compress can |
|
709 deallocate the unused storage, but it can equally remove zero elements |
|
710 from the matrix. The removal of zero elements from the matrix is |
|
711 controlled by setting the argument of the @dfn{maybe_compress} function |
|
712 to be 'true'. However, the cost of removing the zeros is high because it |
|
713 implies resorting the elements. Therefore, if possible it is better |
|
714 is the user doesn't add the zeros in the first place. An example of |
|
715 the use of @dfn{maybe_compress} is |
|
716 |
|
717 @example |
|
718 int nz = 6, nr = 3, nc = 4; |
|
719 SparseMatrix sm1 (nr, nc, nz); |
|
720 sm1(0,0) = 1; sm1(0,1) = 2; sm1(1,3) = 3; sm1(2,3) = 4; |
|
721 sm1.maybe_compress (); // No zero elements were added |
|
722 |
|
723 SparseMatrix sm2 (nr, nc, nz); |
|
724 sm2(0,0) = 1; sm2(0,1) = 2; sm(0,2) = 0; sm(1,2) = 0; |
|
725 sm1(1,3) = 3; sm1(2,3) = 4; |
|
726 sm2.maybe_compress (true); // Zero elements were added |
|
727 @end example |
|
728 |
|
729 The use of the @dfn{maybe_compress} function should be avoided if |
|
730 possible, as it will slow the creation of the matrices. |
|
731 |
|
732 A third means of creating a sparse matrix is to work directly with |
|
733 the data in compressed row format. An example of this technique might |
|
734 be |
|
735 |
|
736 @c Note the @verbatim environment is a relatively new addition to texinfo. |
|
737 @c Therefore use the @example environment and replace @, with @@, |
|
738 @c { with @{, etc |
|
739 |
|
740 @example |
|
741 octave_value arg; |
|
742 |
|
743 @dots{} |
|
744 |
|
745 int nz = 6, nr = 3, nc = 4; // Assume we know the max no nz |
|
746 SparseMatrix sm (nr, nc, nz); |
|
747 Matrix m = arg.matrix_value (); |
|
748 |
|
749 int ii = 0; |
|
750 sm.cidx (0) = 0; |
|
751 for (int j = 1; j < nc; j++) |
|
752 @{ |
|
753 for (int i = 0; i < nr; i++) |
|
754 @{ |
|
755 double tmp = foo (m(i,j)); |
|
756 if (tmp != 0.) |
|
757 @{ |
|
758 sm.data(ii) = tmp; |
|
759 sm.ridx(ii) = i; |
|
760 ii++; |
|
761 @} |
|
762 @} |
|
763 sm.cidx(j+1) = ii; |
|
764 @} |
5506
|
765 sm.maybe_compress (); // If don't know a-priori the final no of nz. |
5164
|
766 @end example |
|
767 |
|
768 which is probably the most efficient means of creating the sparse matrix. |
|
769 |
|
770 Finally, it might sometimes arise that the amount of storage initially |
|
771 created is insufficient to completely store the sparse matrix. Therefore, |
|
772 the method @code{change_capacity} exists to reallocate the sparse memory. |
|
773 The above example would then be modified as |
|
774 |
|
775 @example |
|
776 octave_value arg; |
|
777 |
|
778 @dots{} |
|
779 |
|
780 int nz = 6, nr = 3, nc = 4; // Assume we know the max no nz |
|
781 SparseMatrix sm (nr, nc, nz); |
|
782 Matrix m = arg.matrix_value (); |
|
783 |
|
784 int ii = 0; |
|
785 sm.cidx (0) = 0; |
|
786 for (int j = 1; j < nc; j++) |
|
787 @{ |
|
788 for (int i = 0; i < nr; i++) |
|
789 @{ |
|
790 double tmp = foo (m(i,j)); |
|
791 if (tmp != 0.) |
|
792 @{ |
|
793 if (ii == nz) |
|
794 @{ |
|
795 nz += 2; // Add 2 more elements |
|
796 sm.change_capacity (nz); |
|
797 @} |
|
798 sm.data(ii) = tmp; |
|
799 sm.ridx(ii) = i; |
|
800 ii++; |
|
801 @} |
|
802 @} |
|
803 sm.cidx(j+1) = ii; |
|
804 @} |
|
805 sm.maybe_mutate (); // If don't know a-priori the final no of nz. |
|
806 @end example |
|
807 |
|
808 Note that both increasing and decreasing the number of non-zero elements in |
|
809 a sparse matrix is expensive, as it involves memory reallocation. Also as |
|
810 parts of the matrix, though not its entirety, exist as the old and new copy |
|
811 at the same time, additional memory is needed. Therefore if possible this |
|
812 should be avoided. |
|
813 |
|
814 @node OctUse, , OctCreation, Oct-Files |
|
815 @subsection Using Sparse Matrices in Oct-Files |
|
816 |
|
817 Most of the same operators and functions on sparse matrices that are |
5324
|
818 available from the Octave are equally available with oct-files. |
5164
|
819 The basic means of extracting a sparse matrix from an @code{octave_value} |
|
820 and returning them as an @code{octave_value}, can be seen in the |
|
821 following example |
|
822 |
|
823 @example |
|
824 octave_value_list retval; |
|
825 |
|
826 SparseMatrix sm = args(0).sparse_matrix_value (); |
|
827 SparseComplexMatrix scm = args(1).sparse_complex_matrix_value (); |
|
828 SparseBoolMatrix sbm = args(2).sparse_bool_matrix_value (); |
|
829 |
|
830 @dots{} |
|
831 |
|
832 retval(2) = sbm; |
|
833 retval(1) = scm; |
|
834 retval(0) = sm; |
|
835 @end example |
|
836 |
|
837 The conversion to an octave-value is handled by the sparse |
|
838 @code{octave_value} constructors, and so no special care is needed. |
|
839 |
5506
|
840 @node Function Reference, , Oct-Files, Sparse Matrices |
5164
|
841 @section Function Reference |
|
842 |
|
843 @iftex |
|
844 @subsection Functions by Category |
|
845 @subsubsection Generate sparse matrix |
|
846 @table @asis |
|
847 @item spdiags |
|
848 A generalization of the function `spdiag'. |
|
849 @item speye |
|
850 Returns a sparse identity matrix. |
|
851 @item sprand |
|
852 Generate a random sparse matrix. |
|
853 @item sprandn |
|
854 Generate a random sparse matrix. |
|
855 @item sprandsym |
|
856 @emph{Not implemented} |
|
857 @end table |
|
858 @subsubsection Sparse matrix conversion |
|
859 @table @asis |
|
860 @item full |
|
861 returns a full storage matrix from a sparse one See also: sparse |
|
862 @item sparse |
|
863 SPARSE: create a sparse matrix |
|
864 @item spconvert |
|
865 This function converts for a simple sparse matrix format easily produced by other programs into Octave's internal sparse format. |
|
866 @item spfind |
|
867 SPFIND: a sparse version of the find operator 1. |
|
868 @end table |
|
869 @subsubsection Manipulate sparse matrices |
|
870 @table @asis |
|
871 @item issparse |
|
872 Return 1 if the value of the expression EXPR is a sparse matrix. |
|
873 @item nnz |
|
874 returns number of non zero elements in SM See also: sparse |
|
875 @item nonzeros |
|
876 Returns a vector of the non-zero values of the sparse matrix S |
|
877 @item nzmax |
|
878 Returns the amount of storage allocated to the sparse matrix SM. |
|
879 @item spalloc |
|
880 Returns an empty sparse matrix of size R-by-C. |
|
881 @item spfun |
|
882 Compute `f(X)' for the non-zero values of X This results in a sparse matrix with the same structure as X. |
|
883 @item spones |
|
884 Replace the non-zero entries of X with ones. |
|
885 @item spy |
|
886 Plot the sparsity pattern of the sparse matrix X |
|
887 @end table |
|
888 @subsubsection Graph Theory |
|
889 @table @asis |
|
890 @item etree |
|
891 Returns the elimination tree for the matrix S. |
|
892 @item etreeplot |
|
893 @emph{Not implemented} |
|
894 @item gplot |
|
895 @emph{Not implemented} |
|
896 @item treelayout |
|
897 @emph{Not implemented} |
|
898 @item treeplot |
|
899 @emph{Not implemented} |
|
900 @end table |
|
901 @subsubsection Sparse matrix reordering |
|
902 @table @asis |
5506
|
903 @item ccolamd |
|
904 Constrained column approximate minimum degree permutation. |
5164
|
905 @item colamd |
|
906 Column approximate minimum degree permutation. |
|
907 @item colperm |
|
908 Returns the column permutations such that the columns of `S (:, P)' are ordered in terms of increase number of non-zero elements. |
5506
|
909 @item csymamd |
|
910 For a symmetric positive definite matrix S, returns the permutation vector p such that `S (P, P)' tends to have a sparser Cholesky factor than S. |
5164
|
911 @item dmperm |
5322
|
912 Perform a Deulmage-Mendelsohn permutation on the sparse matrix S. |
5164
|
913 @item symamd |
|
914 For a symmetric positive definite matrix S, returns the permutation vector p such that `S (P, P)' tends to have a sparser Cholesky factor than S. |
|
915 @item symrcm |
|
916 Returns the Reverse Cuthill McKee reordering of the sparse matrix S. |
|
917 @end table |
|
918 @subsubsection Linear algebra |
|
919 @table @asis |
|
920 @item cholinc |
|
921 @emph{Not implemented} |
|
922 @item condest |
|
923 @emph{Not implemented} |
|
924 @item eigs |
|
925 @emph{Not implemented} |
5322
|
926 @item matrix_type |
|
927 Identify the matrix type or mark a matrix as a particular type. |
5164
|
928 @item normest |
|
929 @emph{Not implemented} |
5506
|
930 @item spchol |
|
931 Compute the Cholesky factor, R, of the symmetric positive definite. |
|
932 @item spcholinv |
|
933 Use the Cholesky factorization to compute the inverse of the |
|
934 sparse symmetric positive definite matrix A. |
|
935 @item spchol2inv |
|
936 Invert a sparse symmetric, positive definite square matrix from its |
|
937 Cholesky decomposition, U. |
5164
|
938 @item spdet |
|
939 Compute the determinant of sparse matrix A using UMFPACK. |
|
940 @item spinv |
|
941 Compute the inverse of the square matrix A. |
5322
|
942 @item spkron |
|
943 Form the kronecker product of two sparse matrices. |
5506
|
944 @item splchol |
|
945 Compute the Cholesky factor, L, of the symmetric positive definite. |
5164
|
946 @item splu |
|
947 Compute the LU decomposition of the sparse matrix A, using subroutines from UMFPACK. |
|
948 @item sprank |
|
949 @emph{Not implemented} |
|
950 @item svds |
|
951 @emph{Not implemented} |
|
952 @end table |
|
953 @subsubsection Iterative techniques |
|
954 @table @asis |
|
955 @item bicg |
|
956 @emph{Not implemented} |
|
957 @item bicgstab |
|
958 @emph{Not implemented} |
|
959 @item cgs |
|
960 @emph{Not implemented} |
|
961 @item gmres |
|
962 @emph{Not implemented} |
5282
|
963 @item luinc |
|
964 Produce the incomplete LU factorization of the sparse matrix A. |
5164
|
965 @item lsqr |
|
966 @emph{Not implemented} |
|
967 @item minres |
|
968 @emph{Not implemented} |
|
969 @item pcg |
|
970 @emph{Not implemented} |
|
971 @item pcr |
|
972 @emph{Not implemented} |
|
973 @item qmr |
|
974 @emph{Not implemented} |
|
975 @item symmlq |
|
976 @emph{Not implemented} |
|
977 @end table |
|
978 @subsubsection Miscellaneous |
|
979 @table @asis |
|
980 @item spaugment |
|
981 @emph{Not implemented} |
|
982 @item spparms |
|
983 Sets or displays the parameters used by the sparse solvers and factorization functions. |
|
984 @item symbfact |
|
985 Performs a symbolic factorization analysis on the sparse matrix S. |
|
986 @item spstats |
|
987 Return the stats for the non-zero elements of the sparse matrix S COUNT is the number of non-zeros in each column, MEAN is the mean of the non-zeros in each column, and VAR is the variance of the non-zeros in each column |
|
988 @item spprod |
|
989 Product of elements along dimension DIM. |
|
990 @item spcumprod |
|
991 Cumulative product of elements along dimension DIM. |
|
992 @item spcumsum |
|
993 Cumulative sum of elements along dimension DIM. |
|
994 @item spsum |
|
995 Sum of elements along dimension DIM. |
|
996 @item spsumsq |
|
997 Sum of squares of elements along dimension DIM. |
|
998 @item spmin |
|
999 For a vector argument, return the minimum value. |
|
1000 @item spmax |
|
1001 For a vector argument, return the maximum value. |
|
1002 @item spatan2 |
|
1003 Compute atan (Y / X) for corresponding sparse matrix elements of Y and X. |
|
1004 @item spdiag |
|
1005 Return a diagonal matrix with the sparse vector V on diagonal K. |
|
1006 @end table |
|
1007 |
|
1008 @subsection Functions Alphabetically |
|
1009 @end iftex |
|
1010 |
|
1011 @menu |
5506
|
1012 * ccolamd:: Constrained column approximate minimum degree permutation. |
5164
|
1013 * colamd:: Column approximate minimum degree permutation. |
|
1014 * colperm:: Returns the column permutations such that the columns of `S |
|
1015 (:, P)' are ordered in terms of increase number of non-zero |
|
1016 elements. |
5506
|
1017 * csymamd:: For a symmetric positive definite matrix S, returns the |
|
1018 permutation vector p such that `S (P, P)' tends to have a |
|
1019 sparser Cholesky factor than S. |
5164
|
1020 * dmperm:: Perfrom a Deulmage-Mendelsohn permutation on the sparse |
|
1021 matrix S. |
|
1022 * etree:: Returns the elimination tree for the matrix S. |
|
1023 * full:: returns a full storage matrix from a sparse one See also: |
|
1024 sparse |
|
1025 * issparse:: Return 1 if the value of the expression EXPR is a sparse |
|
1026 matrix. |
5282
|
1027 * luinc:: Produce the incomplete LU factorization of the sparse |
|
1028 A. |
5322
|
1029 * matrix_type:: Identify the matrix type or mark a matrix as a particular |
|
1030 type. |
5164
|
1031 * nnz:: returns number of non zero elements in SM See also: sparse |
|
1032 * nonzeros:: Returns a vector of the non-zero values of the sparse |
|
1033 matrix S |
|
1034 * nzmax:: Returns the amount of storage allocated to the sparse |
|
1035 matrix SM. |
|
1036 * spalloc:: Returns an empty sparse matrix of size R-by-C. |
|
1037 * sparse:: SPARSE: create a sparse matrix |
|
1038 * spatan2:: Compute atan (Y / X) for corresponding sparse matrix |
|
1039 elements of Y and X. |
5506
|
1040 * spchol:: Compute the Cholesky factor, R, of the symmetric |
|
1041 positive definite. |
|
1042 * spcholinv:: Use the Cholesky factorization to compute the inverse of the |
|
1043 sparse symmetric positive definite matrix A. |
|
1044 * spchol2inv:: Invert a sparse symmetric, positive definite square matrix |
|
1045 from its Cholesky decomposition, U. |
5164
|
1046 * spconvert:: This function converts for a simple sparse matrix format |
|
1047 easily produced by other programs into Octave's internal |
|
1048 sparse format. |
|
1049 * spcumprod:: Cumulative product of elements along dimension DIM. |
|
1050 * spcumsum:: Cumulative sum of elements along dimension DIM. |
|
1051 * spdet:: Compute the determinant of sparse matrix A using UMFPACK. |
|
1052 * spdiag:: Return a diagonal matrix with the sparse vector V on |
|
1053 diagonal K. |
|
1054 * spdiags:: A generalization of the function `spdiag'. |
|
1055 * speye:: Returns a sparse identity matrix. |
|
1056 * spfind:: SPFIND: a sparse version of the find operator 1. |
|
1057 * spfun:: Compute `f(X)' for the non-zero values of X This results in |
|
1058 a sparse matrix with the same structure as X. |
|
1059 * spinv:: Compute the inverse of the square matrix A. |
5322
|
1060 * spkron:: Form the kronecker product of two sparse matrices. |
5506
|
1061 * splchol:: Compute the Cholesky factor, L, of the symmetric positive |
|
1062 definite. |
5164
|
1063 * splu:: Compute the LU decomposition of the sparse matrix A, using |
|
1064 subroutines from UMFPACK. |
|
1065 * spmax:: For a vector argument, return the maximum value. |
|
1066 * spmin:: For a vector argument, return the minimum value. |
|
1067 * spones:: Replace the non-zero entries of X with ones. |
|
1068 * spparms:: Sets or displays the parameters used by the sparse solvers |
|
1069 and factorization functions. |
|
1070 * spprod:: Product of elements along dimension DIM. |
|
1071 * sprand:: Generate a random sparse matrix. |
|
1072 * sprandn:: Generate a random sparse matrix. |
|
1073 * spstats:: Return the stats for the non-zero elements of the sparse |
|
1074 matrix S COUNT is the number of non-zeros in each column, |
|
1075 MEAN is the mean of the non-zeros in each column, and VAR |
|
1076 is the variance of the non-zeros in each column |
|
1077 * spsum:: Sum of elements along dimension DIM. |
|
1078 * spsumsq:: Sum of squares of elements along dimension DIM. |
|
1079 * spy:: Plot the sparsity pattern of the sparse matrix X |
|
1080 * symamd:: For a symmetric positive definite matrix S, returns the |
|
1081 permutation vector p such that `S (P, P)' tends to have a |
|
1082 sparser Cholesky factor than S. |
|
1083 * symbfact:: Performs a symbolic factorization analysis on the sparse |
|
1084 matrix S. |
|
1085 * symrcm:: Returns the Reverse Cuthill McKee reordering of the sparse |
|
1086 matrix S. |
|
1087 @end menu |
|
1088 |
5506
|
1089 @node colamd, ccolamd, , Function Reference |
5164
|
1090 @subsubsection colamd |
|
1091 |
|
1092 @DOCSTRING(colamd) |
|
1093 |
5506
|
1094 @node ccolamd, colperm, colamd, Function Reference |
|
1095 @subsubsection ccolamd |
|
1096 |
|
1097 @DOCSTRING(ccolamd) |
|
1098 |
|
1099 @node colperm, csymamd, ccolamd, Function Reference |
5164
|
1100 @subsubsection colperm |
|
1101 |
|
1102 @DOCSTRING(colperm) |
|
1103 |
5506
|
1104 @node csymamd, dmperm, colperm, Function Reference |
|
1105 @subsubsection csymamd |
|
1106 |
|
1107 @DOCSTRING(csymamd) |
|
1108 |
|
1109 @node dmperm, etree, csymamd, Function Reference |
5164
|
1110 @subsubsection dmperm |
|
1111 |
|
1112 @DOCSTRING(dmperm) |
|
1113 |
|
1114 @node etree, full, dmperm, Function Reference |
|
1115 @subsubsection etree |
|
1116 |
|
1117 @DOCSTRING(etree) |
|
1118 |
|
1119 @node full, issparse, etree, Function Reference |
|
1120 @subsubsection full |
|
1121 |
|
1122 @DOCSTRING(full) |
|
1123 |
5282
|
1124 @node issparse, luinc, full, Function Reference |
5164
|
1125 @subsubsection issparse |
|
1126 |
|
1127 @DOCSTRING(issparse) |
|
1128 |
5322
|
1129 @node luinc, matrix_type, issparse, Function Reference |
5282
|
1130 @subsubsection luinc |
|
1131 |
|
1132 @DOCSTRING(luinc) |
|
1133 |
5322
|
1134 @node matrix_type, nnz, luinc, Function Reference |
|
1135 @subsubsection matrix_type |
|
1136 |
|
1137 @DOCSTRING(matrix_type) |
|
1138 |
|
1139 @node nnz, nonzeros, matrix_type, Function Reference |
5164
|
1140 @subsubsection nnz |
|
1141 |
|
1142 @DOCSTRING(nnz) |
|
1143 |
|
1144 @node nonzeros, nzmax, nnz, Function Reference |
|
1145 @subsubsection nonzeros |
|
1146 |
|
1147 @DOCSTRING(nonzeros) |
|
1148 |
|
1149 @node nzmax, spalloc, nonzeros, Function Reference |
|
1150 @subsubsection nzmax |
|
1151 |
|
1152 @DOCSTRING(nzmax) |
|
1153 |
|
1154 @node spalloc, sparse, nzmax, Function Reference |
|
1155 @subsubsection spalloc |
|
1156 |
|
1157 @DOCSTRING(spalloc) |
|
1158 |
|
1159 @node sparse, spatan2, spalloc, Function Reference |
|
1160 @subsubsection sparse |
|
1161 |
|
1162 @DOCSTRING(sparse) |
|
1163 |
5506
|
1164 @node spatan2, spchol, sparse, Function Reference |
5164
|
1165 @subsubsection spatan2 |
|
1166 |
|
1167 @DOCSTRING(spatan2) |
|
1168 |
5506
|
1169 @node spchol, spcholinv, spatan2, Function Reference |
|
1170 @subsubsection spchol |
|
1171 |
|
1172 @DOCSTRING(spchol) |
|
1173 |
|
1174 @node spcholinv, spchol2inv, spchol, Function Reference |
|
1175 @subsubsection spcholinv |
|
1176 |
|
1177 @DOCSTRING(spcholinv) |
|
1178 |
|
1179 @node spchol2inv, spconvert, spcholinv, Function Reference |
|
1180 @subsubsection spchol2inv |
|
1181 |
|
1182 @DOCSTRING(spchol2inv) |
|
1183 |
|
1184 @node spconvert, spcumprod, spchol2inv, Function Reference |
5164
|
1185 @subsubsection spconvert |
|
1186 |
|
1187 @DOCSTRING(spconvert) |
|
1188 |
|
1189 @node spcumprod, spcumsum, spconvert, Function Reference |
|
1190 @subsubsection spcumprod |
|
1191 |
|
1192 @DOCSTRING(spcumprod) |
|
1193 |
|
1194 @node spcumsum, spdet, spcumprod, Function Reference |
|
1195 @subsubsection spcumsum |
|
1196 |
|
1197 @DOCSTRING(spcumsum) |
|
1198 |
|
1199 @node spdet, spdiag, spcumsum, Function Reference |
|
1200 @subsubsection spdet |
|
1201 |
|
1202 @DOCSTRING(spdet) |
|
1203 |
|
1204 @node spdiag, spdiags, spdet, Function Reference |
|
1205 @subsubsection spdiag |
|
1206 |
|
1207 @DOCSTRING(spdiag) |
|
1208 |
|
1209 @node spdiags, speye, spdiag, Function Reference |
|
1210 @subsubsection spdiags |
|
1211 |
|
1212 @DOCSTRING(spdiags) |
|
1213 |
|
1214 @node speye, spfind, spdiags, Function Reference |
|
1215 @subsubsection speye |
|
1216 |
|
1217 @DOCSTRING(speye) |
|
1218 |
|
1219 @node spfind, spfun, speye, Function Reference |
|
1220 @subsubsection spfind |
|
1221 |
|
1222 @DOCSTRING(spfind) |
|
1223 |
|
1224 @node spfun, spinv, spfind, Function Reference |
|
1225 @subsubsection spfun |
|
1226 |
|
1227 @DOCSTRING(spfun) |
|
1228 |
5322
|
1229 @node spinv, spkron, spfun, Function Reference |
5164
|
1230 @subsubsection spinv |
|
1231 |
|
1232 @DOCSTRING(spinv) |
|
1233 |
5506
|
1234 @node spkron, splchol, spinv, Function Reference |
5322
|
1235 @subsubsection spkron |
|
1236 |
|
1237 @DOCSTRING(spkron) |
|
1238 |
5506
|
1239 @node splchol, splu, spkron, Function Reference |
|
1240 @subsubsection splchol |
|
1241 |
|
1242 @DOCSTRING(splchol) |
|
1243 |
|
1244 @node splu, spmax, splchol, Function Reference |
5164
|
1245 @subsubsection splu |
|
1246 |
|
1247 @DOCSTRING(splu) |
|
1248 |
|
1249 @node spmax, spmin, splu, Function Reference |
|
1250 @subsubsection spmax |
|
1251 |
|
1252 @DOCSTRING(spmax) |
|
1253 |
|
1254 @node spmin, spones, spmax, Function Reference |
|
1255 @subsubsection spmin |
|
1256 |
|
1257 @DOCSTRING(spmin) |
|
1258 |
|
1259 @node spones, spparms, spmin, Function Reference |
|
1260 @subsubsection spones |
|
1261 |
|
1262 @DOCSTRING(spones) |
|
1263 |
|
1264 @node spparms, spprod, spones, Function Reference |
|
1265 @subsubsection spparms |
|
1266 |
|
1267 @DOCSTRING(spparms) |
|
1268 |
|
1269 @node spprod, sprand, spparms, Function Reference |
|
1270 @subsubsection spprod |
|
1271 |
|
1272 @DOCSTRING(spprod) |
|
1273 |
|
1274 @node sprand, sprandn, spprod, Function Reference |
|
1275 @subsubsection sprand |
|
1276 |
|
1277 @DOCSTRING(sprand) |
|
1278 |
5506
|
1279 @node sprandn, spstats, sprand, Function Reference |
5164
|
1280 @subsubsection sprandn |
|
1281 |
|
1282 @DOCSTRING(sprandn) |
|
1283 |
5506
|
1284 @node spstats, spsum, sprandn, Function Reference |
5164
|
1285 @subsubsection spstats |
|
1286 |
|
1287 @DOCSTRING(spstats) |
|
1288 |
|
1289 @node spsum, spsumsq, spstats, Function Reference |
|
1290 @subsubsection spsum |
|
1291 |
|
1292 @DOCSTRING(spsum) |
|
1293 |
|
1294 @node spsumsq, spy, spsum, Function Reference |
|
1295 @subsubsection spsumsq |
|
1296 |
|
1297 @DOCSTRING(spsumsq) |
|
1298 |
|
1299 @node spy, symamd, spsumsq, Function Reference |
|
1300 @subsubsection spy |
|
1301 |
|
1302 @DOCSTRING(spy) |
|
1303 |
|
1304 @node symamd, symbfact, spy, Function Reference |
|
1305 @subsubsection symamd |
|
1306 |
|
1307 @DOCSTRING(symamd) |
|
1308 |
|
1309 @node symbfact, symrcm, symamd, Function Reference |
|
1310 @subsubsection symbfact |
|
1311 |
|
1312 @DOCSTRING(symbfact) |
|
1313 |
|
1314 @node symrcm, , symbfact, Function Reference |
|
1315 @subsubsection symrcm |
|
1316 |
|
1317 @DOCSTRING(symrcm) |
|
1318 |
|
1319 @c Local Variables: *** |
|
1320 @c Mode: texinfo *** |
|
1321 @c End: *** |