Mercurial > octave
annotate libinterp/octave-value/ov-re-mat.cc @ 33362:2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
* ov-base-diag.cc, ov-base-mat.cc, ov-base-scalar.cc,
ov-base-sparse.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc,
ov-class.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-perm.cc, ov-range.cc, ov-re-mat.cc,
ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc: Replace all uses of
panic_impossible with error.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 08 Apr 2024 19:39:34 -0400 |
parents | abdb846bafe8 |
children |
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 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31825
diff
changeset
|
3 // Copyright (C) 1996-2024 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 //////////////////////////////////////////////////////////////////////// |
2376 | 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:
21231
diff
changeset
|
27 # include "config.h" |
2376 | 28 #endif |
29 | |
30056
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
30 #include <clocale> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
31 #include <istream> |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
32 #include <limits> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
33 #include <ostream> |
4726 | 34 #include <vector> |
2901 | 35 |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
36 #include "dNDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
37 #include "fNDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
38 #include "int8NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
39 #include "int16NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
40 #include "int32NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
41 #include "int64NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
42 #include "uint8NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
43 #include "uint16NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
44 #include "uint32NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
45 #include "uint64NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
46 |
4944 | 47 #include "data-conv.h" |
2376 | 48 #include "lo-ieee.h" |
49 #include "lo-utils.h" | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
50 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
51 #include "lo-mappers.h" |
4944 | 52 #include "mach-info.h" |
2376 | 53 #include "mx-base.h" |
4153 | 54 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
55 #include "oct-locbuf.h" |
2376 | 56 |
4901 | 57 #include "defun.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
58 #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
|
59 #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
|
60 #include "ovl.h" |
2979 | 61 #include "oct-lvalue.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:
19861
diff
changeset
|
62 #include "oct-hdf5.h" |
4944 | 63 #include "oct-stream.h" |
2410 | 64 #include "ops.h" |
3219 | 65 #include "ov-base.h" |
2410 | 66 #include "ov-scalar.h" |
2376 | 67 #include "ov-re-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
68 #include "ov-flt-re-mat.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
69 #include "ov-complex.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
70 #include "ov-cx-mat.h" |
7004 | 71 #include "ov-re-sparse.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
72 #include "ov-re-diag.h" |
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
73 #include "ov-cx-diag.h" |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
74 #include "ov-lazy-idx.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
75 #include "ov-perm.h" |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
76 #include "pr-flt-fmt.h" |
2376 | 77 #include "pr-output.h" |
2948 | 78 #include "variables.h" |
2376 | 79 |
4687 | 80 #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
|
81 #include "ls-oct-text.h" |
4687 | 82 #include "ls-utils.h" |
4805 | 83 #include "ls-hdf5.h" |
4687 | 84 |
22022
278fc29b69ca
maint: Eliminate unnecessary double newline blocks (only whitespace changes).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
85 |
4612 | 86 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_matrix, "matrix", "double"); |
2376 | 87 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
88 static octave_base_value * |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
89 default_numeric_demotion_function (const octave_base_value& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
90 { |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
91 const octave_matrix& v = dynamic_cast<const octave_matrix&> (a); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
92 |
8754
900a5bf52309
Fix invalid conversion error on implicit demotion of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
93 return new octave_float_matrix (v.float_array_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
94 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
95 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
96 octave_base_value::type_conv_info |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
97 octave_matrix::numeric_demotion_function () const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
98 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 return octave_base_value::type_conv_info |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
100 (default_numeric_demotion_function, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
101 octave_float_matrix::static_type_id ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
102 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
103 |
5759 | 104 octave_base_value * |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
105 octave_matrix::try_narrowing_conversion () |
2410 | 106 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
107 octave_base_value *retval = nullptr; |
2410 | 108 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
109 if (m_matrix.numel () == 1) |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
110 retval = new octave_scalar (m_matrix (0)); |
2410 | 111 |
112 return retval; | |
113 } | |
114 | |
2376 | 115 double |
116 octave_matrix::double_value (bool) const | |
117 { | |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
118 if (isempty ()) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
119 err_invalid_conversion ("real matrix", "real scalar"); |
4455 | 120 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
121 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
|
122 "real matrix", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
123 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
124 return m_matrix(0, 0); |
2376 | 125 } |
126 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
128 octave_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
129 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
130 if (isempty ()) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
131 err_invalid_conversion ("real matrix", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
133 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
|
134 "real matrix", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
135 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
136 return m_matrix(0, 0); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
138 |
5775 | 139 // FIXME |
4513 | 140 |
141 Matrix | |
142 octave_matrix::matrix_value (bool) const | |
143 { | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
144 return Matrix (m_matrix); |
4513 | 145 } |
146 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
147 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
148 octave_matrix::float_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
150 return FloatMatrix (Matrix (m_matrix)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
151 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
152 |
2376 | 153 Complex |
154 octave_matrix::complex_value (bool) const | |
155 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
156 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
|
157 err_invalid_conversion ("real matrix", "complex scalar"); |
4455 | 158 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
159 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
|
160 "real matrix", "complex scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
161 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
162 return Complex (m_matrix(0, 0), 0); |
2376 | 163 } |
164 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
165 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
166 octave_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
167 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
168 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
169 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
170 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
171 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
172 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
|
173 err_invalid_conversion ("real matrix", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
174 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
175 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
|
176 "real matrix", "complex scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
177 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
178 retval = m_matrix(0, 0); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
179 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
180 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
181 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
182 |
5775 | 183 // FIXME |
4513 | 184 |
185 ComplexMatrix | |
186 octave_matrix::complex_matrix_value (bool) const | |
187 { | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
188 return ComplexMatrix (Matrix (m_matrix)); |
4513 | 189 } |
190 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
191 FloatComplexMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
192 octave_matrix::float_complex_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
193 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
194 return FloatComplexMatrix (Matrix (m_matrix)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
195 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
196 |
4699 | 197 ComplexNDArray |
198 octave_matrix::complex_array_value (bool) const | |
199 { | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
200 return ComplexNDArray (m_matrix); |
4699 | 201 } |
202 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
203 FloatComplexNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
204 octave_matrix::float_complex_array_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
205 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
206 return FloatComplexNDArray (m_matrix); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
207 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
208 |
5898 | 209 boolNDArray |
5943 | 210 octave_matrix::bool_array_value (bool warn) const |
5898 | 211 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
212 if (m_matrix.any_element_is_nan ()) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
213 octave::err_nan_to_logical_conversion (); |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
214 if (warn && m_matrix.any_element_not_one_or_zero ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
215 warn_logical_conversion (); |
5943 | 216 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
217 return boolNDArray (m_matrix); |
5898 | 218 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 |
4758 | 220 charNDArray |
221 octave_matrix::char_array_value (bool) const | |
222 { | |
223 charNDArray retval (dims ()); | |
224 | |
5275 | 225 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
226 |
5275 | 227 for (octave_idx_type i = 0; i < nel; i++) |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
228 retval.elem (i) = static_cast<char> (m_matrix.elem (i)); |
4758 | 229 |
230 return retval; | |
231 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
232 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
233 SparseMatrix |
5164 | 234 octave_matrix::sparse_matrix_value (bool) const |
235 { | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
236 return SparseMatrix (Matrix (m_matrix)); |
5164 | 237 } |
238 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
239 SparseComplexMatrix |
5164 | 240 octave_matrix::sparse_complex_matrix_value (bool) const |
241 { | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
242 // FIXME: Need a SparseComplexMatrix (Matrix) constructor to make |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
243 // this function more efficient. Then this should become |
5164 | 244 // return SparseComplexMatrix (matrix.matrix_value ()); |
245 return SparseComplexMatrix (sparse_matrix_value ()); | |
246 } | |
247 | |
2376 | 248 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
249 octave_matrix::as_double () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
250 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
251 return NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
252 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
253 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
254 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
255 octave_matrix::as_single () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
256 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
257 return FloatNDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
258 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
259 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
260 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
261 octave_matrix::as_int8 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
262 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
263 return int8NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
264 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
265 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
266 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
267 octave_matrix::as_int16 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
268 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
269 return int16NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
270 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
271 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
272 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
273 octave_matrix::as_int32 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
274 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
275 return int32NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
276 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
277 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
278 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
279 octave_matrix::as_int64 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
280 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
281 return int64NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
282 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
283 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
284 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
285 octave_matrix::as_uint8 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
286 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
287 return uint8NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
288 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
289 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
290 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
291 octave_matrix::as_uint16 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
292 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
293 return uint16NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
294 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
295 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
296 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
297 octave_matrix::as_uint32 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
298 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
299 return uint32NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
300 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
301 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
302 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
303 octave_matrix::as_uint64 () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
304 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
305 return uint64NDArray (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
306 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
307 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22283
diff
changeset
|
308 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
309 octave_matrix::diag (octave_idx_type k) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
310 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
311 octave_value retval; |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
312 if (k == 0 && m_matrix.ndims () == 2 |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
313 && (m_matrix.rows () == 1 || m_matrix.columns () == 1)) |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
314 retval = DiagMatrix (DiagArray2<double> (m_matrix)); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
315 else |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
316 retval = octave_base_matrix<NDArray>::diag (k); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
317 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
318 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
319 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
320 |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
321 octave_value |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
322 octave_matrix::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
323 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
324 if (m_matrix.ndims () != 2 |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
325 || (m_matrix.rows () != 1 && m_matrix.columns () != 1)) |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
326 error ("diag: expecting vector argument"); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
327 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
328 Matrix mat (m_matrix); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
329 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
330 return mat.diag (m, n); |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
331 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
332 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
333 // We override these two functions to allow reshaping both |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
334 // the matrix and the index cache. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
335 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
336 octave_matrix::reshape (const dim_vector& new_dims) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
337 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
338 if (m_idx_cache) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
339 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
340 return new octave_matrix (m_matrix.reshape (new_dims), |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
341 octave::idx_vector (m_idx_cache->as_array ().reshape (new_dims), |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
342 m_idx_cache->extent (0))); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
343 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
344 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
345 return octave_base_matrix<NDArray>::reshape (new_dims); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
346 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
347 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
348 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
349 octave_matrix::squeeze () const |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
350 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
351 if (m_idx_cache) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
352 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
353 return new octave_matrix (m_matrix.squeeze (), |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
354 octave::idx_vector (m_idx_cache->as_array ().squeeze (), |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
355 m_idx_cache->extent (0))); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
356 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
357 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
358 return octave_base_matrix<NDArray>::squeeze (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
359 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
360 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
361 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
362 octave_matrix::sort (octave_idx_type dim, sortmode mode) const |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
363 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
364 if (m_idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
365 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
366 // This is a valid index matrix, so sort via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
367 // generally more efficient. |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
368 return octave_lazy_index (*m_idx_cache).sort (dim, mode); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
369 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
370 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
371 return octave_base_matrix<NDArray>::sort (dim, mode); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
372 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
373 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
374 octave_value |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30056
diff
changeset
|
375 octave_matrix::sort (Array<octave_idx_type>& sidx, octave_idx_type dim, |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
376 sortmode mode) const |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
377 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
378 if (m_idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
379 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
380 // This is a valid index matrix, so sort via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
381 // generally more efficient. |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
382 return octave_lazy_index (*m_idx_cache).sort (sidx, dim, mode); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
383 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
384 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
385 return octave_base_matrix<NDArray>::sort (sidx, dim, mode); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
386 } |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
387 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
388 sortmode |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
389 octave_matrix::issorted (sortmode mode) const |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
390 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
391 if (m_idx_cache) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
392 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
393 // This is a valid index matrix, so check via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
394 // generally more efficient. |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
395 return m_idx_cache->as_array ().issorted (mode); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
396 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
397 else |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
398 return octave_base_matrix<NDArray>::issorted (mode); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
399 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
400 Array<octave_idx_type> |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
401 octave_matrix::sort_rows_idx (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
402 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
403 if (m_idx_cache) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
404 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
405 // This is a valid index matrix, so sort via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
406 // generally more efficient. |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
407 return octave_lazy_index (*m_idx_cache).sort_rows_idx (mode); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
408 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
409 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
410 return octave_base_matrix<NDArray>::sort_rows_idx (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
411 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
412 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
413 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
414 octave_matrix::is_sorted_rows (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
415 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
416 if (m_idx_cache) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
417 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
418 // This is a valid index matrix, so check via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
419 // generally more efficient. |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
420 return m_idx_cache->as_array ().is_sorted_rows (mode); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
421 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
422 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
423 return octave_base_matrix<NDArray>::is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
424 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
425 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
426 octave_value |
5279 | 427 octave_matrix::convert_to_str_internal (bool, bool, char type) const |
2376 | 428 { |
429 octave_value retval; | |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
31825
diff
changeset
|
430 const dim_vector& dv = dims (); |
5862 | 431 octave_idx_type nel = dv.numel (); |
432 | |
433 charNDArray chm (dv); | |
2376 | 434 |
5862 | 435 bool warned = false; |
436 | |
437 for (octave_idx_type i = 0; i < nel; i++) | |
2376 | 438 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
439 octave_quit (); |
5862 | 440 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
441 double d = m_matrix(i); |
4844 | 442 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
443 if (octave::math::isnan (d)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
444 octave::err_nan_to_character_conversion (); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
445 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
446 int ival = octave::math::nint (d); |
4844 | 447 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
448 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
449 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
450 // FIXME: is there something better we could do? |
2376 | 451 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
452 ival = 0; |
5862 | 453 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
454 if (! warned) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
455 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
456 ::warning ("range error for conversion to character value"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
457 warned = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
458 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
459 } |
2376 | 460 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
461 chm(i) = static_cast<char> (ival); |
5862 | 462 } |
2376 | 463 |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9470
diff
changeset
|
464 retval = octave_value (chm, type); |
2376 | 465 |
466 return retval; | |
467 } | |
468 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
469 bool |
6974 | 470 octave_matrix::save_ascii (std::ostream& os) |
4687 | 471 { |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
31825
diff
changeset
|
472 const dim_vector& dv = dims (); |
5958 | 473 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
474 if (dv.ndims () > 2) |
4687 | 475 { |
476 NDArray tmp = array_value (); | |
477 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
478 os << "# ndims: " << dv.ndims () << "\n"; |
4687 | 479 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
480 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
|
481 os << ' ' << dv(i); |
4687 | 482 |
483 os << "\n" << tmp; | |
484 } | |
485 else | |
486 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
487 // 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
|
488 // compatibility. Makes load_ascii much more complex!! |
4687 | 489 os << "# rows: " << rows () << "\n" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
490 << "# columns: " << columns () << "\n"; |
4687 | 491 |
5958 | 492 os << matrix_value (); |
4687 | 493 } |
494 | |
495 return true; | |
496 } | |
497 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
498 bool |
4687 | 499 octave_matrix::load_ascii (std::istream& is) |
500 { | |
5099 | 501 string_vector keywords(2); |
502 | |
503 keywords[0] = "ndims"; | |
504 keywords[1] = "rows"; | |
4687 | 505 |
5099 | 506 std::string kw; |
5275 | 507 octave_idx_type val = 0; |
5099 | 508 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
509 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
|
510 error ("load: failed to extract number of rows and columns"); |
4687 | 511 |
30056
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
512 // Set "C" locale for the duration of this function to avoid the performance |
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
513 // panelty of frequently switching the locale when reading floating point |
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
514 // values from the stream. |
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
515 char *prev_locale = std::setlocale (LC_ALL, nullptr); |
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
516 std::string old_locale (prev_locale ? prev_locale : ""); |
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
517 std::setlocale (LC_ALL, "C"); |
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
518 octave::unwind_action act |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
519 ([&old_locale] () { std::setlocale (LC_ALL, old_locale.c_str ()); }); |
30056
7c494a811cc3
load_ascii: Improve performance on platforms with slow setlocale (bug #60984).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30006
diff
changeset
|
520 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
521 if (kw == "ndims") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
522 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
523 int mdims = static_cast<int> (val); |
4687 | 524 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
525 if (mdims < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
526 error ("load: failed to extract number of dimensions"); |
5099 | 527 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
528 dim_vector dv; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
529 dv.resize (mdims); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
530 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
531 for (int i = 0; i < mdims; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
532 is >> dv(i); |
5099 | 533 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
534 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
535 error ("load: failed to read dimensions"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
536 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
537 NDArray tmp(dv); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
538 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
539 is >> tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
540 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
541 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
542 error ("load: failed to load matrix constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
543 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
544 m_matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
545 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
546 else if (kw == "rows") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
547 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
548 octave_idx_type nr = val; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
549 octave_idx_type nc = 0; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
550 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
551 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
|
552 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
|
553 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
554 if (nr > 0 && nc > 0) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
555 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
556 Matrix tmp (nr, nc); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
557 is >> tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
558 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
559 error ("load: failed to load matrix constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
560 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
561 m_matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
562 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
563 else if (nr == 0 || nc == 0) |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
564 m_matrix = Matrix (nr, nc); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
565 else |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
566 error ("unexpected dimensions in octave_matrix::load_ascii - please report this bug"); |
5099 | 567 } |
568 else | |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
569 error ("unexpected dimensions keyword (= '%s') octave_matrix::load_ascii - please report this bug", kw.c_str ()); |
4687 | 570 |
21124
95f8c8cdbffe
maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
571 return true; |
4687 | 572 } |
573 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
574 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
|
575 octave_matrix::save_binary (std::ostream& os, bool save_as_floats) |
4687 | 576 { |
577 | |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
31825
diff
changeset
|
578 const dim_vector& dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
579 if (dv.ndims () < 1) |
4687 | 580 return false; |
581 | |
582 // 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
|
583 int32_t tmp = - dv.ndims (); |
5760 | 584 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
|
585 for (int i = 0; i < dv.ndims (); i++) |
4687 | 586 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
587 tmp = dv(i); |
5760 | 588 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 589 } |
590 | |
591 NDArray m = array_value (); | |
592 save_type st = LS_DOUBLE; | |
593 if (save_as_floats) | |
594 { | |
595 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
596 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
597 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
598 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
599 } |
4687 | 600 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
601 st = LS_FLOAT; |
4687 | 602 } |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
603 else if (dv.numel () > 8192) // FIXME: make this configurable. |
4687 | 604 { |
605 double max_val, min_val; | |
606 if (m.all_integers (max_val, min_val)) | |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29604
diff
changeset
|
607 st = octave::get_save_type (max_val, min_val); |
4687 | 608 } |
609 | |
610 const double *mtmp = m.data (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
611 write_doubles (os, mtmp, st, dv.numel ()); |
4687 | 612 |
613 return true; | |
614 } | |
615 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
616 bool |
4687 | 617 octave_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
|
618 octave::mach_info::float_format fmt) |
4687 | 619 { |
620 char tmp; | |
5828 | 621 int32_t mdims; |
5760 | 622 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 623 return false; |
624 if (swap) | |
4944 | 625 swap_bytes<4> (&mdims); |
4687 | 626 if (mdims < 0) |
627 { | |
628 mdims = - mdims; | |
5828 | 629 int32_t di; |
4687 | 630 dim_vector dv; |
631 dv.resize (mdims); | |
632 | |
633 for (int i = 0; i < mdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
634 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
635 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
636 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
637 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
638 swap_bytes<4> (&di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
639 dv(i) = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
640 } |
4687 | 641 |
5157 | 642 // Convert an array with a single dimension to be a row vector. |
643 // Octave should never write files like this, other software | |
644 // might. | |
645 | |
646 if (mdims == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
648 mdims = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
649 dv.resize (mdims); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
650 dv(1) = dv(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
651 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
652 } |
5157 | 653 |
5760 | 654 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
655 return false; |
4687 | 656 |
657 NDArray m(dv); | |
32660
f53ac65ffba6
maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents:
32633
diff
changeset
|
658 double *re = m.rwdata (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
659 read_doubles (is, re, static_cast<save_type> (tmp), dv.numel (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
660 swap, fmt); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
661 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
662 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
663 return false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
664 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
665 m_matrix = m; |
4687 | 666 } |
667 else | |
668 { | |
5828 | 669 int32_t nr, nc; |
4687 | 670 nr = mdims; |
5760 | 671 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
672 return false; |
4687 | 673 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
674 swap_bytes<4> (&nc); |
5760 | 675 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
676 return false; |
4687 | 677 Matrix m (nr, nc); |
32660
f53ac65ffba6
maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents:
32633
diff
changeset
|
678 double *re = m.rwdata (); |
29604
44f0b8975fe5
Cast to wider resulting type before multiplication.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29569
diff
changeset
|
679 octave_idx_type len = static_cast<octave_idx_type> (nr) * nc; |
5760 | 680 read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
681 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
682 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
683 return false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
684 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
685 m_matrix = m; |
4687 | 686 } |
687 return true; | |
688 } | |
689 | |
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:
19861
diff
changeset
|
690 bool |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
691 octave_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
692 bool save_as_floats) |
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:
19861
diff
changeset
|
693 { |
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:
19861
diff
changeset
|
694 bool retval = false; |
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:
19861
diff
changeset
|
695 |
4687 | 696 #if defined (HAVE_HDF5) |
4944 | 697 |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
31825
diff
changeset
|
698 const dim_vector& dv = dims (); |
4837 | 699 int empty = save_hdf5_empty (loc_id, name, dv); |
700 if (empty) | |
4805 | 701 return (empty > 0); |
702 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
703 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:
17861
diff
changeset
|
704 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:
17861
diff
changeset
|
705 space_hid = data_hid = -1; |
4687 | 706 NDArray m = array_value (); |
707 | |
4805 | 708 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
709 | |
4687 | 710 // Octave uses column-major, while HDF5 uses row-major ordering |
4805 | 711 for (int i = 0; i < rank; i++) |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
712 hdims[i] = dv(rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
713 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
714 space_hid = H5Screate_simple (rank, hdims, nullptr); |
4687 | 715 |
716 if (space_hid < 0) return false; | |
717 | |
718 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
719 | |
720 if (save_as_floats) | |
721 { | |
722 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
723 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
724 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
725 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
726 } |
4687 | 727 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
728 save_type_hid = H5T_NATIVE_FLOAT; |
4687 | 729 } |
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
|
730 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS) |
4687 | 731 // hdf5 currently doesn't support float/integer conversions |
732 else | |
733 { | |
734 double max_val, min_val; | |
735 | |
736 if (m.all_integers (max_val, min_val)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
737 save_type_hid |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29604
diff
changeset
|
738 = save_type_to_hdf5 (octave::get_save_type (max_val, min_val)); |
4687 | 739 } |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
740 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
741 |
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
|
742 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
743 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30056
diff
changeset
|
744 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30056
diff
changeset
|
745 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
|
746 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
747 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
748 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
|
749 #endif |
4687 | 750 if (data_hid < 0) |
751 { | |
752 H5Sclose (space_hid); | |
753 return false; | |
754 } | |
755 | |
31825
8078a7f4edfa
Use data() instead of fortran_vec() where possible (bug #63803)
Arun Giridhar <arungiridhar@gmail.com>
parents:
31771
diff
changeset
|
756 const double *mtmp = m.data (); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30056
diff
changeset
|
757 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30056
diff
changeset
|
758 octave_H5S_ALL, octave_H5P_DEFAULT, mtmp) >= 0; |
4687 | 759 |
760 H5Dclose (data_hid); | |
761 H5Sclose (space_hid); | |
4837 | 762 |
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:
19861
diff
changeset
|
763 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
764 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
765 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
766 octave_unused_parameter (save_as_floats); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
767 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
768 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:
19861
diff
changeset
|
769 #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:
19861
diff
changeset
|
770 |
4687 | 771 return retval; |
772 } | |
773 | |
774 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:
19861
diff
changeset
|
775 octave_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 776 { |
4837 | 777 bool retval = false; |
778 | |
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:
19861
diff
changeset
|
779 #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:
19861
diff
changeset
|
780 |
4805 | 781 dim_vector dv; |
782 int empty = load_hdf5_empty (loc_id, name, dv); | |
783 if (empty > 0) | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
784 m_matrix.resize (dv); |
4837 | 785 if (empty) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
786 return (empty > 0); |
4805 | 787 |
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
|
788 #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:
21013
diff
changeset
|
789 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
|
790 #else |
4687 | 791 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
|
792 #endif |
4687 | 793 hid_t space_id = H5Dget_space (data_hid); |
794 | |
795 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
|
796 |
4687 | 797 if (rank < 1) |
798 { | |
799 H5Sclose (space_id); | |
800 H5Dclose (data_hid); | |
801 return false; | |
802 } | |
803 | |
804 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
805 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
806 | |
807 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
808 | |
809 // Octave uses column-major, while HDF5 uses row-major ordering | |
810 if (rank == 1) | |
811 { | |
812 dv.resize (2); | |
813 dv(0) = 1; | |
814 dv(1) = hdims[0]; | |
815 } | |
816 else | |
817 { | |
818 dv.resize (rank); | |
4815 | 819 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:
10273
diff
changeset
|
820 dv(j) = hdims[i]; |
4687 | 821 } |
822 | |
823 NDArray m (dv); | |
32660
f53ac65ffba6
maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents:
32633
diff
changeset
|
824 double *re = m.rwdata (); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
825 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, 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:
21013
diff
changeset
|
826 octave_H5P_DEFAULT, re) >= 0) |
4687 | 827 { |
828 retval = true; | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
829 m_matrix = m; |
4687 | 830 } |
831 | |
832 H5Sclose (space_id); | |
833 H5Dclose (data_hid); | |
4837 | 834 |
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:
19861
diff
changeset
|
835 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
836 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
837 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
838 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
839 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:
19861
diff
changeset
|
840 #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:
19861
diff
changeset
|
841 |
4687 | 842 return retval; |
843 } | |
4944 | 844 |
4643 | 845 void |
846 octave_matrix::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
847 bool pr_as_read_syntax) const |
4643 | 848 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
849 octave_print_internal (os, m_matrix, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
850 current_print_indent_level ()); |
4643 | 851 } |
852 | |
5900 | 853 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
|
854 octave_matrix::as_mxArray (bool interleaved) const |
5900 | 855 { |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
856 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, dims (), mxREAL); |
5900 | 857 |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
858 mxDouble *pd = static_cast<mxDouble *> (retval->get_data ()); |
5900 | 859 |
6686 | 860 mwSize nel = numel (); |
5900 | 861 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
862 const double *pdata = m_matrix.data (); |
5900 | 863 |
6686 | 864 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
|
865 pd[i] = pdata[i]; |
5900 | 866 |
867 return retval; | |
868 } | |
869 | |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
870 // This uses a smarter strategy for doing the complex->real mappers. We |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
871 // allocate an array for a real result and keep filling it until a complex |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
872 // result is produced. |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
873 static octave_value |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
874 do_rc_map (const NDArray& a, Complex (&fcn) (double)) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
875 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
876 octave_idx_type n = a.numel (); |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26399
diff
changeset
|
877 NDArray rr (a.dims ()); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
878 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
879 for (octave_idx_type i = 0; i < n; i++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
880 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
881 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
882 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
883 Complex tmp = fcn (a(i)); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
884 if (tmp.imag () == 0.0) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26399
diff
changeset
|
885 rr.xelem (i) = tmp.real (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
886 else |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
887 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26399
diff
changeset
|
888 ComplexNDArray rc (a.dims ()); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
889 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
890 for (octave_idx_type j = 0; j < i; j++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26399
diff
changeset
|
891 rc.xelem (j) = rr.xelem (j); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
892 |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26399
diff
changeset
|
893 rc.xelem (i) = tmp; |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
894 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
895 for (octave_idx_type j = i+1; j < n; j++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
896 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
897 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
898 |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26399
diff
changeset
|
899 rc.xelem (j) = fcn (a(j)); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
900 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
901 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
902 return new octave_complex_matrix (rc); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
903 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
904 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
905 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
906 return rr; |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
907 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
908 |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
909 octave_value |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
910 octave_matrix::map (unary_mapper_t umap) const |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
911 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
912 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
913 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
914 case umap_imag: |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
915 return NDArray (m_matrix.dims (), 0.0); |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
916 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
917 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
918 case umap_conj: |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
919 return m_matrix; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
920 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
921 // Mappers handled specially. |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
922 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
923 case umap_ ## UMAP: \ |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
924 return octave_value (m_matrix.FCN ()) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
925 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
926 ARRAY_METHOD_MAPPER (abs, abs); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
927 ARRAY_METHOD_MAPPER (isnan, isnan); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
928 ARRAY_METHOD_MAPPER (isinf, isinf); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
929 ARRAY_METHOD_MAPPER (isfinite, isfinite); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
930 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
931 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
932 case umap_ ## UMAP: \ |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
933 return octave_value (m_matrix.map<TYPE> (FCN)) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
934 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
935 #define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
936 case umap_ ## UMAP: \ |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
937 return do_rc_map (m_matrix, FCN) |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
938 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
939 RC_ARRAY_MAPPER (acos, Complex, octave::math::rc_acos); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
940 RC_ARRAY_MAPPER (acosh, Complex, octave::math::rc_acosh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
941 ARRAY_MAPPER (angle, double, std::arg); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
942 ARRAY_MAPPER (arg, double, std::arg); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
943 RC_ARRAY_MAPPER (asin, Complex, octave::math::rc_asin); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
944 ARRAY_MAPPER (asinh, double, octave::math::asinh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
945 ARRAY_MAPPER (atan, double, ::atan); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
946 RC_ARRAY_MAPPER (atanh, Complex, octave::math::rc_atanh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
947 ARRAY_MAPPER (erf, double, octave::math::erf); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
948 ARRAY_MAPPER (erfinv, double, octave::math::erfinv); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
949 ARRAY_MAPPER (erfcinv, double, octave::math::erfcinv); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
950 ARRAY_MAPPER (erfc, double, octave::math::erfc); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
951 ARRAY_MAPPER (erfcx, double, octave::math::erfcx); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
952 ARRAY_MAPPER (erfi, double, octave::math::erfi); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
953 ARRAY_MAPPER (dawson, double, octave::math::dawson); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
954 ARRAY_MAPPER (gamma, double, octave::math::gamma); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
955 RC_ARRAY_MAPPER (lgamma, Complex, octave::math::rc_lgamma); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
956 ARRAY_MAPPER (cbrt, double, octave::math::cbrt); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
957 ARRAY_MAPPER (ceil, double, ::ceil); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
958 ARRAY_MAPPER (cos, double, ::cos); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
959 ARRAY_MAPPER (cosh, double, ::cosh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
960 ARRAY_MAPPER (exp, double, ::exp); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
961 ARRAY_MAPPER (expm1, double, octave::math::expm1); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
962 ARRAY_MAPPER (fix, double, octave::math::fix); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
963 ARRAY_MAPPER (floor, double, ::floor); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
964 RC_ARRAY_MAPPER (log, Complex, octave::math::rc_log); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
965 RC_ARRAY_MAPPER (log2, Complex, octave::math::rc_log2); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
966 RC_ARRAY_MAPPER (log10, Complex, octave::math::rc_log10); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
967 RC_ARRAY_MAPPER (log1p, Complex, octave::math::rc_log1p); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
968 ARRAY_MAPPER (round, double, octave::math::round); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
969 ARRAY_MAPPER (roundb, double, octave::math::roundb); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
970 ARRAY_MAPPER (signum, double, octave::math::signum); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
971 ARRAY_MAPPER (sin, double, ::sin); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
972 ARRAY_MAPPER (sinh, double, ::sinh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
973 RC_ARRAY_MAPPER (sqrt, Complex, octave::math::rc_sqrt); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
974 ARRAY_MAPPER (tan, double, ::tan); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
975 ARRAY_MAPPER (tanh, double, ::tanh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
976 ARRAY_MAPPER (isna, bool, octave::math::isna); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
977 ARRAY_MAPPER (xsignbit, double, octave::math::signbit); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
978 |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
979 // Special cases for Matlab compatibility. |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
980 case umap_xtolower: |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
981 case umap_xtoupper: |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
982 return m_matrix; |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
983 |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
984 case umap_xisalnum: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
985 case umap_xisalpha: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
986 case umap_xisascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
987 case umap_xiscntrl: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
988 case umap_xisdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
989 case umap_xisgraph: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
990 case umap_xislower: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
991 case umap_xisprint: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
992 case umap_xispunct: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
993 case umap_xisspace: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
994 case umap_xisupper: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
995 case umap_xisxdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
996 { |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
997 octave_value str_conv = convert_to_str (true, true); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
998 return str_conv.map (umap); |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
999 } |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
1000 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
1001 default: |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1002 return octave_base_value::map (umap); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
1003 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
1004 } |