Mercurial > hg > octave-nkf
annotate libinterp/octave-value/ov-bool-mat.cc @ 18718:51a0d1c1023c stable
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Make parameter list case-insensitive.
Return empty matrix rather than empty cell list on failure.
* listdlg.m: Use for loop to index into java array to get octave value.
Use strcmpi to parse input options. Correctly return an empty matrix
rather than empty list if dialog fails.
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Sat, 22 Mar 2014 16:04:32 +0100 |
parents | ea0d4dea1a17 |
children | f958e8cd6348 |
rev | line source |
---|---|
2871 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
2871 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2871 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2871 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3503 | 28 #include <iostream> |
4726 | 29 #include <vector> |
2901 | 30 |
2871 | 31 #include "lo-ieee.h" |
32 #include "mx-base.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
33 #include "oct-locbuf.h" |
2871 | 34 |
9852
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9850
diff
changeset
|
35 #include "defun.h" |
2871 | 36 #include "gripes.h" |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
37 #include "mxarray.h" |
2871 | 38 #include "oct-obj.h" |
39 #include "ops.h" | |
3219 | 40 #include "ov-base.h" |
41 #include "ov-base-mat.h" | |
42 #include "ov-base-mat.cc" | |
2871 | 43 #include "ov-bool.h" |
44 #include "ov-bool-mat.h" | |
45 #include "ov-re-mat.h" | |
46 #include "pr-output.h" | |
47 | |
4687 | 48 #include "byte-swap.h" |
49 #include "ls-oct-ascii.h" | |
50 #include "ls-hdf5.h" | |
51 #include "ls-utils.h" | |
52 | |
4513 | 53 template class octave_base_matrix<boolNDArray>; |
2871 | 54 |
3219 | 55 DEFINE_OCTAVE_ALLOCATOR (octave_bool_matrix); |
2871 | 56 |
4612 | 57 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_bool_matrix, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
58 "bool matrix", "logical"); |
2871 | 59 |
5759 | 60 static octave_base_value * |
61 default_numeric_conversion_function (const octave_base_value& a) | |
2871 | 62 { |
63 CAST_CONV_ARG (const octave_bool_matrix&); | |
64 | |
4668 | 65 return new octave_matrix (NDArray (v.bool_array_value ())); |
2871 | 66 } |
67 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
68 octave_base_value::type_conv_info |
2871 | 69 octave_bool_matrix::numeric_conversion_function (void) const |
70 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
71 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
72 octave_matrix::static_type_id ()); |
2871 | 73 } |
74 | |
5759 | 75 octave_base_value * |
2871 | 76 octave_bool_matrix::try_narrowing_conversion (void) |
77 { | |
5759 | 78 octave_base_value *retval = 0; |
2871 | 79 |
4513 | 80 if (matrix.ndims () == 2) |
81 { | |
82 boolMatrix bm = matrix.matrix_value (); | |
2871 | 83 |
5275 | 84 octave_idx_type nr = bm.rows (); |
85 octave_idx_type nc = bm.cols (); | |
4513 | 86 |
87 if (nr == 1 && nc == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 retval = new octave_bool (bm (0, 0)); |
4513 | 89 } |
2871 | 90 |
91 return retval; | |
92 } | |
93 | |
94 double | |
95 octave_bool_matrix::double_value (bool) const | |
96 { | |
4102 | 97 double retval = lo_ieee_nan_value (); |
2871 | 98 |
4455 | 99 if (rows () > 0 && columns () > 0) |
100 { | |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
101 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 "bool matrix", "real scalar"); |
4455 | 103 |
104 retval = matrix (0, 0); | |
105 } | |
2871 | 106 else |
107 gripe_invalid_conversion ("bool matrix", "real scalar"); | |
108 | |
109 return retval; | |
110 } | |
111 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
112 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 octave_bool_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
119 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 "bool matrix", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 gripe_invalid_conversion ("bool matrix", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
127 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
129 |
2871 | 130 Complex |
131 octave_bool_matrix::complex_value (bool) const | |
132 { | |
4102 | 133 double tmp = lo_ieee_nan_value (); |
134 | |
135 Complex retval (tmp, tmp); | |
2871 | 136 |
4455 | 137 if (rows () > 0 && columns () > 0) |
138 { | |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
139 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
140 "bool matrix", "complex scalar"); |
4455 | 141 |
142 retval = matrix (0, 0); | |
143 } | |
2871 | 144 else |
145 gripe_invalid_conversion ("bool matrix", "complex scalar"); | |
146 | |
147 return retval; | |
148 } | |
149 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
151 octave_bool_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
152 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
153 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
154 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
155 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
156 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
157 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
158 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
159 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 "bool matrix", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
161 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
162 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
163 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
164 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
165 gripe_invalid_conversion ("bool matrix", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
166 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
167 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
168 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
169 |
4457 | 170 octave_value |
5279 | 171 octave_bool_matrix::convert_to_str_internal (bool pad, bool force, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 char type) const |
4457 | 173 { |
4844 | 174 octave_value tmp = octave_value (array_value ()); |
5279 | 175 return tmp.convert_to_str (pad, force, type); |
4457 | 176 } |
177 | |
4643 | 178 void |
179 octave_bool_matrix::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 bool pr_as_read_syntax) const |
4643 | 181 { |
182 octave_print_internal (os, matrix, pr_as_read_syntax, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
183 current_print_indent_level ()); |
4643 | 184 } |
185 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
186 bool |
6974 | 187 octave_bool_matrix::save_ascii (std::ostream& os) |
4687 | 188 { |
189 dim_vector d = dims (); | |
190 if (d.length () > 2) | |
191 { | |
192 NDArray tmp = array_value (); | |
193 os << "# ndims: " << d.length () << "\n"; | |
194 | |
5275 | 195 for (int i = 0; i < d.length (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
196 os << " " << d (i); |
4687 | 197 |
198 os << "\n" << tmp; | |
199 } | |
200 else | |
201 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
202 // Keep this case, rather than use generic code above for backward |
4687 | 203 // compatiability. Makes load_ascii much more complex!! |
204 os << "# rows: " << rows () << "\n" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 << "# columns: " << columns () << "\n"; |
4687 | 206 |
207 Matrix tmp = matrix_value (); | |
208 | |
209 os << tmp; | |
210 } | |
211 | |
212 return true; | |
213 } | |
214 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
215 bool |
4687 | 216 octave_bool_matrix::load_ascii (std::istream& is) |
217 { | |
218 bool success = true; | |
219 | |
5099 | 220 string_vector keywords (2); |
4687 | 221 |
5099 | 222 keywords[0] = "ndims"; |
223 keywords[1] = "rows"; | |
4687 | 224 |
5099 | 225 std::string kw; |
5275 | 226 octave_idx_type val = 0; |
4687 | 227 |
5099 | 228 if (extract_keyword (is, keywords, kw, val, true)) |
4687 | 229 { |
5099 | 230 if (kw == "ndims") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
231 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
232 int mdims = static_cast<int> (val); |
4687 | 233 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
234 if (mdims >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 dv.resize (mdims); |
5099 | 238 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 for (int i = 0; i < mdims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 is >> dv(i); |
5099 | 241 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 boolNDArray btmp (dv); |
6717 | 245 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 if (btmp.is_empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 matrix = btmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
248 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
250 NDArray tmp(dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 is >> tmp; |
5099 | 252 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
253 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
255 for (octave_idx_type i = 0; i < btmp.nelem (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
256 btmp.elem (i) = (tmp.elem (i) != 0.); |
6717 | 257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
258 matrix = btmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
260 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
262 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
263 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
264 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
265 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
266 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
267 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
269 error ("load: failed to extract dimensions"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
270 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
272 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
273 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
274 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 error ("load: failed to extract number of dimensions"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
278 } |
5099 | 279 else if (kw == "rows") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
281 octave_idx_type nr = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 octave_idx_type nc = 0; |
5099 | 283 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 if (nr > 0 && nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 Matrix tmp (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
289 is >> tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
290 if (is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 boolMatrix btmp (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
295 btmp.elem (i,j) = (tmp.elem (i, j) != 0.); |
6717 | 296 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 matrix = btmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
304 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 else if (nr == 0 || nc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 matrix = boolMatrix (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 error ("load: failed to extract number of rows and columns"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 } |
5099 | 316 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
317 panic_impossible (); |
5099 | 318 } |
319 else | |
320 { | |
321 error ("load: failed to extract number of rows and columns"); | |
322 success = false; | |
4687 | 323 } |
324 | |
325 return success; | |
326 } | |
327 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
328 bool |
4687 | 329 octave_bool_matrix::save_binary (std::ostream& os, bool& /* save_as_floats */) |
330 { | |
331 | |
332 dim_vector d = dims (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14469
diff
changeset
|
333 if (d.length () < 1) |
4687 | 334 return false; |
335 | |
336 // Use negative value for ndims to differentiate with old format!! | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14469
diff
changeset
|
337 int32_t tmp = - d.length (); |
5760 | 338 os.write (reinterpret_cast<char *> (&tmp), 4); |
5275 | 339 for (int i = 0; i < d.length (); i++) |
4687 | 340 { |
341 tmp = d(i); | |
5760 | 342 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 343 } |
344 | |
345 boolNDArray m = bool_array_value (); | |
346 bool *mtmp = m.fortran_vec (); | |
5275 | 347 octave_idx_type nel = m.nelem (); |
4687 | 348 OCTAVE_LOCAL_BUFFER (char, htmp, nel); |
349 | |
5275 | 350 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 351 htmp[i] = (mtmp[i] ? 1 : 0); |
352 | |
353 os.write (htmp, nel); | |
354 | |
355 return true; | |
356 } | |
357 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
358 bool |
4687 | 359 octave_bool_matrix::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 oct_mach_info::float_format /* fmt */) |
4687 | 361 { |
5828 | 362 int32_t mdims; |
5760 | 363 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 364 return false; |
365 if (swap) | |
4944 | 366 swap_bytes<4> (&mdims); |
4687 | 367 if (mdims >= 0) |
368 return false; | |
369 | |
370 // mdims is negative for consistency with other matrices, where it is | |
371 // negative to allow the positive value to be used for rows/cols for | |
372 // backward compatibility | |
373 mdims = - mdims; | |
5828 | 374 int32_t di; |
4687 | 375 dim_vector dv; |
376 dv.resize (mdims); | |
377 | |
378 for (int i = 0; i < mdims; i++) | |
379 { | |
5760 | 380 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 return false; |
4687 | 382 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
383 swap_bytes<4> (&di); |
4687 | 384 dv(i) = di; |
385 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
386 |
5157 | 387 // Convert an array with a single dimension to be a row vector. |
388 // Octave should never write files like this, other software | |
389 // might. | |
390 | |
391 if (mdims == 1) | |
392 { | |
393 mdims = 2; | |
394 dv.resize (mdims); | |
395 dv(1) = dv(0); | |
396 dv(0) = 1; | |
397 } | |
398 | |
5275 | 399 octave_idx_type nel = dv.numel (); |
4687 | 400 OCTAVE_LOCAL_BUFFER (char, htmp, nel); |
401 if (! is.read (htmp, nel)) | |
402 return false; | |
403 boolNDArray m(dv); | |
404 bool *mtmp = m.fortran_vec (); | |
5275 | 405 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 406 mtmp[i] = (htmp[i] ? 1 : 0); |
407 matrix = m; | |
408 | |
409 return true; | |
410 } | |
411 | |
412 #if defined (HAVE_HDF5) | |
4944 | 413 |
4687 | 414 bool |
415 octave_bool_matrix::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
416 bool /* save_as_floats */) |
4687 | 417 { |
4837 | 418 dim_vector dv = dims (); |
419 int empty = save_hdf5_empty (loc_id, name, dv); | |
420 if (empty) | |
4805 | 421 return (empty > 0); |
422 | |
4837 | 423 int rank = dv.length (); |
4687 | 424 hid_t space_hid = -1, data_hid = -1; |
425 bool retval = true; | |
426 boolNDArray m = bool_array_value (); | |
427 | |
4805 | 428 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
429 | |
4687 | 430 // Octave uses column-major, while HDF5 uses row-major ordering |
4805 | 431 for (int i = 0; i < rank; i++) |
4837 | 432 hdims[i] = dv (rank-i-1); |
4687 | 433 |
4815 | 434 space_hid = H5Screate_simple (rank, hdims, 0); |
4687 | 435 if (space_hid < 0) return false; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
436 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
437 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_HBOOL, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
438 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
439 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
440 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_HBOOL, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
441 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
442 #endif |
4687 | 443 if (data_hid < 0) |
444 { | |
445 H5Sclose (space_hid); | |
446 return false; | |
447 } | |
448 | |
5275 | 449 octave_idx_type nel = m.nelem (); |
4687 | 450 bool *mtmp = m.fortran_vec (); |
6276 | 451 OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nel); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
452 |
5275 | 453 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 454 htmp[i] = mtmp[i]; |
455 | |
456 retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
457 H5P_DEFAULT, htmp) >= 0; |
4687 | 458 |
459 H5Dclose (data_hid); | |
460 H5Sclose (space_hid); | |
4837 | 461 |
4687 | 462 return retval; |
463 } | |
464 | |
465 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9852
diff
changeset
|
466 octave_bool_matrix::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 467 { |
4837 | 468 bool retval = false; |
469 | |
4805 | 470 dim_vector dv; |
471 int empty = load_hdf5_empty (loc_id, name, dv); | |
472 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
473 matrix.resize (dv); |
4837 | 474 if (empty) |
475 return (empty > 0); | |
4805 | 476 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
477 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
478 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
479 #else |
4687 | 480 hid_t data_hid = H5Dopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
481 #endif |
4687 | 482 hid_t space_id = H5Dget_space (data_hid); |
483 | |
484 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
485 |
4687 | 486 if (rank < 1) |
487 { | |
488 H5Dclose (data_hid); | |
489 return false; | |
490 } | |
491 | |
492 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
493 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
494 | |
495 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
496 | |
497 // Octave uses column-major, while HDF5 uses row-major ordering | |
498 if (rank == 1) | |
499 { | |
500 dv.resize (2); | |
501 dv(0) = 1; | |
502 dv(1) = hdims[0]; | |
503 } | |
504 else | |
505 { | |
506 dv.resize (rank); | |
4815 | 507 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 dv(j) = hdims[i]; |
4687 | 509 } |
510 | |
5275 | 511 octave_idx_type nel = dv.numel (); |
6276 | 512 OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nel); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
513 if (H5Dread (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, H5P_DEFAULT, htmp) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
514 >= 0) |
4687 | 515 { |
516 retval = true; | |
517 | |
518 boolNDArray btmp (dv); | |
5275 | 519 for (octave_idx_type i = 0; i < nel; i++) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
520 btmp.elem (i) = htmp[i]; |
4687 | 521 |
522 matrix = btmp; | |
523 } | |
524 | |
525 H5Dclose (data_hid); | |
4837 | 526 |
4687 | 527 return retval; |
528 } | |
4944 | 529 |
4687 | 530 #endif |
531 | |
5900 | 532 mxArray * |
533 octave_bool_matrix::as_mxArray (void) const | |
534 { | |
535 mxArray *retval = new mxArray (mxLOGICAL_CLASS, dims (), mxREAL); | |
536 | |
537 bool *pr = static_cast<bool *> (retval->get_data ()); | |
538 | |
6686 | 539 mwSize nel = numel (); |
5900 | 540 |
541 const bool *p = matrix.data (); | |
542 | |
6686 | 543 for (mwIndex i = 0; i < nel; i++) |
5900 | 544 pr[i] = p[i]; |
545 | |
546 return retval; | |
547 } | |
548 | |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
549 DEFUN (logical, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
550 "-*- texinfo -*-\n\ |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
551 @deftypefn {Built-in Function} {} logical (@var{x})\n\ |
18601
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
552 Convert the numeric object @var{x} to logical type.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
553 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
554 Any non-zero values will be converted to true (1) while zero values\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
555 will be converted to false (0). The non-numeric value NaN cannot be\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
556 converted and will produce an error.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
557 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
558 Compatibility Note: Octave accepts complex values as input, whereas\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
559 @sc{matlab} issues an error.\n\ |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
560 @seealso{double, single, char}\n\ |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
561 @end deftypefn") |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
562 { |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
563 octave_value retval; |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
564 |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
565 if (args.length () == 1) |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
566 { |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
567 octave_value arg = args(0); |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
568 if (arg.is_bool_type ()) |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
569 retval = arg; |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
570 else if (arg.is_numeric_type ()) |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
571 { |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
572 if (arg.is_sparse_type ()) |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
573 retval = arg.sparse_bool_matrix_value (); |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
574 else if (arg.is_scalar_type ()) |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
575 retval = arg.bool_value (); |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
576 else |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
577 retval = arg.bool_array_value (); |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
578 } |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
579 else |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
580 gripe_wrong_type_arg ("logical", arg); |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
581 } |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
582 else |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
583 print_usage (); |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
584 |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
585 return retval; |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
586 } |
12645
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
587 |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
588 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
589 %!test |
12645
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
590 %! m = eye (2) != 0; |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
591 %! s = !0; |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
592 %! c = {"double", "single", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "logical"}; |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
593 %! for i = 1:numel (c) |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
594 %! assert (logical (eye (2, c{i})), m) |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
595 %! assert (logical (eye (1, c{i})), s) |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
596 %! endfor |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
597 */ |