Mercurial > octave
annotate scripts/sparse/spfun.m @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 7854d5752dd2 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
3 ## Copyright (C) 2004-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5164 | 7 ## |
7016 | 8 ## This file is part of Octave. |
5164 | 9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
7016 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
7016 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
5164 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5164 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
27 ## @deftypefn {} {@var{y} =} spfun (@var{f}, @var{S}) |
29125 | 28 ## Compute @code{f (@var{S})} for the nonzero elements of @var{S}. |
29 ## | |
30 ## The input function @var{f} is applied only to the nonzero elements of | |
31 ## the input matrix @var{S} which is typically sparse. The function @var{f} | |
32 ## can be passed as a string, function handle, or inline function. | |
33 ## | |
34 ## The output @var{y} is a sparse matrix with the same sparsity structure as | |
35 ## the input @var{S}. @code{spfun} preserves sparsity structure which is | |
36 ## different than simply applying the function @var{f} to the sparse matrix | |
37 ## @var{S} when @code{@var{f} (0) != 0}. | |
38 ## | |
39 ## Example | |
40 ## | |
41 ## Sparsity preserving @code{spfun} versus normal function application | |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
42 ## |
29125 | 43 ## @example |
44 ## @group | |
45 ## S = pi * speye (2,2) | |
46 ## S = | |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
47 ## |
29125 | 48 ## Compressed Column Sparse (rows = 2, cols = 2, nnz = 2 [50%]) |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
49 ## |
29125 | 50 ## (1, 1) -> 3.1416 |
51 ## (2, 2) -> 3.1416 | |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
52 ## |
29125 | 53 ## y = spfun (@@cos, S) |
54 ## y = | |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
55 ## |
29125 | 56 ## Compressed Column Sparse (rows = 2, cols = 2, nnz = 2 [50%]) |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
57 ## |
29125 | 58 ## (1, 1) -> -1 |
59 ## (2, 2) -> -1 | |
60 ## @end group | |
61 ## | |
62 ## @group | |
63 ## y = cos (S) | |
64 ## y = | |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
65 ## |
29125 | 66 ## Compressed Column Sparse (rows = 2, cols = 2, nnz = 4 [100%]) |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
67 ## |
29125 | 68 ## (1, 1) -> -1 |
69 ## (2, 1) -> 1 | |
70 ## (1, 2) -> 1 | |
71 ## (2, 2) -> -1 | |
72 ## | |
73 ## @end group | |
74 ## @end example | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
75 ## @seealso{arrayfun, cellfun, structfun} |
5164 | 76 ## @end deftypefn |
77 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
78 function y = spfun (f, S) |
6498 | 79 |
5164 | 80 if (nargin != 2) |
6046 | 81 print_usage (); |
5164 | 82 endif |
83 | |
29125 | 84 if (! isnumeric (S)) |
85 error ("spfun: S must be numeric"); | |
86 endif | |
87 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
88 [i, j, v] = find (S); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
89 [m, n] = size (S); |
5164 | 90 |
29125 | 91 y = sparse (i, j, feval (f, v), m, n); |
5164 | 92 |
93 endfunction | |
94 | |
95 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
96 %!assert (spfun ("exp", [1,2;3,0]), sparse ([exp(1),exp(2);exp(3),0])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
97 %!assert (spfun ("exp", sparse ([1,2;3,0])), sparse ([exp(1),exp(2);exp(3),0])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 %!assert (spfun (@exp, [1,2;3,0]), sparse ([exp(1),exp(2);exp(3),0])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %!assert (spfun (@exp, sparse ([1,2;3,0])), sparse ([exp(1),exp(2);exp(3),0])) |
29125 | 100 |
101 ## Test input validation | |
102 %!error <Invalid call> spfun () | |
103 %!error <Invalid call> spfun (@cos) | |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
104 %!error <S must be numeric> spfun (@cos, {1}) |
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29125
diff
changeset
|
105 %!error <S must be numeric> spfun (@cos, "FooBar") |