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