Mercurial > hg > octave-lyh
annotate src/ov-null-mat.cc @ 14383:07c55bceca23 stable
Fix guarded_eval() subfunction in fminunc (bug #35534).
* fminunc.m: Fix guarded_eval() subfunction in fminunc (bug #35534).
author | Olaf Till <olaf.till@uni-jena.de> |
---|---|
date | Wed, 15 Feb 2012 14:44:37 +0100 |
parents | 72c96de7a403 |
children | b76f0740940e |
rev | line source |
---|---|
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 /* |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12814
diff
changeset
|
3 Copyright (C) 2008-2012 Jaroslav Hajek |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 option) any later version. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 for more details. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 */ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
24 #include <config.h> |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 #endif |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 #include "ov-null-mat.h" |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 #include "ops.h" |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 #include "defun.h" |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_null_matrix, "null_matrix", "double"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 const octave_value octave_null_matrix::instance (new octave_null_matrix ()); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 static octave_base_value * |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 default_null_matrix_numeric_conversion_function (const octave_base_value& a) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 { |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8345
diff
changeset
|
38 // The cast is not necessary? |
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8345
diff
changeset
|
39 // CAST_CONV_ARG (const octave_null_matrix&); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 return a.empty_clone (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
44 octave_base_value::type_conv_info |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 octave_null_matrix::numeric_conversion_function (void) const |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
47 return octave_base_value::type_conv_info (default_null_matrix_numeric_conversion_function, |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
48 octave_matrix::static_type_id ()); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_null_str, "null_string", "char"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 const octave_value octave_null_str::instance (new octave_null_str ()); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 static octave_base_value * |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 default_null_str_numeric_conversion_function (const octave_base_value& a) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 { |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8345
diff
changeset
|
58 // The cast is not necessary? |
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8345
diff
changeset
|
59 // CAST_CONV_ARG (const octave_null_str&); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 return a.empty_clone (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
64 octave_base_value::type_conv_info |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 octave_null_str::numeric_conversion_function (void) const |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
67 return octave_base_value::type_conv_info (default_null_str_numeric_conversion_function, |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
68 octave_char_matrix_str::static_type_id ()); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_null_sq_str, "null_sq_string", "char"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
72 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
73 const octave_value octave_null_sq_str::instance (new octave_null_sq_str ()); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
74 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
75 static octave_base_value * |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 default_null_sq_str_numeric_conversion_function (const octave_base_value& a) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 { |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8345
diff
changeset
|
78 // The cast is not necessary? |
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8345
diff
changeset
|
79 // CAST_CONV_ARG (const octave_null_sq_str&); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
80 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
81 return a.empty_clone (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
82 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
83 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
84 octave_base_value::type_conv_info |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
85 octave_null_sq_str::numeric_conversion_function (void) const |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
86 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
87 return octave_base_value::type_conv_info (default_null_sq_str_numeric_conversion_function, |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
88 octave_char_matrix_sq_str::static_type_id ()); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
89 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
90 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
91 DEFUN (isnull, args, , |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
92 "-*- texinfo -*-\n\ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
93 @deftypefn {Built-in Function} {} isnull (@var{x})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
94 Return true if @var{x} is a special null matrix, string, or single quoted\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
95 string. Indexed assignment with such a value on the right-hand side should\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
96 delete array elements. This function should be used when overloading\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
97 indexed assignment for user-defined classes instead of @code{isempty}, to\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
98 distinguish the cases:\n\ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
99 @table @asis\n\ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
100 @item @code{A(I) = []}\n\ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
101 This should delete elements if @code{I} is nonempty.\n\ |
10840 | 102 \n\ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
103 @item @code{X = []; A(I) = X}\n\ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
104 This should give an error if @code{I} is nonempty.\n\ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
105 @end table\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
106 @seealso{isempty, isindex}\n\ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
107 @end deftypefn") |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
108 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
109 octave_value retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
110 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
111 int nargin = args.length (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
112 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
113 if (nargin == 1 && args(0).is_defined ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
114 retval = args(0).is_null_value (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
115 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
116 print_usage (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
117 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
118 return retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
119 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
120 |
12814
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
121 /* |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
122 |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
123 %!assert (isnull ([]), true) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
124 %!assert (isnull ([1]), false) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
125 %!assert (isnull (zeros (0,3)), false) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
126 %!assert (isnull (""), true) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
127 %!assert (isnull ("A"), false) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
128 %!assert (isnull (''), true) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
129 %!assert (isnull ('A'), false) |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
130 %!test |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
131 %! x = []; |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
132 %! assert (isnull (x), false); |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
133 |
ce1fb93d884d
codesprint: Add tests for isnull()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
134 */ |