Mercurial > octave
annotate libinterp/octave-value/ov-bool-mat.cc @ 21102:dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
* graphics.cc (err_set_invalid): Add OCTAVE_NORETURN attribute.
* graphisc.cc: Rename gripe_set_invalid to err_set_invalid.
* jit-typeinfo.cc (err_bad_result): Rename from gripe_bad_result.
* load-save.cc (err_file_open): Rename from gripe_file_open.
* ls-mat5.cc (warn_dim_too_large): Rename from gripe_dim_too_large.
* oct-stream.cc (err_invalid_file_id): Rename from gripe_invalid_file_id.
* txt-eng-ft.cc (warn_missing_glyph, warn_glyph_render): Rename from
gripe_missing_glyph, gripe_glyph_render.
* xpow.cc: Add FIXME about strange gripe_failed_diagonalization function.
* ov-base-int.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc,
ov-class.cc, ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc,
ov-str-mat.cc, ov-struct.cc
(warn_load, warn_save):
ov-base.cc (warn_load, warn_save, err_indexed_assignment,
err_assign_conversion_failed, err_no_conversion): Rename from gripe_XXX
version.
* ov-base.h (warn_load, warn_save): Rename from gripe_load, gripe_save.
* ov-classdef.cc (err_method_access, err_property_access): Rename from
gripe_method_access, gripe_property_access.
* ov-classdef.h (err_invalid_object): Rename from gripe_invalid_object.
* ov-oncleanup.h (gripe_internal): Delete function. Place single calling
instance directly in code.
* ov.cc (err_binary_op, err_binary_op_conv, err_unary_op, err_unary_op_conv,
err_unary_op_conversion_failed): Add OCTAVE_NORETURN attribute. Rename from
gripe_XXX.
* ov.cc (err_cat_op, err_cat_op_conv, ): Rename from gripe_XXX.
* lex.h (warn_single_quote_string, warn_language_extension,
maybe_warn_language_extension_comment, warn_language_extension_continuation,
warn_language_extension_operator): Rename from gripe_XXX.
* lex.ll (warn_single_quote_string, warn_language_extension,
maybe_warn_language_extension_comment, warn_language_extension_continuation,
warn_language_extension_operator): Rename from gripe_XXX.
* pt-check.cc (errmsg): Rename from gripe.
* pt-check.h (errmsg): Add OCTAVE_NORETURN attribute. Rename from gripe.
* PermMatrix.cc (err_invalid_permutation): Add OCTAVE_NORETURN attribute.
Rename from gripe_invalid_permutation.
* idx-vector.cc (err_invalid_range): Add OCTAVE_NORETURN attribute.
Rename from gripe_invalid_range.
liboctave/numeric/lo-specfun.cc (err_betainc_nonconformant): Add
OCTAVE_NORETURN attribute. Rename from gripe_betainc_nonconformant.
* oct-group.cc (err_invalid): New static function.
* oct-group.h (gripe_invalid): Delete private function.
* oct-passwd.cc (err_invalid): New static function.
* oct-passwd.h (gripe_invalid): Delete private function.
* data-conv.cc (err_unrecognized_float_fmt): Add OCTAVE_NORETURN attribute.
Rename from gripe_unrecognized_float_fmt.
* lo-cutils.c (warn_missing_wait_macro): Rename from gripe_missing_wait_macro.
* unwind-prot.cc (err_unhandled_exception): Rename from gripe_exception.
* unwind-prot.h (err_unhandled_exception): Rename from gripe_exception.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Jan 2016 21:06:26 -0800 |
parents | e39e05d90788 |
children | 3ac9f47fb04b |
rev | line source |
---|---|
2871 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1996-2015 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" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
36 #include "errwarn.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" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
38 #include "ovl.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
39 #include "oct-hdf5.h" |
2871 | 40 #include "ops.h" |
3219 | 41 #include "ov-base.h" |
42 #include "ov-base-mat.h" | |
43 #include "ov-base-mat.cc" | |
2871 | 44 #include "ov-bool.h" |
45 #include "ov-bool-mat.h" | |
46 #include "ov-re-mat.h" | |
47 #include "pr-output.h" | |
48 | |
4687 | 49 #include "byte-swap.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
50 #include "ls-oct-text.h" |
4687 | 51 #include "ls-hdf5.h" |
52 #include "ls-utils.h" | |
53 | |
4513 | 54 template class octave_base_matrix<boolNDArray>; |
2871 | 55 |
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 { | |
19317
25f535b90e52
Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents:
18812
diff
changeset
|
82 boolMatrix bm (matrix); |
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 { | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
101 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
102 "bool matrix", "real scalar"); |
4455 | 103 |
104 retval = matrix (0, 0); | |
105 } | |
2871 | 106 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
107 err_invalid_conversion ("bool matrix", "real scalar"); |
2871 | 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 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
119 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
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 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
125 err_invalid_conversion ("bool matrix", "real scalar"); |
7789
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 { | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
139 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
140 "bool matrix", "complex scalar"); |
4455 | 141 |
142 retval = matrix (0, 0); | |
143 } | |
2871 | 144 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
145 err_invalid_conversion ("bool matrix", "complex scalar"); |
2871 | 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 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
159 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
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 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
165 err_invalid_conversion ("bool matrix", "complex scalar"); |
7789
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++) |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20163
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 |
20449
df4165dfc676
maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
203 // compatibility. Makes load_ascii much more complex!! |
4687 | 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 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
228 if (! extract_keyword (is, keywords, kw, val, true)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
229 error ("load: failed to extract number of rows and columns"); |
4687 | 230 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
231 if (kw == "ndims") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
232 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
233 int mdims = static_cast<int> (val); |
5099 | 234 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
235 if (mdims < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
236 error ("load: failed to extract number of dimensions"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
237 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
238 dim_vector dv; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
239 dv.resize (mdims); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
240 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
241 for (int i = 0; i < mdims; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
242 is >> dv(i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
243 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
244 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
245 error ("load: failed to extract dimensions"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
246 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
247 boolNDArray btmp (dv); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
248 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
249 if (btmp.is_empty ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
250 matrix = btmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
251 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
252 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
253 NDArray tmp(dv); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
254 is >> tmp; |
5099 | 255 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
256 if (! is) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
257 error ("load: failed to load matrix constant"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
258 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
259 for (octave_idx_type i = 0; i < btmp.numel (); i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
260 btmp.elem (i) = (tmp.elem (i) != 0.); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
261 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
262 matrix = btmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
263 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
264 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
265 else if (kw == "rows") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
266 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
267 octave_idx_type nr = val; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
268 octave_idx_type nc = 0; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
269 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
270 if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
271 error ("load: failed to extract number of rows and columns"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
272 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
273 if (nr > 0 && nc > 0) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
274 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
275 Matrix tmp (nr, nc); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
276 is >> tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
277 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
278 error ("load: failed to load matrix constant"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
279 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
280 boolMatrix btmp (nr, nc); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
281 for (octave_idx_type j = 0; j < nc; j++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
282 for (octave_idx_type i = 0; i < nr; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
283 btmp.elem (i,j) = (tmp.elem (i, j) != 0.); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
284 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
285 matrix = btmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
286 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
287 else if (nr == 0 || nc == 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
288 matrix = boolMatrix (nr, nc); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
289 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
290 panic_impossible (); |
5099 | 291 } |
292 else | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
293 panic_impossible (); |
4687 | 294 |
295 return success; | |
296 } | |
297 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
298 bool |
4687 | 299 octave_bool_matrix::save_binary (std::ostream& os, bool& /* save_as_floats */) |
300 { | |
301 | |
302 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
|
303 if (d.length () < 1) |
4687 | 304 return false; |
305 | |
306 // 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
|
307 int32_t tmp = - d.length (); |
5760 | 308 os.write (reinterpret_cast<char *> (&tmp), 4); |
5275 | 309 for (int i = 0; i < d.length (); i++) |
4687 | 310 { |
311 tmp = d(i); | |
5760 | 312 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 313 } |
314 | |
315 boolNDArray m = bool_array_value (); | |
316 bool *mtmp = m.fortran_vec (); | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
317 octave_idx_type nel = m.numel (); |
4687 | 318 OCTAVE_LOCAL_BUFFER (char, htmp, nel); |
319 | |
5275 | 320 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 321 htmp[i] = (mtmp[i] ? 1 : 0); |
322 | |
323 os.write (htmp, nel); | |
324 | |
325 return true; | |
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::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 oct_mach_info::float_format /* fmt */) |
4687 | 331 { |
5828 | 332 int32_t mdims; |
5760 | 333 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 334 return false; |
335 if (swap) | |
4944 | 336 swap_bytes<4> (&mdims); |
4687 | 337 if (mdims >= 0) |
338 return false; | |
339 | |
340 // mdims is negative for consistency with other matrices, where it is | |
341 // negative to allow the positive value to be used for rows/cols for | |
342 // backward compatibility | |
343 mdims = - mdims; | |
5828 | 344 int32_t di; |
4687 | 345 dim_vector dv; |
346 dv.resize (mdims); | |
347 | |
348 for (int i = 0; i < mdims; i++) | |
349 { | |
5760 | 350 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
|
351 return false; |
4687 | 352 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
353 swap_bytes<4> (&di); |
4687 | 354 dv(i) = di; |
355 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
356 |
5157 | 357 // Convert an array with a single dimension to be a row vector. |
358 // Octave should never write files like this, other software | |
359 // might. | |
360 | |
361 if (mdims == 1) | |
362 { | |
363 mdims = 2; | |
364 dv.resize (mdims); | |
365 dv(1) = dv(0); | |
366 dv(0) = 1; | |
367 } | |
368 | |
5275 | 369 octave_idx_type nel = dv.numel (); |
4687 | 370 OCTAVE_LOCAL_BUFFER (char, htmp, nel); |
371 if (! is.read (htmp, nel)) | |
372 return false; | |
373 boolNDArray m(dv); | |
374 bool *mtmp = m.fortran_vec (); | |
5275 | 375 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 376 mtmp[i] = (htmp[i] ? 1 : 0); |
377 matrix = m; | |
378 | |
379 return true; | |
380 } | |
381 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
382 bool |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
383 octave_bool_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
384 bool /* save_as_floats */) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
385 { |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
386 bool retval = true; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
387 |
4687 | 388 #if defined (HAVE_HDF5) |
4944 | 389 |
4837 | 390 dim_vector dv = dims (); |
391 int empty = save_hdf5_empty (loc_id, name, dv); | |
392 if (empty) | |
4805 | 393 return (empty > 0); |
394 | |
4837 | 395 int rank = dv.length (); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
396 hid_t space_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
397 space_hid = data_hid = -1; |
4687 | 398 boolNDArray m = bool_array_value (); |
399 | |
4805 | 400 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
401 | |
4687 | 402 // Octave uses column-major, while HDF5 uses row-major ordering |
4805 | 403 for (int i = 0; i < rank; i++) |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20163
diff
changeset
|
404 hdims[i] = dv(rank-i-1); |
4687 | 405 |
4815 | 406 space_hid = H5Screate_simple (rank, hdims, 0); |
4687 | 407 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
|
408 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
409 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_HBOOL, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20979
diff
changeset
|
410 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
411 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
412 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_HBOOL, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20979
diff
changeset
|
413 octave_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
|
414 #endif |
4687 | 415 if (data_hid < 0) |
416 { | |
417 H5Sclose (space_hid); | |
418 return false; | |
419 } | |
420 | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
421 octave_idx_type nel = m.numel (); |
4687 | 422 bool *mtmp = m.fortran_vec (); |
6276 | 423 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
|
424 |
5275 | 425 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 426 htmp[i] = mtmp[i]; |
427 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20979
diff
changeset
|
428 retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20979
diff
changeset
|
429 octave_H5P_DEFAULT, htmp) >= 0; |
4687 | 430 |
431 H5Dclose (data_hid); | |
432 H5Sclose (space_hid); | |
4837 | 433 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
434 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
435 warn_save ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
436 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
437 |
4687 | 438 return retval; |
439 } | |
440 | |
441 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
442 octave_bool_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 443 { |
4837 | 444 bool retval = false; |
445 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
446 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
447 |
4805 | 448 dim_vector dv; |
449 int empty = load_hdf5_empty (loc_id, name, dv); | |
450 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
|
451 matrix.resize (dv); |
4837 | 452 if (empty) |
453 return (empty > 0); | |
4805 | 454 |
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
|
455 #if HAVE_HDF5_18 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20979
diff
changeset
|
456 hid_t data_hid = H5Dopen (loc_id, name, octave_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
|
457 #else |
4687 | 458 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
|
459 #endif |
4687 | 460 hid_t space_id = H5Dget_space (data_hid); |
461 | |
462 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
|
463 |
4687 | 464 if (rank < 1) |
465 { | |
466 H5Dclose (data_hid); | |
467 return false; | |
468 } | |
469 | |
470 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
471 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
472 | |
473 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
474 | |
475 // Octave uses column-major, while HDF5 uses row-major ordering | |
476 if (rank == 1) | |
477 { | |
478 dv.resize (2); | |
479 dv(0) = 1; | |
480 dv(1) = hdims[0]; | |
481 } | |
482 else | |
483 { | |
484 dv.resize (rank); | |
4815 | 485 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
|
486 dv(j) = hdims[i]; |
4687 | 487 } |
488 | |
5275 | 489 octave_idx_type nel = dv.numel (); |
6276 | 490 OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nel); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20979
diff
changeset
|
491 if (H5Dread (data_hid, H5T_NATIVE_HBOOL, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, htmp) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
492 >= 0) |
4687 | 493 { |
494 retval = true; | |
495 | |
496 boolNDArray btmp (dv); | |
5275 | 497 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
|
498 btmp.elem (i) = htmp[i]; |
4687 | 499 |
500 matrix = btmp; | |
501 } | |
502 | |
503 H5Dclose (data_hid); | |
4837 | 504 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
505 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
506 warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
507 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
508 |
4687 | 509 return retval; |
510 } | |
4944 | 511 |
5900 | 512 mxArray * |
513 octave_bool_matrix::as_mxArray (void) const | |
514 { | |
515 mxArray *retval = new mxArray (mxLOGICAL_CLASS, dims (), mxREAL); | |
516 | |
517 bool *pr = static_cast<bool *> (retval->get_data ()); | |
518 | |
6686 | 519 mwSize nel = numel (); |
5900 | 520 |
521 const bool *p = matrix.data (); | |
522 | |
6686 | 523 for (mwIndex i = 0; i < nel; i++) |
5900 | 524 pr[i] = p[i]; |
525 | |
526 return retval; | |
527 } | |
528 | |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
529 DEFUN (logical, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
530 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
531 @deftypefn {} {} logical (@var{x})\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
532 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
|
533 \n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
534 Any nonzero values will be converted to true (1) while zero values will be\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
535 converted to false (0). The non-numeric value NaN cannot be converted and\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
536 will produce an error.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
537 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
538 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
|
539 @sc{matlab} issues an error.\n\ |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
540 @seealso{double, single, char}\n\ |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
541 @end deftypefn") |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
542 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
543 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
544 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
545 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
546 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
547 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
548 octave_value arg = args(0); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
549 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
550 if (arg.is_bool_type ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
551 retval = arg; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
552 else if (arg.is_numeric_type ()) |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
553 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
554 if (arg.is_sparse_type ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
555 retval = arg.sparse_bool_matrix_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
556 else if (arg.is_scalar_type ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
557 retval = arg.bool_value (); |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
558 else |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
559 retval = arg.bool_array_value (); |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
560 } |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
561 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
562 err_wrong_type_arg ("logical", arg); |
9850
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
563 |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
564 return retval; |
85f6c386f2bb
implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
565 } |
12645
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
566 |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
567 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
568 %!test |
12645
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
569 %! m = eye (2) != 0; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
570 %! s = ! 0; |
12645
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
571 %! 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
|
572 %! for i = 1:numel (c) |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
573 %! 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
|
574 %! 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
|
575 %! endfor |
d3ccd2e37de6
Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
576 */ |