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