annotate scripts/general/common_size.m @ 10791:3140cb7a05a1

Add spellchecker scripts for Octave and run spellcheck of documentation interpreter/doccheck: New directory for spelling/grammar scripts. interpreter/doccheck/README: Instructions for using scripts. interpreter/doccheck/spellcheck: Script to spellcheck a Texinfo file. interpreter/doccheck/aspell.conf: GNU Aspell configuration file for Octave documentation. interpreter/doccheck/aspell-octave.en.pws: Private Aspell dictionary. interpreter/doccheck/add_to_aspell_dict: Script to add new Octave-specific words to private Aspell dictionary. interpreter/octave.texi: New @nospell macro which forces Aspell to ignore the word marked by the macro. interpreter/mk_doc_cache.m: Skip new @nospell macro when building doc_cache.
author Rik <octave@nomad.inbox5.com>
date Sat, 17 Jul 2010 19:53:01 -0700
parents 7fbdeaa9b0e0
children 693e22af08ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1995, 1996, 1999, 2000, 2002, 2004, 2005, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
2 ## Kurt Hornik
9477
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
3 ## Copyright (C) 2009 VZLU Prague
10034
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
4 ## Copyright (C) 2009 Jaroslav Hajek
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
5 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
6 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
7 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
8 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
9 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
10 ## 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
11 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
12 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
13 ## Octave is distributed in the hope that it will be useful, but
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
14 ## WITHOUT ANY WARRANTY; without even the implied warranty of
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
16 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
17 ##
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
18 ## 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
19 ## 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
20 ## <http://www.gnu.org/licenses/>.
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
21
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
22 ## -*- texinfo -*-
6547
4fb053f24fd6 [project @ 2007-04-19 21:47:40 by jwe]
jwe
parents: 5428
diff changeset
23 ## @deftypefn {Function File} {[@var{err}, @var{y1}, @dots{}] =} common_size (@var{x1}, @dots{})
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
24 ## Determine if all input arguments are either scalar or of common
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
25 ## size. If so, @var{err} is zero, and @var{yi} is a matrix of the
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
26 ## common size with all entries equal to @var{xi} if this is a scalar or
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
27 ## @var{xi} otherwise. If the inputs cannot be brought to a common size,
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10043
diff changeset
28 ## @var{err} is 1, and @var{yi} is @var{xi}. For example,
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
29 ##
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
30 ## @example
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
31 ## @group
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
32 ## [errorcode, a, b] = common_size ([1 2; 3 4], 5)
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
33 ## @result{} errorcode = 0
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
34 ## @result{} a = [ 1, 2; 3, 4 ]
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
35 ## @result{} b = [ 5, 5; 5, 5 ]
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
36 ## @end group
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
37 ## @end example
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
38 ##
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
39 ## @noindent
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
40 ## This is useful for implementing functions where arguments can either
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
41 ## be scalars or of common size.
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2539
diff changeset
42 ## @end deftypefn
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
43
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
44 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
45 ## Created: 15 October 1994
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
46 ## Adapted-By: jwe
9477
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
47 ## Optimized-By: Jaroslav Hajek
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
48
3979
e0b7a493e5a8 [project @ 2002-07-10 17:45:34 by jwe]
jwe
parents: 3922
diff changeset
49 function [errorcode, varargout] = common_size (varargin)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
50
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
51 if (nargin < 2)
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
52 error ("common_size: only makes sense if nargin >= 2");
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
53 endif
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
54
9477
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
55 ## Find scalar args.
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
56 nscal = cellfun ("numel", varargin) != 1;
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
57
9477
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
58 i = find (nscal, 1);
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
59
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
60 if (isempty (i))
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
61 errorcode = 0;
3979
e0b7a493e5a8 [project @ 2002-07-10 17:45:34 by jwe]
jwe
parents: 3922
diff changeset
62 varargout = varargin;
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
63 else
9477
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
64 match = cellfun (@size_equal, varargin, varargin(i));
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
65 if (any (nscal &! match))
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
66 errorcode = 1;
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
67 varargout = varargin;
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
68 else
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
69 errorcode = 0;
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
70 if (nargout > 1)
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
71 scal = !nscal;
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
72 varargout = varargin;
10034
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
73 if (any (nscal))
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
74 ## This could also be achieved by cellfun (@repmat, ...), but repmat is an
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
75 ## m-function and hence still carries interpreter overhead. Further,
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
76 ## cellfun is slightly optimized for the case used below.
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
77 uo = "uniformoutput";
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
78 dims = size (varargin{find (nscal, 1)});
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
79 subs = substruct ("()", arrayfun (@ones, 1, dims, uo, false));
10043
7fbdeaa9b0e0 fix common_size optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10034
diff changeset
80 varargout(scal) = cellfun ("subsref", varargin(scal), {subs}, uo, false);
10034
439c7a9d0fca optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 9477
diff changeset
81 endif
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
82 endif
9477
4d3d90253e8a optimize common_size
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
83 endif
2539
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
84 endif
1dca28c213f0 [project @ 1996-11-19 23:54:48 by jwe]
jwe
parents:
diff changeset
85 endfunction