annotate scripts/sparse/spdiags.m @ 20164:df437a52bcaf stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed miscellaneous, sparse, strings in scripts directory. * scripts/miscellaneous/bzip2.m, scripts/miscellaneous/citation.m, scripts/miscellaneous/compare_versions.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dir.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/genvarname.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/news.m, scripts/miscellaneous/open.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/run.m, scripts/miscellaneous/swapbytes.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/what.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/gplot.m, scripts/sparse/ichol.m, scripts/sparse/ilu.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/qmr.m, scripts/sparse/spaugment.m, scripts/sparse/spconvert.m, scripts/sparse/spdiags.m, scripts/sparse/spfun.m, scripts/sparse/spones.m, scripts/sparse/sprandsym.m, scripts/sparse/spstats.m, scripts/sparse/spy.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m, scripts/sparse/treeplot.m, scripts/strings/base2dec.m, scripts/strings/bin2dec.m, scripts/strings/blanks.m, scripts/strings/cstrcat.m, scripts/strings/deblank.m, scripts/strings/dec2base.m, scripts/strings/dec2bin.m, scripts/strings/dec2hex.m, scripts/strings/findstr.m, scripts/strings/hex2dec.m, scripts/strings/index.m, scripts/strings/isletter.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strchr.m, scripts/strings/strjoin.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/strsplit.m, scripts/strings/strtok.m, scripts/strings/strtrim.m, scripts/strings/strtrunc.m, scripts/strings/substr.m, scripts/strings/untabify.m, scripts/time/datenum.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Mon, 04 May 2015 14:22:02 -0700
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
1 ## Copyright (C) 2000-2015 Paul Kienzle
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
2 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
3 ## This file is part of Octave.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
8 ## your option) any later version.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
9 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
13 ## General Public License for more details.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
14 ##
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
18
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
20 ## @deftypefn {Function File} {@var{B} =} spdiags (@var{A})
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
21 ## @deftypefnx {Function File} {[@var{B}, @var{d}] =} spdiags (@var{A})
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
22 ## @deftypefnx {Function File} {@var{B} =} spdiags (@var{A}, @var{d})
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
23 ## @deftypefnx {Function File} {@var{A} =} spdiags (@var{v}, @var{d}, @var{A})
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
24 ## @deftypefnx {Function File} {@var{A} =} spdiags (@var{v}, @var{d}, @var{m}, @var{n})
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
25 ## A generalization of the function @code{diag}.
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
26 ##
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ## Called with a single input argument, the nonzero diagonals @var{d} of
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## @var{A} are extracted.
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ##
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## With two arguments the diagonals to extract are given by the vector @var{d}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
32 ## The other two forms of @code{spdiags} modify the input matrix by replacing
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ## the diagonals. They use the columns of @var{v} to replace the diagonals
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
34 ## represented by the vector @var{d}. If the sparse matrix @var{A} is
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
35 ## defined then the diagonals of this matrix are replaced. Otherwise a
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
36 ## matrix of @var{m} by @var{n} is created with the diagonals given by the
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
37 ## columns of @var{v}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
39 ## Negative values of @var{d} represent diagonals below the main diagonal, and
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
40 ## positive values of @var{d} diagonals above the main diagonal.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41 ##
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
42 ## For example:
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43 ##
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
44 ## @example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
45 ## @group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 ## spdiags (reshape (1:12, 4, 3), [-1 0 1], 5, 4)
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
47 ## @result{} 5 10 0 0
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
48 ## 1 6 11 0
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
49 ## 0 2 7 12
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
50 ## 0 0 3 8
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
51 ## 0 0 0 4
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
52 ## @end group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
53 ## @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
54 ##
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
55 ## @seealso{diag}
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56 ## @end deftypefn
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
57
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
58 function [B, d] = spdiags (v, d, m, n)
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
59
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
60 if (nargin < 1 || nargin > 4)
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
61 print_usage ();
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
62 endif
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
63
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
64 if (nargin == 1 || nargin == 2)
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
65 ## extract nonzero diagonals of A into B,d
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
66 [nr, nc] = size (v);
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
67 [i, j] = find (v);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7144
diff changeset
68
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
69 if (nargin == 1)
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
70 ## d contains the active diagonals
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
71 d = unique (j-i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
72 endif
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
73
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
74 ## FIXME: Maybe this could be done faster using [i,j,v] = find (v)
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
75 ## and then massaging the indices i, j. However, some
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
76 ## benchmarking has shown that diag() written in C++ makes
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
77 ## the following code faster even with the for loop.
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
78 Brows = min (nr, nc);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
79 B = zeros (Brows, length (d));
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
80 for k = 1:length (d)
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
81 dn = d(k);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
82 if (dn <= -nr || dn > nc)
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
83 continue;
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
84 endif
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
85 dv = diag (v, dn);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
86 len = rows (dv);
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
87 ## Put sub/super-diagonals in the right place based on matrix size (MxN)
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
88 if (nr >= nc)
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
89 if (dn > 0)
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
90 offset = Brows - len + 1;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
91 B(offset:Brows, k) = dv;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
92 else
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
93 B(1:len, k) = dv;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
94 endif
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
95 else
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
96 if (dn < 0)
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
97 offset = Brows - len + 1;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
98 B(offset:Brows, k) = dv;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
99 else
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
100 B(1:len, k) = dv;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
101 endif
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
102 endif
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
103 endfor
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
104
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
105 elseif (nargin == 3)
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
106 ## Replace specific diagonals d of m with v,d
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
107 [nr, nc] = size (m);
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
108 A = spdiags (m, d);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
109 B = m - spdiags (A, d, nr, nc) + spdiags (v, d, nr, nc);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
110
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
111 else
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
112 ## Create new matrix of size mxn using v,d
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
113 [j, i, v] = find (v);
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
114 if (m >= n)
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
115 offset = max (min (d(:), n-m), 0);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
116 else
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
117 offset = d(:);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
118 endif
14666
1e77f6078692 spdiags.m: correctly treat row vector arguments
David Bateman <dbateman@free.fr>
parents: 14363
diff changeset
119 j = j(:) + offset(i(:));
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
120 i = j - d(:)(i(:));
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
121 idx = i > 0 & i <= m & j > 0 & j <= n;
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
122 B = sparse (i(idx), j(idx), v(idx), m, n);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
123
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 5568
diff changeset
124 endif
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
126 endfunction
12558
1f0243949b77 spdiags.m: Treat empty vector (1x0 or 0x1) the same as diag().
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
127
1f0243949b77 spdiags.m: Treat empty vector (1x0 or 0x1) the same as diag().
Marco Caliari <marco.caliari@univr.it>
parents: 11587
diff changeset
128
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
129 %!test
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
130 %! [B,d] = spdiags (magic (3));
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
131 %! assert (d, [-2 -1 0 1 2]');
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
132 %! assert (B, [4 3 8 0 0
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
133 %! 0 9 5 1 0
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
134 %! 0 0 2 7 6]);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
135 %! B = spdiags (magic (3), [-2 1]);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
136 %! assert (B, [4 0; 0 1; 0 7]);
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
137
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
138 ## Test zero filling for supra- and super-diagonals
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
139 %!test
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
140 %! ## Case 1: M = N
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
141 %! A = sparse (zeros (3,3));
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
142 %! A(1,3) = 13;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
143 %! A(3,1) = 31;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
144 %! [B, d] = spdiags (A);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
145 %! assert (d, [-2 2]');
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
146 %! assert (B, [31 0; 0 0; 0 13]);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
147 %! assert (spdiags (B, d, 3,3), A)
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
148
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
149 %!test
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
150 %! ## Case 1: M > N
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
151 %! A = sparse (zeros (4,3));
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
152 %! A(1,3) = 13;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
153 %! A(3,1) = 31;
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
154 %! [B, d] = spdiags (A);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
155 %! assert (d, [-2 2]');
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
156 %! assert (B, [31 0; 0 0; 0 13]);
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
157 %! assert (spdiags (B, d, 4,3), A)
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
158
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
159 %!test
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
160 %! ## Case 1: M < N
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
161 %! A = sparse (zeros (3,4));
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
162 %! A(1,3) = 13;
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
163 %! A(3,1) = 31;
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
164 %! [B, d] = spdiags (A);
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
165 %! assert (d, [-2 2]');
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
166 %! assert (B, [0 13; 0 0; 31 0]);
18782
5556ddfb841b spdiags.m: Treat sub/super-diagonals the same as Matlab.
Rik <rik@octave.org>
parents: 18150
diff changeset
167 %! assert (spdiags (B, d, 3,4), A)
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
168
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
169 %!assert (spdiags (zeros (1,0),1,1,1), sparse (0))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
170 %!assert (spdiags (zeros (0,1),1,1,1), sparse (0))
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
171 %!assert (spdiags ([0.5 -1 0.5], 0:2, 1, 1), sparse (0.5))
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 14666
diff changeset
172
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
173 ## Test input validation
18150
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
174 %!error spdiags ()
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
175 %!error spdiags (1,2,3,4,5)
190ef1764d30 spdiags.m: Overhaul function for performance (bug #32966).
Rik <rik@octave.org>
parents: 17744
diff changeset
176