Mercurial > octave-nkf
annotate scripts/sparse/sprandn.m @ 19631:db92e7e28e1f
strip trailing whitespace from most source files
* NEWS, doc/interpreter/contributors.in, doc/interpreter/func.txi,
doc/interpreter/genpropdoc.m, doc/interpreter/octave_logo.eps,
doc/interpreter/plot.txi, doc/interpreter/stmt.txi,
examples/data/Makefile.am, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/error.cc,
libinterp/corefcn/file-io.cc, libinterp/corefcn/gl-render.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h,
libinterp/corefcn/load-path.cc, libinterp/corefcn/pr-output.cc,
libinterp/corefcn/pt-jit.cc, libinterp/corefcn/strfind.cc,
libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h,
libinterp/corefcn/urlwrite.cc, libinterp/corefcn/variables.cc,
libinterp/octave-value/ov-classdef.cc,
libinterp/octave-value/ov-classdef.h, libinterp/octave.cc,
libinterp/parse-tree/lex.h, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/pt-classdef.h, liboctave/system/file-ops.cc,
liboctave/system/oct-env.cc, m4/acinclude.m4,
scripts/deprecated/finite.m, scripts/deprecated/fmod.m,
scripts/deprecated/fnmatch.m, scripts/deprecated/luinc.m,
scripts/deprecated/octave_tmp_file_name.m, scripts/deprecated/syl.m,
scripts/deprecated/usage.m, scripts/general/inputParser.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/isequal.m,
scripts/general/private/__isequal__.m, scripts/geometry/voronoi.m,
scripts/image/image.m, scripts/image/imshow.m,
scripts/image/ind2rgb.m, scripts/linear-algebra/bandwidth.m,
scripts/linear-algebra/isbanded.m, scripts/miscellaneous/bzip2.m,
scripts/miscellaneous/cast.m, scripts/miscellaneous/copyfile.m,
scripts/miscellaneous/delete.m, scripts/miscellaneous/fullfile.m,
scripts/miscellaneous/getappdata.m, scripts/miscellaneous/gunzip.m,
scripts/miscellaneous/isappdata.m, scripts/miscellaneous/ls.m,
scripts/miscellaneous/mex.m, scripts/miscellaneous/movefile.m,
scripts/miscellaneous/orderfields.m, scripts/miscellaneous/recycle.m,
scripts/miscellaneous/rmappdata.m, scripts/miscellaneous/setfield.m,
scripts/miscellaneous/symvar.m, scripts/miscellaneous/tar.m,
scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m,
scripts/miscellaneous/ver.m, scripts/miscellaneous/what.m,
scripts/miscellaneous/xor.m, scripts/miscellaneous/zip.m,
scripts/optimization/fminbnd.m, scripts/optimization/sqp.m,
scripts/path/private/getsavepath.m, scripts/path/savepath.m,
scripts/pkg/pkg.m, scripts/pkg/private/installed_packages.m,
scripts/plot/draw/plotyy.m, scripts/plot/draw/polar.m,
scripts/plot/draw/private/__quiver__.m,
scripts/plot/draw/private/__scatter__.m,
scripts/plot/draw/private/__stem__.m, scripts/plot/draw/surface.m,
scripts/plot/draw/surfnorm.m, scripts/plot/util/copyobj.m,
scripts/plot/util/hgload.m, scripts/plot/util/hgsave.m,
scripts/plot/util/isprop.m, scripts/plot/util/linkprop.m,
scripts/plot/util/private/__go_draw_axes__.m, scripts/set/setdiff.m,
scripts/set/union.m, scripts/signal/periodogram.m,
scripts/sparse/eigs.m, scripts/sparse/ilu.m, scripts/sparse/qmr.m,
scripts/sparse/sprand.m, scripts/sparse/sprandn.m,
scripts/specfun/beta.m, scripts/specfun/ellipke.m,
scripts/specfun/isprime.m, scripts/statistics/base/lscov.m,
scripts/testfun/__run_test_suite__.m, scripts/testfun/test.m:
Strip trailing whitespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 10:29:54 -0500 |
parents | 0e1f5a750d00 |
children | 4197fc428c7d |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17338
diff
changeset
|
1 ## Copyright (C) 2004-2013 Paul Kienzle |
5164 | 2 ## |
7016 | 3 ## This file is part of Octave. |
4 ## | |
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. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 ## | |
19 ## Original version by Paul Kienzle distributed as free software in the | |
20 ## public domain. | |
5164 | 21 |
22 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
23 ## @deftypefn {Function File} {} sprandn (@var{m}, @var{n}, @var{d}) |
18623
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
24 ## @deftypefnx {Function File} {} sprandn (@var{m}, @var{n}, @var{d}, @var{rc}) |
5610 | 25 ## @deftypefnx {Function File} {} sprandn (@var{s}) |
18624 | 26 ## Generate a sparse matrix with normally distributed random values. |
27 ## | |
28 ## The size of the matrix is @var{m}x@var{n} with a density of values @var{d}. | |
29 ## @var{d} must be between 0 and 1. Values will be normally distributed with a | |
30 ## mean of 0 and a variance of 1. | |
5164 | 31 ## |
18624 | 32 ## If called with a single matrix argument, a sparse matrix is generated with |
18851
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18850
diff
changeset
|
33 ## random values wherever the matrix @var{s} is nonzero. |
18624 | 34 ## |
35 ## If called with a scalar fourth argument @var{rc}, a random sparse matrix | |
36 ## with reciprocal condition number @var{rc} is generated. If @var{rc} is | |
37 ## a vector, then it specifies the first singular values of the generated | |
38 ## matrix (@code{length (@var{rc}) <= min (@var{m}, @var{n})}). | |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
39 ## |
18624 | 40 ## @seealso{sprand, sprandsym, randn} |
5164 | 41 ## @end deftypefn |
42 | |
43 ## Author: Paul Kienzle <pkienzle@users.sf.net> | |
44 | |
18624 | 45 function s = sprandn (m, n, d, rc) |
6498 | 46 |
13197
6db186dfdeaa
Refactor sprandn/sprand code, move common code to common function (bug #34352)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13064
diff
changeset
|
47 if (nargin == 1 ) |
18624 | 48 s = __sprand_impl__ (m, @randn); |
13197
6db186dfdeaa
Refactor sprandn/sprand code, move common code to common function (bug #34352)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13064
diff
changeset
|
49 elseif ( nargin == 3) |
18624 | 50 s = __sprand_impl__ (m, n, d, "sprandn", @randn); |
18623
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
51 elseif (nargin == 4) |
18624 | 52 s = __sprand_impl__ (m, n, d, rc, "sprandn", @randn); |
13197
6db186dfdeaa
Refactor sprandn/sprand code, move common code to common function (bug #34352)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13064
diff
changeset
|
53 else |
6046 | 54 print_usage (); |
5164 | 55 endif |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
56 |
5164 | 57 endfunction |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
58 |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
59 |
18624 | 60 %% Test 3-input calling form |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
61 %!test |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
62 %! s = sprandn (4, 10, 0.1); |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
63 %! assert (size (s), [4, 10]); |
13197
6db186dfdeaa
Refactor sprandn/sprand code, move common code to common function (bug #34352)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13064
diff
changeset
|
64 %! assert (nnz (s) / numel (s), 0.1); |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
65 |
18623
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
66 %% Test 4-input calling form |
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
67 %!test |
18624 | 68 %! d = rand (); |
18623
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
69 %! s1 = sprandn (100, 100, d, 0.4); |
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
70 %! rc = [5, 4, 3, 2, 1, 0.1]; |
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
71 %! s2 = sprandn (100, 100, d, rc); |
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
72 %! s3 = sprandn (6, 4, d, rc); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
73 %! assert (svd (s2)'(1:length (rc)), rc, sqrt (eps)); |
18623
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
74 %! assert (1/cond (s1), 0.4, sqrt (eps)); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
75 %! assert (nnz (s1) / (100*100), d, 0.02); |
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
76 %! assert (nnz (s2) / (100*100), d, 0.02); |
18623
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
77 %! assert (svd (s3)', [5 4 3 2], sqrt (eps)); |
35a5e7740a6d
Added implementation for 4th argument of sprand/sprandn (bug #41839).
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents:
17744
diff
changeset
|
78 |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
79 %% Test 1-input calling form |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
80 %!test |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
81 %! s = sprandn (sparse ([1 2 3], [3 2 3], [2 2 2])); |
13064
bae887ebea48
codesprint: Add input validation and tests for sprandsym.m
Rik <octave@nomad.inbox5.com>
parents:
13058
diff
changeset
|
82 %! [i, j] = find (s); |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
83 %! assert (sort (i), [1 2 3]'); |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
84 %! assert (sort (j), [2 3 3]'); |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
85 |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
86 %% Test input validation |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
87 %!error sprandn () |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
88 %!error sprandn (1, 2) |
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
89 %!error sprandn (1, 2, 3, 4) |
18624 | 90 %!error <M must be an integer greater than 0> sprandn (ones (3), 3, 0.5) |
91 %!error <M must be an integer greater than 0> sprandn (3.5, 3, 0.5) | |
92 %!error <M must be an integer greater than 0> sprandn (0, 3, 0.5) | |
93 %!error <N must be an integer greater than 0> sprandn (3, ones (3), 0.5) | |
94 %!error <N must be an integer greater than 0> sprandn (3, 3.5, 0.5) | |
95 %!error <N must be an integer greater than 0> sprandn (3, 0, 0.5) | |
96 %!error <D must be between 0 and 1> sprandn (3, 3, -1) | |
97 %!error <D must be between 0 and 1> sprandn (3, 3, 2) | |
98 %!error <RC must be a scalar or vector> sprandn (2, 2, 0.2, ones (3,3)) | |
99 %!error <RC must be between 0 and 1> sprandn (2, 2, 0.2, -1) | |
100 %!error <RC must be between 0 and 1> sprandn (2, 2, 0.2, 2) | |
13058
14422cc782b2
codesprint: Write input validation and tests for sprandn.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
101 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18848
diff
changeset
|
102 %% Test very large, very low density matrix doesn't fail |
16779
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
14868
diff
changeset
|
103 %!test |
18624 | 104 %! s = sprandn (1e6,1e6,1e-7); |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16779
diff
changeset
|
105 |