Mercurial > octave
annotate libinterp/octave-value/ov-cx-sparse.cc @ 33634:4a70f390c85e default tip @
maint: Merge stable to default.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 28 May 2024 15:25:54 +0200 |
parents | 4b601ca024d5 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
3 // Copyright (C) 1998-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
5164 | 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" |
5164 | 28 #endif |
29 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
30 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
31 #include <ostream> |
5164 | 32 #include <vector> |
33 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
34 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
35 #include "lo-mappers.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7740
diff
changeset
|
36 #include "oct-locbuf.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
37 |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
38 #include "mxarray.h" |
5164 | 39 #include "ov-base.h" |
40 #include "ov-scalar.h" | |
41 #include "ov-complex.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
42 #include "errwarn.h" |
5164 | 43 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
44 #include "oct-hdf5.h" |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
45 |
5164 | 46 #include "ov-re-sparse.h" |
47 #include "ov-cx-sparse.h" | |
48 | |
49 #include "ov-base-sparse.h" | |
50 #include "ov-base-sparse.cc" | |
51 | |
52 #include "ov-bool-sparse.h" | |
53 | |
22022
278fc29b69ca
maint: Eliminate unnecessary double newline blocks (only whitespace changes).
Rik <rik@octave.org>
parents:
21885
diff
changeset
|
54 |
29240
0a6ed9dcd601
Silence compiler warnings about ignored attributes (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28126
diff
changeset
|
55 template class octave_base_sparse<SparseComplexMatrix>; |
5164 | 56 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_sparse_complex_matrix, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 "sparse complex matrix", "double"); |
5164 | 59 |
5759 | 60 octave_base_value * |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
61 octave_sparse_complex_matrix::try_narrowing_conversion () |
5164 | 62 { |
30801
568bddf0215e
deprecate sparse_auto_mutate function and internal variable
John W. Eaton <jwe@octave.org>
parents:
30565
diff
changeset
|
63 return (matrix.all_elements_are_real () |
568bddf0215e
deprecate sparse_auto_mutate function and internal variable
John W. Eaton <jwe@octave.org>
parents:
30565
diff
changeset
|
64 ? new octave_sparse_matrix (::real (matrix)) : nullptr); |
5164 | 65 } |
66 | |
67 double | |
68 octave_sparse_complex_matrix::double_value (bool force_conversion) const | |
69 { | |
5781 | 70 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
71 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
72 "complex sparse matrix", "real scalar"); |
5164 | 73 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 // FIXME: maybe this should be a function, valid_as_scalar() |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
75 if (isempty ()) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
76 err_invalid_conversion ("complex sparse matrix", "real scalar"); |
5164 | 77 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
78 if (numel () > 1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
79 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
|
80 "complex sparse matrix", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
81 |
23708
750e42a35adc
Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents:
23619
diff
changeset
|
82 return std::real (matrix(0, 0)); |
5164 | 83 } |
84 | |
85 Matrix | |
86 octave_sparse_complex_matrix::matrix_value (bool force_conversion) const | |
87 { | |
88 Matrix retval; | |
89 | |
5781 | 90 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
91 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
92 "complex sparse matrix", "real matrix"); |
5164 | 93 |
94 retval = ::real (matrix.matrix_value ()); | |
95 | |
96 return retval; | |
97 } | |
98 | |
99 Complex | |
100 octave_sparse_complex_matrix::complex_value (bool) const | |
101 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 // FIXME: maybe this should be a function, valid_as_scalar() |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
103 if (isempty ()) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
104 err_invalid_conversion ("complex sparse matrix", "real scalar"); |
5164 | 105 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
106 if (numel () > 1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
107 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
|
108 "complex sparse matrix", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
109 |
22508
0b278f54f60a
Remove unnecessary initializations in complex_value methods.
Julien Bect <jbect@users.sourceforge.net>
parents:
22477
diff
changeset
|
110 return matrix(0, 0); |
5164 | 111 } |
112 | |
113 ComplexMatrix | |
114 octave_sparse_complex_matrix::complex_matrix_value (bool) const | |
115 { | |
116 return matrix.matrix_value (); | |
117 } | |
118 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
119 ComplexNDArray |
5164 | 120 octave_sparse_complex_matrix::complex_array_value (bool) const |
121 { | |
122 return ComplexNDArray (matrix.matrix_value ()); | |
123 } | |
124 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
125 charNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
126 octave_sparse_complex_matrix::char_array_value (bool frc_str_conv) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
127 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
128 charNDArray retval; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
129 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
130 if (! frc_str_conv) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
131 warn_implicit_conversion ("Octave:num-to-str", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
132 "sparse complex matrix", "string"); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
133 else |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
134 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
135 retval = charNDArray (dims (), 0); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
136 octave_idx_type nc = matrix.cols (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
137 octave_idx_type nr = matrix.rows (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
138 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
139 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
140 for (octave_idx_type i = matrix.cidx (j); i < matrix.cidx (j+1); i++) |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
141 retval(matrix.ridx (i) + nr * j) |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
142 = static_cast<char> (std::real (matrix.data (i))); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
143 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
144 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
145 return retval; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
146 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
147 |
5164 | 148 SparseMatrix |
149 octave_sparse_complex_matrix::sparse_matrix_value (bool force_conversion) const | |
150 { | |
151 SparseMatrix retval; | |
152 | |
5781 | 153 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
154 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
155 "complex sparse matrix", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
156 "real sparse matrix"); |
5164 | 157 |
158 retval = ::real (matrix); | |
159 | |
160 return retval; | |
161 } | |
162 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
163 SparseBoolMatrix |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
164 octave_sparse_complex_matrix::sparse_bool_matrix_value (bool warn) const |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
165 { |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
166 if (matrix.any_element_is_nan ()) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
167 octave::err_nan_to_logical_conversion (); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
168 if (warn && (! matrix.all_elements_are_real () |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
169 || real (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:
21022
diff
changeset
|
170 warn_logical_conversion (); |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
171 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
172 return mx_el_ne (matrix, Complex (0.0)); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
173 } |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
174 |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
175 octave_value |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
176 octave_sparse_complex_matrix::as_double () const |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
177 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
178 return this->matrix; |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
179 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
180 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
181 bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
182 octave_sparse_complex_matrix::save_binary (std::ostream& os, |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
183 bool save_as_floats) |
5164 | 184 { |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
185 const dim_vector& dv = this->dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
186 if (dv.ndims () < 1) |
5164 | 187 return false; |
188 | |
189 // Ensure that additional memory is deallocated | |
190 matrix.maybe_compress (); | |
191 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
192 int nr = dv(0); |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
193 int nc = dv(1); |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
194 int nz = nnz (); |
5164 | 195 |
5828 | 196 int32_t itmp; |
5164 | 197 // Use negative value for ndims to be consistent with other formats |
18738
3bffa847d215
maint: Use space after variable name and before equals sign.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
198 itmp = -2; |
5760 | 199 os.write (reinterpret_cast<char *> (&itmp), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
200 |
18738
3bffa847d215
maint: Use space after variable name and before equals sign.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
201 itmp = nr; |
5760 | 202 os.write (reinterpret_cast<char *> (&itmp), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
203 |
18738
3bffa847d215
maint: Use space after variable name and before equals sign.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
204 itmp = nc; |
5760 | 205 os.write (reinterpret_cast<char *> (&itmp), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
206 |
18738
3bffa847d215
maint: Use space after variable name and before equals sign.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
207 itmp = nz; |
5760 | 208 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 209 |
210 save_type st = LS_DOUBLE; | |
211 if (save_as_floats) | |
212 { | |
213 if (matrix.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
214 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
215 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
216 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 } |
5164 | 218 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
219 st = LS_FLOAT; |
5164 | 220 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
221 else if (matrix.nnz () > 8192) // FIXME: make this configurable. |
5164 | 222 { |
223 double max_val, min_val; | |
224 if (matrix.all_integers (max_val, min_val)) | |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
225 st = octave::get_save_type (max_val, min_val); |
5164 | 226 } |
227 | |
228 // add one to the printed indices to go from | |
229 // zero-based to one-based arrays | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
230 for (int i = 0; i < nc+1; i++) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
231 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
232 octave_quit (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
233 itmp = matrix.cidx (i); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
234 os.write (reinterpret_cast<char *> (&itmp), 4); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
235 } |
5164 | 236 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
237 for (int i = 0; i < nz; i++) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
238 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
239 octave_quit (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
240 itmp = matrix.ridx (i); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
241 os.write (reinterpret_cast<char *> (&itmp), 4); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
242 } |
5164 | 243 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
244 write_doubles (os, reinterpret_cast<const double *> (matrix.data ()), st, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
245 2 * nz); |
5164 | 246 |
247 return true; | |
248 } | |
249 | |
250 bool | |
251 octave_sparse_complex_matrix::load_binary (std::istream& is, bool swap, | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
252 octave::mach_info::float_format fmt) |
5164 | 253 { |
5828 | 254 int32_t nz, nc, nr, tmp; |
5327 | 255 char ctmp; |
256 | |
5760 | 257 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164 | 258 return false; |
259 | |
260 if (swap) | |
261 swap_bytes<4> (&tmp); | |
262 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
263 if (tmp != -2) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
264 error ("load: only 2-D sparse matrices are supported"); |
5164 | 265 |
5760 | 266 if (! is.read (reinterpret_cast<char *> (&nr), 4)) |
5164 | 267 return false; |
5760 | 268 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
5164 | 269 return false; |
5760 | 270 if (! is.read (reinterpret_cast<char *> (&nz), 4)) |
5164 | 271 return false; |
272 | |
273 if (swap) | |
274 { | |
275 swap_bytes<4> (&nr); | |
276 swap_bytes<4> (&nc); | |
277 swap_bytes<4> (&nz); | |
278 } | |
279 | |
5275 | 280 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
281 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 static_cast<octave_idx_type> (nz)); |
5164 | 283 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
284 for (int i = 0; i < nc+1; i++) |
5164 | 285 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
286 octave_quit (); |
5760 | 287 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 return false; |
5164 | 289 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
290 swap_bytes<4> (&tmp); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
291 m.cidx (i) = tmp; |
5164 | 292 } |
293 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
294 for (int i = 0; i < nz; i++) |
5164 | 295 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
296 octave_quit (); |
5760 | 297 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 return false; |
5164 | 299 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 swap_bytes<4> (&tmp); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
301 m.ridx (i) = tmp; |
5164 | 302 } |
303 | |
5760 | 304 if (! is.read (reinterpret_cast<char *> (&ctmp), 1)) |
5164 | 305 return false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
306 |
5760 | 307 read_doubles (is, reinterpret_cast<double *> (m.data ()), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 static_cast<save_type> (ctmp), 2 * nz, swap, fmt); |
5164 | 309 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
310 if (! is) |
5164 | 311 return false; |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
312 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
313 if (! m.indices_ok ()) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
314 return false; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
315 |
5164 | 316 matrix = m; |
317 | |
318 return true; | |
319 } | |
320 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
321 bool |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
322 octave_sparse_complex_matrix::save_hdf5 (octave_hdf5_id loc_id, |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
323 const char *name, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
324 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:
19697
diff
changeset
|
325 { |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
326 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:
19697
diff
changeset
|
327 |
5164 | 328 #if defined (HAVE_HDF5) |
5900 | 329 |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
330 const dim_vector& dv = dims (); |
5164 | 331 int empty = save_hdf5_empty (loc_id, name, dv); |
332 if (empty) | |
333 return (empty > 0); | |
334 | |
335 // Ensure that additional memory is deallocated | |
336 matrix.maybe_compress (); | |
337 | |
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
|
338 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
339 hid_t group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
340 octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
341 #else |
5164 | 342 hid_t group_hid = H5Gcreate (loc_id, name, 0); |
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
|
343 #endif |
5164 | 344 if (group_hid < 0) |
345 return false; | |
346 | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
347 hid_t space_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
348 space_hid = data_hid = -1; |
5164 | 349 SparseComplexMatrix m = sparse_complex_matrix_value (); |
5351 | 350 octave_idx_type tmp; |
5164 | 351 hsize_t hdims[2]; |
352 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
353 space_hid = H5Screate_simple (0, hdims, nullptr); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
354 if (space_hid < 0) |
5164 | 355 { |
356 H5Gclose (group_hid); | |
357 return false; | |
358 } | |
359 | |
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
|
360 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
361 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
362 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
363 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
|
364 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
365 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, 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
|
366 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
|
367 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
368 if (data_hid < 0) |
5164 | 369 { |
370 H5Sclose (space_hid); | |
371 H5Gclose (group_hid); | |
372 return false; | |
373 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
374 |
5164 | 375 tmp = m.rows (); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
376 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, 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
|
377 octave_H5P_DEFAULT, &tmp) >= 0; |
5164 | 378 H5Dclose (data_hid); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
379 if (! retval) |
5164 | 380 { |
381 H5Sclose (space_hid); | |
382 H5Gclose (group_hid); | |
383 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
384 } |
5164 | 385 |
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
|
386 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
387 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
388 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
389 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
|
390 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
391 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, 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
|
392 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
|
393 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
394 if (data_hid < 0) |
5164 | 395 { |
396 H5Sclose (space_hid); | |
397 H5Gclose (group_hid); | |
398 return false; | |
399 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
400 |
5164 | 401 tmp = m.cols (); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
402 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, 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
|
403 octave_H5P_DEFAULT, &tmp) >= 0; |
5164 | 404 H5Dclose (data_hid); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
405 if (! retval) |
5164 | 406 { |
407 H5Sclose (space_hid); | |
408 H5Gclose (group_hid); | |
409 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
410 } |
5164 | 411 |
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
|
412 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
413 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
414 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
415 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
|
416 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
417 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, 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
|
418 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
|
419 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
420 if (data_hid < 0) |
5164 | 421 { |
422 H5Sclose (space_hid); | |
423 H5Gclose (group_hid); | |
424 return false; | |
425 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
426 |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
427 tmp = m.nnz (); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
428 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, 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
|
429 octave_H5P_DEFAULT, &tmp) >= 0; |
5164 | 430 H5Dclose (data_hid); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
431 if (! retval) |
5164 | 432 { |
433 H5Sclose (space_hid); | |
434 H5Gclose (group_hid); | |
435 return false; | |
436 } | |
437 | |
438 H5Sclose (space_hid); | |
439 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14469
diff
changeset
|
440 hdims[0] = m.cols () + 1; |
5164 | 441 hdims[1] = 1; |
442 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
443 space_hid = H5Screate_simple (2, hdims, nullptr); |
5164 | 444 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
445 if (space_hid < 0) |
5164 | 446 { |
447 H5Gclose (group_hid); | |
448 return false; | |
449 } | |
450 | |
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
|
451 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
452 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
453 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
454 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
|
455 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
456 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, 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
|
457 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
|
458 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
459 if (data_hid < 0) |
5164 | 460 { |
461 H5Sclose (space_hid); | |
462 H5Gclose (group_hid); | |
463 return false; | |
464 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
465 |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
466 octave_idx_type *itmp = m.xcidx (); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
467 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, 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
|
468 octave_H5P_DEFAULT, itmp) >= 0; |
5164 | 469 H5Dclose (data_hid); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
470 if (! retval) |
5164 | 471 { |
472 H5Sclose (space_hid); | |
473 H5Gclose (group_hid); | |
474 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
475 } |
5164 | 476 |
477 H5Sclose (space_hid); | |
478 | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
479 hdims[0] = m.nnz (); |
5164 | 480 hdims[1] = 1; |
481 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
482 space_hid = H5Screate_simple (2, hdims, nullptr); |
5164 | 483 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
484 if (space_hid < 0) |
5164 | 485 { |
486 H5Gclose (group_hid); | |
487 return false; | |
488 } | |
489 | |
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
|
490 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
491 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
492 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
493 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
|
494 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
495 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, 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
|
496 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
|
497 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
498 if (data_hid < 0) |
5164 | 499 { |
500 H5Sclose (space_hid); | |
501 H5Gclose (group_hid); | |
502 return false; | |
503 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
504 |
5164 | 505 itmp = m.xridx (); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
506 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
507 octave_H5P_DEFAULT, itmp) >= 0; |
5164 | 508 H5Dclose (data_hid); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
509 if (! retval) |
5164 | 510 { |
511 H5Sclose (space_hid); | |
512 H5Gclose (group_hid); | |
513 return false; | |
514 } | |
515 | |
516 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
517 | |
518 if (save_as_floats) | |
519 { | |
520 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 } |
5164 | 525 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 save_type_hid = H5T_NATIVE_FLOAT; |
5164 | 527 } |
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
|
528 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS) |
5164 | 529 // hdf5 currently doesn't support float/integer conversions |
530 else | |
531 { | |
532 double max_val, min_val; | |
533 | |
534 if (m.all_integers (max_val, min_val)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
535 save_type_hid |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
536 = save_type_to_hdf5 (octave::get_save_type (max_val, min_val)); |
5164 | 537 } |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
538 #endif |
5164 | 539 |
540 hid_t type_hid = hdf5_make_complex_type (save_type_hid); | |
541 if (type_hid < 0) | |
542 { | |
543 H5Sclose (space_hid); | |
544 H5Gclose (group_hid); | |
545 return false; | |
546 } | |
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
|
547 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
548 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
549 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
550 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
|
551 #else |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
552 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
553 octave_H5P_DEFAULT); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
554 #endif |
5164 | 555 if (data_hid < 0) |
556 { | |
557 H5Sclose (space_hid); | |
558 H5Tclose (type_hid); | |
559 H5Gclose (group_hid); | |
560 return false; | |
561 } | |
562 | |
563 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
564 retval = false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
565 if (complex_type_hid >= 0) |
5164 | 566 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
567 Complex *ctmp = m.xdata (); |
5164 | 568 |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
569 retval = H5Dwrite (data_hid, complex_type_hid, octave_H5S_ALL, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30006
diff
changeset
|
570 octave_H5S_ALL, octave_H5P_DEFAULT, ctmp) >= 0; |
5164 | 571 } |
572 | |
573 H5Dclose (data_hid); | |
574 H5Sclose (space_hid); | |
575 H5Tclose (type_hid); | |
576 H5Gclose (group_hid); | |
577 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
578 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
579 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
580 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
581 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
|
582 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
583 warn_save ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
584 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
585 |
5164 | 586 return retval; |
587 } | |
588 | |
589 bool | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
590 octave_sparse_complex_matrix::load_hdf5 (octave_hdf5_id loc_id, |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
591 const char *name) |
5164 | 592 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
593 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:
19697
diff
changeset
|
594 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
595 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
596 |
5351 | 597 octave_idx_type nr, nc, nz; |
5164 | 598 hid_t group_hid, data_hid, space_hid; |
599 hsize_t rank; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
600 |
5164 | 601 dim_vector dv; |
602 int empty = load_hdf5_empty (loc_id, name, dv); | |
603 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
604 matrix.resize (dv); |
5164 | 605 if (empty) |
606 return (empty > 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
607 |
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
|
608 #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
|
609 group_hid = H5Gopen (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
|
610 #else |
5164 | 611 group_hid = H5Gopen (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
|
612 #endif |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
613 if (group_hid < 0) return false; |
5164 | 614 |
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
|
615 #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
|
616 data_hid = H5Dopen (group_hid, "nr", 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
|
617 #else |
5164 | 618 data_hid = H5Dopen (group_hid, "nr"); |
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
|
619 #endif |
5164 | 620 space_hid = H5Dget_space (data_hid); |
621 rank = H5Sget_simple_extent_ndims (space_hid); | |
622 | |
623 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
624 { |
5164 | 625 H5Dclose (data_hid); |
626 H5Gclose (group_hid); | |
627 return false; | |
628 } | |
629 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
630 if (H5Dread (data_hid, H5T_NATIVE_IDX, 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
|
631 octave_H5S_ALL, octave_H5P_DEFAULT, &nr) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
632 { |
5164 | 633 H5Dclose (data_hid); |
634 H5Gclose (group_hid); | |
635 return false; | |
636 } | |
637 | |
638 H5Dclose (data_hid); | |
639 | |
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
|
640 #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
|
641 data_hid = H5Dopen (group_hid, "nc", 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
|
642 #else |
5164 | 643 data_hid = H5Dopen (group_hid, "nc"); |
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
|
644 #endif |
5164 | 645 space_hid = H5Dget_space (data_hid); |
646 rank = H5Sget_simple_extent_ndims (space_hid); | |
647 | |
648 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
649 { |
5164 | 650 H5Dclose (data_hid); |
651 H5Gclose (group_hid); | |
652 return false; | |
653 } | |
654 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
655 if (H5Dread (data_hid, H5T_NATIVE_IDX, 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
|
656 octave_H5S_ALL, octave_H5P_DEFAULT, &nc) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
657 { |
5164 | 658 H5Dclose (data_hid); |
659 H5Gclose (group_hid); | |
660 return false; | |
661 } | |
662 | |
663 H5Dclose (data_hid); | |
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
|
664 |
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
|
665 #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
|
666 data_hid = H5Dopen (group_hid, "nz", 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
|
667 #else |
5164 | 668 data_hid = H5Dopen (group_hid, "nz"); |
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
|
669 #endif |
5164 | 670 space_hid = H5Dget_space (data_hid); |
671 rank = H5Sget_simple_extent_ndims (space_hid); | |
672 | |
673 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
674 { |
5164 | 675 H5Dclose (data_hid); |
676 H5Gclose (group_hid); | |
677 return false; | |
678 } | |
679 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
680 if (H5Dread (data_hid, H5T_NATIVE_IDX, 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
|
681 octave_H5S_ALL, octave_H5P_DEFAULT, &nz) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
682 { |
5164 | 683 H5Dclose (data_hid); |
684 H5Gclose (group_hid); | |
685 return false; | |
686 } | |
687 | |
688 H5Dclose (data_hid); | |
689 | |
5275 | 690 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
691 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 static_cast<octave_idx_type> (nz)); |
5164 | 693 |
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
|
694 #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
|
695 data_hid = H5Dopen (group_hid, "cidx", 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
|
696 #else |
5164 | 697 data_hid = H5Dopen (group_hid, "cidx"); |
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
|
698 #endif |
5164 | 699 space_hid = H5Dget_space (data_hid); |
700 rank = H5Sget_simple_extent_ndims (space_hid); | |
701 | |
702 if (rank != 2) | |
703 { | |
704 H5Sclose (space_hid); | |
705 H5Dclose (data_hid); | |
706 H5Gclose (group_hid); | |
707 return false; | |
708 } | |
709 | |
710 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
711 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
712 | |
713 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
714 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
715 if (static_cast<int> (hdims[0]) != nc + 1 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
716 || static_cast<int> (hdims[1]) != 1) |
5164 | 717 { |
718 H5Sclose (space_hid); | |
719 H5Dclose (data_hid); | |
720 H5Gclose (group_hid); | |
721 return false; | |
722 } | |
723 | |
5351 | 724 octave_idx_type *itmp = m.xcidx (); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
725 if (H5Dread (data_hid, H5T_NATIVE_IDX, 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
|
726 octave_H5S_ALL, octave_H5P_DEFAULT, itmp) < 0) |
5164 | 727 { |
728 H5Sclose (space_hid); | |
729 H5Dclose (data_hid); | |
730 H5Gclose (group_hid); | |
731 return false; | |
732 } | |
733 | |
734 H5Sclose (space_hid); | |
735 H5Dclose (data_hid); | |
736 | |
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
|
737 #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
|
738 data_hid = H5Dopen (group_hid, "ridx", 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
|
739 #else |
5164 | 740 data_hid = H5Dopen (group_hid, "ridx"); |
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
|
741 #endif |
5164 | 742 space_hid = H5Dget_space (data_hid); |
743 rank = H5Sget_simple_extent_ndims (space_hid); | |
744 | |
745 if (rank != 2) | |
746 { | |
747 H5Sclose (space_hid); | |
748 H5Dclose (data_hid); | |
749 H5Gclose (group_hid); | |
750 return false; | |
751 } | |
752 | |
753 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
754 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
755 if (static_cast<int> (hdims[0]) != nz |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
756 || static_cast<int> (hdims[1]) != 1) |
5164 | 757 { |
758 H5Sclose (space_hid); | |
759 H5Dclose (data_hid); | |
760 H5Gclose (group_hid); | |
761 return false; | |
762 } | |
763 | |
764 itmp = m.xridx (); | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
765 if (H5Dread (data_hid, H5T_NATIVE_IDX, 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
|
766 octave_H5S_ALL, octave_H5P_DEFAULT, itmp) < 0) |
5164 | 767 { |
768 H5Sclose (space_hid); | |
769 H5Dclose (data_hid); | |
770 H5Gclose (group_hid); | |
771 return false; | |
772 } | |
773 | |
774 H5Sclose (space_hid); | |
775 H5Dclose (data_hid); | |
776 | |
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
|
777 #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
|
778 data_hid = H5Dopen (group_hid, "data", 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
|
779 #else |
5164 | 780 data_hid = H5Dopen (group_hid, "data"); |
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
|
781 #endif |
5164 | 782 hid_t type_hid = H5Dget_type (data_hid); |
783 | |
784 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
785 | |
786 if (! hdf5_types_compatible (type_hid, complex_type)) | |
787 { | |
788 H5Tclose (complex_type); | |
789 H5Dclose (data_hid); | |
790 H5Gclose (group_hid); | |
791 return false; | |
792 } | |
793 | |
794 space_hid = H5Dget_space (data_hid); | |
795 rank = H5Sget_simple_extent_ndims (space_hid); | |
796 | |
797 if (rank != 2) | |
798 { | |
799 H5Sclose (space_hid); | |
800 H5Dclose (data_hid); | |
801 H5Gclose (group_hid); | |
802 return false; | |
803 } | |
804 | |
805 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
806 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
807 if (static_cast<int> (hdims[0]) != nz |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
808 || static_cast<int> (hdims[1]) != 1) |
5164 | 809 { |
810 H5Sclose (space_hid); | |
811 H5Dclose (data_hid); | |
812 H5Gclose (group_hid); | |
813 return false; | |
814 } | |
815 | |
816 Complex *ctmp = m.xdata (); | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
817 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
818 if (H5Dread (data_hid, complex_type, 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
|
819 octave_H5P_DEFAULT, ctmp) >= 0 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
820 && m.indices_ok ()) |
5164 | 821 { |
822 retval = true; | |
823 matrix = m; | |
824 } | |
825 | |
826 H5Tclose (complex_type); | |
827 H5Sclose (space_hid); | |
828 H5Dclose (data_hid); | |
829 H5Gclose (group_hid); | |
830 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
831 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
832 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
833 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
834 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
835 warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
836 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
837 |
5164 | 838 return retval; |
839 } | |
840 | |
5900 | 841 mxArray * |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
842 octave_sparse_complex_matrix::as_mxArray (bool interleaved) const |
5900 | 843 { |
6686 | 844 mwSize nz = nzmax (); |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
845 mwSize nr = rows (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
846 mwSize nc = columns (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
847 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
848 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz, |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
849 mxCOMPLEX); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
850 |
6686 | 851 mwIndex *ir = retval->get_ir (); |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
852 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
853 const Complex *pdata = matrix.data (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
854 const octave_idx_type *pridx = matrix.ridx (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
855 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
856 if (interleaved) |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
857 { |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
858 mxComplexDouble *pd |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
859 = static_cast<mxComplexDouble *> (retval->get_data ()); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
860 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
861 for (mwIndex i = 0; i < nz; i++) |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
862 { |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
863 pd[i].real = pdata[i].real (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
864 pd[i].imag = pdata[i].imag (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
865 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
866 ir[i] = pridx[i]; |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
867 } |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
868 } |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
869 else |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
870 { |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
871 mxDouble *pr = static_cast<mxDouble *> (retval->get_data ()); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
872 mxDouble *pi = static_cast<mxDouble *> (retval->get_imag_data ()); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
873 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
874 for (mwIndex i = 0; i < nz; i++) |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
875 { |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
876 pr[i] = pdata[i].real (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
877 pi[i] = pdata[i].imag (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
878 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
879 ir[i] = pridx[i]; |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
880 } |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
881 } |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
882 |
6686 | 883 mwIndex *jc = retval->get_jc (); |
5903 | 884 |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
885 const octave_idx_type *pcidx = matrix.cidx (); |
5903 | 886 |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
887 for (mwIndex i = 0; i < nc + 1; i++) |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
888 jc[i] = pcidx[i]; |
5903 | 889 |
890 return retval; | |
5900 | 891 } |
892 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
893 octave_value |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
894 octave_sparse_complex_matrix::map (unary_mapper_t umap) const |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
895 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
896 switch (umap) |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
897 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
898 // Mappers handled specially. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
899 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
900 return ::real (matrix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
901 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
902 return ::imag (matrix); |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
903 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
904 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
905 case umap_ ## UMAP: \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
906 return octave_value (matrix.FCN ()) |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
907 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
908 ARRAY_METHOD_MAPPER (abs, abs); |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
909 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
910 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
911 case umap_ ## UMAP: \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
912 return octave_value (matrix.map<TYPE> (FCN)) |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
913 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
914 ARRAY_MAPPER (acos, Complex, octave::math::acos); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
915 ARRAY_MAPPER (acosh, Complex, octave::math::acosh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
916 ARRAY_MAPPER (angle, double, std::arg); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
917 ARRAY_MAPPER (arg, double, std::arg); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
918 ARRAY_MAPPER (asin, Complex, octave::math::asin); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
919 ARRAY_MAPPER (asinh, Complex, octave::math::asinh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
920 ARRAY_MAPPER (atan, Complex, octave::math::atan); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
921 ARRAY_MAPPER (atanh, Complex, octave::math::atanh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
922 ARRAY_MAPPER (erf, Complex, octave::math::erf); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
923 ARRAY_MAPPER (erfc, Complex, octave::math::erfc); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
924 ARRAY_MAPPER (erfcx, Complex, octave::math::erfcx); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
925 ARRAY_MAPPER (erfi, Complex, octave::math::erfi); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
926 ARRAY_MAPPER (dawson, Complex, octave::math::dawson); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
927 ARRAY_MAPPER (ceil, Complex, octave::math::ceil); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
928 ARRAY_MAPPER (conj, Complex, std::conj<double>); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
929 ARRAY_MAPPER (cos, Complex, std::cos); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
930 ARRAY_MAPPER (cosh, Complex, std::cosh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
931 ARRAY_MAPPER (exp, Complex, std::exp); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
932 ARRAY_MAPPER (expm1, Complex, octave::math::expm1); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
933 ARRAY_MAPPER (fix, Complex, octave::math::fix); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
934 ARRAY_MAPPER (floor, Complex, octave::math::floor); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
935 ARRAY_MAPPER (log, Complex, std::log); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
936 ARRAY_MAPPER (log2, Complex, octave::math::log2); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
937 ARRAY_MAPPER (log10, Complex, std::log10); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
938 ARRAY_MAPPER (log1p, Complex, octave::math::log1p); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
939 ARRAY_MAPPER (round, Complex, octave::math::round); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
940 ARRAY_MAPPER (roundb, Complex, octave::math::roundb); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
941 ARRAY_MAPPER (signum, Complex, octave::math::signum); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
942 ARRAY_MAPPER (sin, Complex, std::sin); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
943 ARRAY_MAPPER (sinh, Complex, std::sinh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
944 ARRAY_MAPPER (sqrt, Complex, std::sqrt); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
945 ARRAY_MAPPER (tan, Complex, std::tan); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
946 ARRAY_MAPPER (tanh, Complex, std::tanh); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
947 ARRAY_MAPPER (isnan, bool, octave::math::isnan); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
948 ARRAY_MAPPER (isna, bool, octave::math::isna); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
949 ARRAY_MAPPER (isinf, bool, octave::math::isinf); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
30801
diff
changeset
|
950 ARRAY_MAPPER (isfinite, bool, octave::math::isfinite); |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
951 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
952 default: // Attempt to go via dense matrix. |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
953 return octave_base_sparse<SparseComplexMatrix>::map (umap); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
954 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
955 } |