Mercurial > octave-nkf
annotate scripts/set/private/validsetargs.m @ 20473:e59a44fa74ff
union.m: Matlab compatible output when mixed input and one is empty (bug #45685).
* union.m: add BIST tests for mixed cell/matrix inputs.
* validasetargs.m: Check for cases of cellstr and empty array and coerce empty
array into cellstr.
author | Juan Pablo Carbajal <ajuanpi+dev@gmail.com> |
---|---|
date | Mon, 03 Aug 2015 23:22:14 +0200 |
parents | 00e31f316a3a |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
1 ## Copyright (C) 2000-2015 Paul Kienzle |
11523 | 2 ## Copyright (C) 2009-2010 Jaroslav Hajek |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 ## |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 ## This file is part of Octave. |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 ## |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 ## Octave is free software; you can redistribute it and/or modify it |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 ## your option) any later version. |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 ## |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 ## Octave is distributed in the hope that it will be useful, but |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 ## General Public License for more details. |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 ## |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public License |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 ## along with Octave; see the file COPYING. If not, see |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 ## Validate arguments for binary set operation. |
19037
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
21 |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
22 function [x, y] = validsetargs (caller, x, y, byrows_arg) |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 |
19734
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19731
diff
changeset
|
24 isallowedarraytype = @(x) isnumeric (x) || ischar (x) || islogical (x); |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19731
diff
changeset
|
25 |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 if (nargin == 3) |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 icx = iscellstr (x); |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 icy = iscellstr (y); |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 if (icx || icy) |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 if (icx && ischar (y)) |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 y = cellstr (y); |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 elseif (icy && ischar (x)) |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 x = cellstr (x); |
20473
e59a44fa74ff
union.m: Matlab compatible output when mixed input and one is empty (bug #45685).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
19734
diff
changeset
|
34 elseif (icy && isempty (x)) |
e59a44fa74ff
union.m: Matlab compatible output when mixed input and one is empty (bug #45685).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
19734
diff
changeset
|
35 x = {}; |
e59a44fa74ff
union.m: Matlab compatible output when mixed input and one is empty (bug #45685).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
19734
diff
changeset
|
36 elseif (icx && isempty (y)) |
e59a44fa74ff
union.m: Matlab compatible output when mixed input and one is empty (bug #45685).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
19734
diff
changeset
|
37 y = {}; |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 elseif (! (icx && icy)) |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 error ("%s: cell array of strings cannot be combined with a nonstring value", caller); |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 endif |
19734
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19731
diff
changeset
|
41 elseif (! (isallowedarraytype (x) && isallowedarraytype (y))) |
19037
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 error ("%s: A and B must be arrays or cell arrays of strings", caller); |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 endif |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 elseif (nargin == 4) |
19037
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
45 if (! strcmpi (byrows_arg, "rows")) |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 error ("%s: invalid option: %s", caller, byrows_arg); |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 endif |
19037
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
49 if (iscell (x) || iscell (y)) |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 error ('%s: cells not supported with "rows"', caller); |
19734
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19731
diff
changeset
|
51 elseif (! (isallowedarraytype (x) && isallowedarraytype (y))) |
19037
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 error ("%s: A and B must be arrays or cell arrays of strings", caller); |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 else |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 if (ndims (x) > 2 || ndims (y) > 2) |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 error ('%s: A and B must be 2-dimensional matrices for "rows"', caller); |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 elseif (columns (x) != columns (y) && ! (isempty (x) || isempty (y))) |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 error ("%s: number of columns in A and B must match", caller); |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 endif |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 endif |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 endif |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 |
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
63 |
19037
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 ## %!tests for function are in union.m |