annotate libinterp/octave-value/ov-bool-mat.cc @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents a61e1a0f6024
children 83f9f8bda883
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30390
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
27 # include "config.h"
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
28 #endif
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
29
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
30 #include <istream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
31 #include <ostream>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4687
diff changeset
32 #include <vector>
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2871
diff changeset
33
22296
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
34 #include "dNDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
35 #include "fNDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
36 #include "int8NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
37 #include "int16NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
38 #include "int32NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
39 #include "int64NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
40 #include "uint8NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
41 #include "uint16NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
42 #include "uint32NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
43 #include "uint64NDArray.h"
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
44
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
45 #include "lo-ieee.h"
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
46 #include "mx-base.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
47 #include "oct-locbuf.h"
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
48
9852
aabf7a8c2e57 implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 9850
diff changeset
49 #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
50 #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
51 #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
52 #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
53 #include "oct-hdf5.h"
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
54 #include "ops.h"
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3145
diff changeset
55 #include "ov-base.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3145
diff changeset
56 #include "ov-base-mat.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3145
diff changeset
57 #include "ov-base-mat.cc"
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
58 #include "ov-bool.h"
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
59 #include "ov-bool-mat.h"
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
60 #include "ov-re-mat.h"
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
61 #include "pr-output.h"
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
62
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
63 #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
64 #include "ls-oct-text.h"
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
65 #include "ls-hdf5.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
66 #include "ls-utils.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
67
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4457
diff changeset
68 template class octave_base_matrix<boolNDArray>;
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
69
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4513
diff changeset
70 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
71 "bool matrix", "logical");
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
72
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
73 static octave_base_value *
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
74 default_numeric_conversion_function (const octave_base_value& a)
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
75 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
76 const octave_bool_matrix& v = dynamic_cast<const octave_bool_matrix&> (a);
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
77
4668
7849788ca4bd [project @ 2003-11-26 04:28:39 by jwe]
jwe
parents: 4643
diff changeset
78 return new octave_matrix (NDArray (v.bool_array_value ()));
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
79 }
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
80
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
81 octave_base_value::type_conv_info
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
82 octave_bool_matrix::numeric_conversion_function (void) const
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
83 {
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
84 return octave_base_value::type_conv_info (default_numeric_conversion_function,
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
85 octave_matrix::static_type_id ());
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
86 }
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
87
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
88 octave_base_value *
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
89 octave_bool_matrix::try_narrowing_conversion (void)
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
90 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23220
diff changeset
91 octave_base_value *retval = nullptr;
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
92
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4457
diff changeset
93 if (matrix.ndims () == 2)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4457
diff changeset
94 {
19317
25f535b90e52 Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents: 18812
diff changeset
95 boolMatrix bm (matrix);
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
96
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
97 octave_idx_type nr = bm.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
98 octave_idx_type nc = bm.cols ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4457
diff changeset
99
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4457
diff changeset
100 if (nr == 1 && nc == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
101 retval = new octave_bool (bm (0, 0));
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4457
diff changeset
102 }
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
103
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
104 return retval;
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
105 }
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
106
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
107 double
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
108 octave_bool_matrix::double_value (bool) const
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
109 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
110 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
111 err_invalid_conversion ("bool matrix", "real scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
112
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
113 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
114 "bool matrix", "real scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
115
22477
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22407
diff changeset
116 return matrix(0, 0);
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
117 }
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
118
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
119 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
120 octave_bool_matrix::float_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
121 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
122 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
123 err_invalid_conversion ("bool matrix", "real scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
124
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
125 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
126 "bool matrix", "real scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
127
22477
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22407
diff changeset
128 return matrix(0, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
129 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
130
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
131 Complex
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
132 octave_bool_matrix::complex_value (bool) const
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
133 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
134 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
135 err_invalid_conversion ("bool matrix", "complex scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
136
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
137 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
138 "bool matrix", "complex scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
139
22508
0b278f54f60a Remove unnecessary initializations in complex_value methods.
Julien Bect <jbect@users.sourceforge.net>
parents: 22477
diff changeset
140 return Complex (matrix(0, 0), 0);
2871
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
141 }
c691fdf6bebb [project @ 1997-04-19 01:26:38 by jwe]
jwe
parents:
diff changeset
142
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
143 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
144 octave_bool_matrix::float_complex_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
145 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
146 float tmp = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
147
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
148 FloatComplex retval (tmp, tmp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
149
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
150 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
151 err_invalid_conversion ("bool matrix", "complex scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
152
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
153 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
154 "bool matrix", "complex scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
155
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
156 retval = matrix(0, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
157
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
158 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
159 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
160
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4455
diff changeset
161 octave_value
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
162 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
163 char type) const
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4455
diff changeset
164 {
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4837
diff changeset
165 octave_value tmp = octave_value (array_value ());
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
166 return tmp.convert_to_str (pad, force, type);
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4455
diff changeset
167 }
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4455
diff changeset
168
22296
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
169 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
170 octave_bool_matrix::as_double (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
171 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
172 return NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
173 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
174
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
175 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
176 octave_bool_matrix::as_single (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
177 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
178 return FloatNDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
179 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
180
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
181 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
182 octave_bool_matrix::as_int8 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
183 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
184 return int8NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
185 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
186
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
187 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
188 octave_bool_matrix::as_int16 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
189 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
190 return int16NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
191 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
192
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
193 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
194 octave_bool_matrix::as_int32 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
195 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
196 return int32NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
197 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
198
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
199 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
200 octave_bool_matrix::as_int64 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
201 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
202 return int64NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
203 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
204
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
205 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
206 octave_bool_matrix::as_uint8 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
207 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
208 return uint8NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
209 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
210
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
211 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
212 octave_bool_matrix::as_uint16 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
213 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
214 return uint16NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
215 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
216
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
217 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
218 octave_bool_matrix::as_uint32 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
219 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
220 return uint32NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
221 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
222
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
223 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
224 octave_bool_matrix::as_uint64 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
225 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
226 return uint64NDArray (matrix);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
227 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
228
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
229 void
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
230 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
231 bool pr_as_read_syntax) const
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
232 {
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
233 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
234 current_print_indent_level ());
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
235 }
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
236
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
237 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6718
diff changeset
238 octave_bool_matrix::save_ascii (std::ostream& os)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
239 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
240 dim_vector dv = dims ();
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
241 if (dv.ndims () > 2)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
242 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
243 NDArray tmp = array_value ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
244 os << "# ndims: " << dv.ndims () << "\n";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
245
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
246 for (int i = 0; i < dv.ndims (); i++)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23795
diff changeset
247 os << ' ' << dv(i);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
248
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
249 os << "\n" << tmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
250 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
251 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
252 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
253 // 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
254 // compatibility. Makes load_ascii much more complex!!
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
255 os << "# rows: " << rows () << "\n"
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
256 << "# columns: " << columns () << "\n";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
257
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
258 Matrix tmp = matrix_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
259
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
260 os << tmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
261 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
262
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
263 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
264 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
265
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
266 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
267 octave_bool_matrix::load_ascii (std::istream& is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
268 {
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
269 string_vector keywords (2);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
270
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
271 keywords[0] = "ndims";
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
272 keywords[1] = "rows";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
273
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
274 std::string kw;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
275 octave_idx_type val = 0;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
276
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
277 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
278 error ("load: failed to extract number of rows and columns");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
279
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
280 if (kw == "ndims")
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
281 {
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
282 int mdims = static_cast<int> (val);
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
283
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
284 if (mdims < 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
285 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
286
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
287 dim_vector dv;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
288 dv.resize (mdims);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
289
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
290 for (int i = 0; i < mdims; i++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
291 is >> dv(i);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
292
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
293 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
294 error ("load: failed to extract dimensions");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
295
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
296 boolNDArray btmp (dv);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
297
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23457
diff changeset
298 if (btmp.isempty ())
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
299 matrix = btmp;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
300 else
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
301 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
302 NDArray tmp(dv);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
303 is >> tmp;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
304
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
305 if (! is)
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
306 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
307
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
308 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
309 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
310
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
311 matrix = btmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
312 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
313 }
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
314 else if (kw == "rows")
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
315 {
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
316 octave_idx_type nr = val;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
317 octave_idx_type nc = 0;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
318
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
319 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
320 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
321
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
322 if (nr > 0 && nc > 0)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
323 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
324 Matrix tmp (nr, nc);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
325 is >> tmp;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
326 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
327 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
328
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
329 boolMatrix btmp (nr, nc);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
330 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
331 for (octave_idx_type i = 0; i < nr; i++)
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29958
diff changeset
332 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
333
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
334 matrix = btmp;
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
335 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
336 else if (nr == 0 || nc == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
337 matrix = boolMatrix (nr, nc);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
338 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
339 panic_impossible ();
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
340 }
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
341 else
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
342 panic_impossible ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
343
21124
95f8c8cdbffe maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents: 21118
diff changeset
344 return true;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
345 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
346
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
347 bool
26399
586413770c7f pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
348 octave_bool_matrix::save_binary (std::ostream& os, bool /* save_as_floats */)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
349 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
350
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
351 dim_vector dv = dims ();
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
352 if (dv.ndims () < 1)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
353 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
354
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
355 // Use negative value for ndims to differentiate with old format!!
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
356 int32_t tmp = - dv.ndims ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
357 os.write (reinterpret_cast<char *> (&tmp), 4);
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
358 for (int i = 0; i < dv.ndims (); i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
359 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
360 tmp = dv(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
361 os.write (reinterpret_cast<char *> (&tmp), 4);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
362 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
363
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
364 boolNDArray m = bool_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
365 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
366 octave_idx_type nel = m.numel ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
367 OCTAVE_LOCAL_BUFFER (char, htmp, nel);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
368
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
369 for (octave_idx_type i = 0; i < nel; i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
370 htmp[i] = (mtmp[i] ? 1 : 0);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
371
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
372 os.write (htmp, nel);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
373
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
374 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
375 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
376
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
377 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
378 octave_bool_matrix::load_binary (std::istream& is, bool swap,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
379 octave::mach_info::float_format /* fmt */)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
380 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
381 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
382 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
383 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
384 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4844
diff changeset
385 swap_bytes<4> (&mdims);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
386 if (mdims >= 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
387 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
388
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
389 // mdims is negative for consistency with other matrices, where it is
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
390 // negative to allow the positive value to be used for rows/cols for
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
391 // backward compatibility
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
392 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
393 int32_t di;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
394 dim_vector dv;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
395 dv.resize (mdims);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
396
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
397 for (int i = 0; i < mdims; i++)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
398 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
399 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
400 return false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
401 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
402 swap_bytes<4> (&di);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
403 dv(i) = di;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
404 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
405
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
406 // Convert an array with a single dimension to be a row vector.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
407 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
408 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
409
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
410 if (mdims == 1)
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
411 {
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
412 mdims = 2;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
413 dv.resize (mdims);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
414 dv(1) = dv(0);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
415 dv(0) = 1;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
416 }
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
417
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
418 octave_idx_type nel = dv.numel ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
419 OCTAVE_LOCAL_BUFFER (char, htmp, nel);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
420 if (! is.read (htmp, nel))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
421 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
422 boolNDArray m(dv);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
423 bool *mtmp = m.fortran_vec ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
424 for (octave_idx_type i = 0; i < nel; i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
425 mtmp[i] = (htmp[i] ? 1 : 0);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
426 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
427
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
428 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
429 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
430
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
431 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
432 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
433 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
434 {
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
435 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
436
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
437 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4844
diff changeset
438
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
439 dim_vector dv = dims ();
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
440 int empty = save_hdf5_empty (loc_id, name, dv);
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
441 if (empty)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
442 return (empty > 0);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
443
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21647
diff changeset
444 int rank = dv.ndims ();
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
445 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
446 space_hid = data_hid = -1;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
447 boolNDArray m = bool_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
448
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
449 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
450
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
451 // Octave uses column-major, while HDF5 uses row-major ordering
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
452 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
453 hdims[i] = dv(rank-i-1);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
454
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23586
diff changeset
455 space_hid = H5Screate_simple (rank, hdims, nullptr);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
456 if (space_hid < 0) return false;
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
457 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
458 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
459 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
460 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
461 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
462 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
463 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
464 if (data_hid < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
465 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
466 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
467 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
468 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
469
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
470 octave_idx_type nel = m.numel ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
471 bool *mtmp = m.fortran_vec ();
6276
d26c558691cd [project @ 2007-02-07 09:01:24 by jwe]
jwe
parents: 5958
diff changeset
472 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
473
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
474 for (octave_idx_type i = 0; i < nel; i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
475 htmp[i] = mtmp[i];
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
476
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20979
diff changeset
477 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
478 octave_H5P_DEFAULT, htmp) >= 0;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
479
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
480 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
481 H5Sclose (space_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
482
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
483 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
484 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
485 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
486
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
487 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
488 #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
489
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
490 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
491 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
492
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
493 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
494 octave_bool_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
495 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
496 bool retval = false;
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
497
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
498 #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
499
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
500 dim_vector dv;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
501 int empty = load_hdf5_empty (loc_id, name, dv);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
502 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
503 matrix.resize (dv);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
504 if (empty)
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
505 return (empty > 0);
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
506
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
507 #if defined (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
508 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
509 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
510 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
511 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
512 hid_t space_id = H5Dget_space (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
513
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
514 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
515
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
516 if (rank < 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
517 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
518 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
519 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
520 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
521
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
522 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
523 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
524
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
525 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
526
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
527 // Octave uses column-major, while HDF5 uses row-major ordering
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
528 if (rank == 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
529 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
530 dv.resize (2);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
531 dv(0) = 1;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
532 dv(1) = hdims[0];
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
533 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
534 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
535 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
536 dv.resize (rank);
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
537 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
538 dv(j) = hdims[i];
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
539 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
540
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
541 octave_idx_type nel = dv.numel ();
6276
d26c558691cd [project @ 2007-02-07 09:01:24 by jwe]
jwe
parents: 5958
diff changeset
542 OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nel);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
543 if (H5Dread (data_hid, H5T_NATIVE_HBOOL, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
544 octave_H5P_DEFAULT, htmp)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
545 >= 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
546 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
547 retval = true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
548
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
549 boolNDArray btmp (dv);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5157
diff changeset
550 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
551 btmp.elem (i) = htmp[i];
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
552
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
553 matrix = btmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
554 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
555
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
556 H5Dclose (data_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
557
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
558 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
559 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
560 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
561
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
562 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
563 #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
564
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
565 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4668
diff changeset
566 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4844
diff changeset
567
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
568 mxArray *
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
569 octave_bool_matrix::as_mxArray (bool interleaved) const
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
570 {
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
571 mxArray *retval = new mxArray (interleaved, mxLOGICAL_CLASS, dims (), mxREAL);
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
572
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
573 mxLogical *pd = static_cast<mxLogical *> (retval->get_data ());
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
574
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 6276
diff changeset
575 mwSize nel = numel ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
576
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
577 const bool *pdata = matrix.data ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
578
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 6276
diff changeset
579 for (mwIndex i = 0; i < nel; i++)
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
580 pd[i] = pdata[i];
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
581
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
582 return retval;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
583 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
584
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
585 OCTAVE_NAMESPACE_BEGIN
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
586
9850
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
587 DEFUN (logical, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
588 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
589 @deftypefn {} {} logical (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
590 Convert the numeric object @var{x} to logical type.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
591
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
592 Any nonzero values will be converted to true (1) while zero values will be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
593 converted to false (0). The non-numeric value NaN cannot be converted and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
594 will produce an error.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
595
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
596 Compatibility Note: Octave accepts complex values as input, whereas
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
597 @sc{matlab} issues an error.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
598 @seealso{double, single, char}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
599 @end deftypefn */)
9850
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
600 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
601 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
602 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
603
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
604 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
605
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
606 octave_value arg = args(0);
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
607
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23577
diff changeset
608 if (arg.islogical ())
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
609 retval = arg;
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23583
diff changeset
610 else if (arg.isnumeric ())
9850
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
611 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23579
diff changeset
612 if (arg.issparse ())
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
613 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
614 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
615 retval = arg.bool_value ();
9850
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
616 else
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20449
diff changeset
617 retval = arg.bool_array_value ();
9850
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
618 }
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
619 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21022
diff changeset
620 err_wrong_type_arg ("logical", arg);
9850
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
621
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
622 return retval;
85f6c386f2bb implement built-in logical
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
623 }
12645
d3ccd2e37de6 Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
624
d3ccd2e37de6 Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
625 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
626 %!test
12645
d3ccd2e37de6 Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
627 %! 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
628 %! s = ! 0;
12645
d3ccd2e37de6 Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
629 %! 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
630 %! for i = 1:numel (c)
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21301
diff changeset
631 %! assert (logical (eye (2, c{i})), m);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21301
diff changeset
632 %! assert (logical (eye (1, c{i})), s);
12645
d3ccd2e37de6 Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
633 %! endfor
d3ccd2e37de6 Allow scalar integer to logical conversion (bug #33219)
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
634 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
635
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
636 OCTAVE_NAMESPACE_END