Mercurial > hg > octave-nkf
annotate scripts/sparse/spfun.m @ 9051:1bf0ce0930be
Grammar check TexInfo in all .m files
Cleanup documentation sources to follow a few consistent rules.
Spellcheck was NOT done. (but will be in another changeset)
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 27 Mar 2009 22:31:03 -0700 |
parents | eb63fbe60fab |
children | 16f53d29049f |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2004, 2005, 2006, 2007, 2008 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{y} =} spfun (@var{f},@var{x}) | |
21 ## Compute @code{f(@var{x})} for the non-zero values of @var{x}. | |
22 ## This results in a sparse matrix with the same structure as | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## @var{x}. The function @var{f} can be passed as a string, a |
5164 | 24 ## function handle or an inline function. |
25 ## @end deftypefn | |
26 | |
6498 | 27 function t = spfun (f, s) |
28 | |
5164 | 29 if (nargin != 2) |
6046 | 30 print_usage (); |
5164 | 31 endif |
32 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7151
diff
changeset
|
33 [i, j, v] = find (s); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7151
diff
changeset
|
34 [m, n] = size (s); |
5164 | 35 |
6220 | 36 if (isa (f, "function_handle") || isa (f, "inline function")) |
6498 | 37 t = sparse (i, j, f(v), m, n); |
5164 | 38 else |
6498 | 39 t = sparse(i, j, feval (f, v), m, n); |
5164 | 40 endif |
41 | |
42 endfunction | |
43 | |
44 %!assert(spfun('exp',[1,2;3,0]),sparse([exp(1),exp(2);exp(3),0])) | |
45 %!assert(spfun('exp',sparse([1,2;3,0])),sparse([exp(1),exp(2);exp(3),0])) | |
46 %!assert(spfun(@exp,[1,2;3,0]),sparse([exp(1),exp(2);exp(3),0])) | |
47 %!assert(spfun(@exp,sparse([1,2;3,0])),sparse([exp(1),exp(2);exp(3),0])) | |
48 |