7017
|
1 ## Copyright (C) 2004, 2005, 2006, 2007 David Bateman & Andy Adler |
5164
|
2 ## |
7016
|
3 ## This file is part of Octave. |
5164
|
4 ## |
7016
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
5164
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
5164
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {@var{s} =} spalloc (@var{r}, @var{c}, @var{nz}) |
|
21 ## Returns an empty sparse matrix of size @var{r}-by-@var{c}. As Octave |
|
22 ## resizes sparse matrices at the first opportunity, so that no additional |
|
23 ## space is needed, the argument @var{nz} is ignored. This function is |
7001
|
24 ## provided only for compatibility reasons. |
5164
|
25 ## |
|
26 ## It should be noted that this means that code like |
|
27 ## |
|
28 ## @example |
|
29 ## k = 5; |
|
30 ## nz = r * k; |
|
31 ## s = spalloc (r, c, nz) |
|
32 ## for j = 1:c |
|
33 ## idx = randperm (r); |
|
34 ## s (:, j) = [zeros(r - k, 1); rand(k, 1)] (idx); |
|
35 ## endfor |
|
36 ## @end example |
|
37 ## |
|
38 ## will reallocate memory at each step. It is therefore vitally important |
|
39 ## that code like this is vectorized as much as possible. |
5642
|
40 ## @seealso{sparse, nzmax} |
5164
|
41 ## @end deftypefn |
|
42 |
|
43 function s = spalloc (r, c, nz) |
7125
|
44 |
|
45 if (nargin < 2) |
|
46 print_usage (); |
|
47 endif |
|
48 |
5164
|
49 s = sparse (r, c); |
|
50 endfunction |