Mercurial > hg > octave-nkf
annotate src/ov-re-sparse.cc @ 14182:f8d99761244c stable
test: Expand %!testif functionality to multiple conditions
* test.m: Add testing for multiple conditions in %!testif statement.
* svds.m, eigs.cc: Test for ARPACK and other libraries before running
some tests.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 09 Jan 2012 13:32:44 -0800 |
parents | 72c96de7a403 |
children | 29aabe9b37a2 |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2004-2012 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5164 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5164 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5164 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <climits> | |
29 | |
30 #include <iostream> | |
31 #include <vector> | |
32 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
33 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
34 #include "lo-mappers.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
35 #include "oct-locbuf.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
36 |
5164 | 37 #include "ov-base.h" |
38 #include "ov-scalar.h" | |
39 #include "gripes.h" | |
40 | |
41 #include "ls-hdf5.h" | |
42 | |
43 #include "ov-re-sparse.h" | |
44 | |
45 #include "ov-base-sparse.h" | |
46 #include "ov-base-sparse.cc" | |
47 | |
48 #include "ov-bool-sparse.h" | |
49 | |
6109 | 50 template class OCTINTERP_API octave_base_sparse<SparseMatrix>; |
5164 | 51 |
52 DEFINE_OCTAVE_ALLOCATOR (octave_sparse_matrix); | |
53 | |
6823 | 54 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_sparse_matrix, "sparse matrix", "double"); |
5164 | 55 |
5282 | 56 idx_vector |
57 octave_sparse_matrix::index_vector (void) const | |
58 { | |
5604 | 59 if (matrix.numel () == matrix.nnz ()) |
5282 | 60 return idx_vector (array_value ()); |
61 else | |
62 { | |
63 std::string nm = type_name (); | |
64 error ("%s type invalid as index value", nm.c_str ()); | |
65 return idx_vector (); | |
66 } | |
67 } | |
68 | |
5759 | 69 octave_base_value * |
5164 | 70 octave_sparse_matrix::try_narrowing_conversion (void) |
71 { | |
5759 | 72 octave_base_value *retval = 0; |
5164 | 73 |
7193 | 74 if (Vsparse_auto_mutate) |
5164 | 75 { |
7193 | 76 // Don't use numel, since it can overflow for very large matrices |
77 // Note that for the second test, this means it becomes approximative | |
78 // since it involves a cast to double to avoid issues of overflow | |
79 if (matrix.rows () == 1 && matrix.cols () == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
80 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
81 // 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
|
82 const SparseMatrix tmp (matrix); |
5164 | 83 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 retval = new octave_scalar (tmp (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
86 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
|
87 && (double (matrix.byte_size ()) > double (matrix.rows ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 * double (matrix.cols ()) * sizeof (double))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 retval = new octave_matrix (matrix.matrix_value ()); |
5164 | 90 } |
91 | |
92 return retval; | |
93 } | |
94 | |
95 double | |
96 octave_sparse_matrix::double_value (bool) const | |
97 { | |
98 double retval = lo_ieee_nan_value (); | |
99 | |
100 if (numel () > 0) | |
101 { | |
6221 | 102 if (numel () > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 gripe_implicit_conversion ("Octave:array-as-scalar", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
104 "real sparse matrix", "real scalar"); |
5164 | 105 |
106 retval = matrix (0, 0); | |
107 } | |
108 else | |
109 gripe_invalid_conversion ("real sparse matrix", "real scalar"); | |
110 | |
111 return retval; | |
112 } | |
113 | |
114 Complex | |
115 octave_sparse_matrix::complex_value (bool) const | |
116 { | |
117 double tmp = lo_ieee_nan_value (); | |
118 | |
119 Complex retval (tmp, tmp); | |
120 | |
5775 | 121 // FIXME -- maybe this should be a function, valid_as_scalar() |
5164 | 122 if (rows () > 0 && columns () > 0) |
123 { | |
6221 | 124 if (numel () > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 gripe_implicit_conversion ("Octave:array-as-scalar", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
126 "real sparse matrix", "complex scalar"); |
5164 | 127 |
128 retval = matrix (0, 0); | |
129 } | |
130 else | |
131 gripe_invalid_conversion ("real sparse matrix", "complex scalar"); | |
132 | |
133 return retval; | |
134 } | |
135 | |
136 Matrix | |
137 octave_sparse_matrix::matrix_value (bool) const | |
138 { | |
139 return matrix.matrix_value (); | |
140 } | |
141 | |
5898 | 142 boolNDArray |
5943 | 143 octave_sparse_matrix::bool_array_value (bool warn) const |
5898 | 144 { |
5943 | 145 NDArray m = matrix.matrix_value (); |
146 | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
147 if (m.any_element_is_nan ()) |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
148 gripe_nan_to_logical_conversion (); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
149 else if (warn && m.any_element_not_one_or_zero ()) |
5943 | 150 gripe_logical_conversion (); |
151 | |
152 return boolNDArray (m); | |
5898 | 153 } |
154 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
155 charNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
156 octave_sparse_matrix::char_array_value (bool) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
157 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
158 charNDArray retval (dims (), 0); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
159 octave_idx_type nc = matrix.cols (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
160 octave_idx_type nr = matrix.rows (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
161 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
162 for (octave_idx_type j = 0; j < nc; j++) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
163 for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
164 retval(matrix.ridx(i) + nr * j) = static_cast<char>(matrix.data (i)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
165 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
166 return retval; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
167 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
168 |
5164 | 169 ComplexMatrix |
170 octave_sparse_matrix::complex_matrix_value (bool) const | |
171 { | |
172 return ComplexMatrix (matrix.matrix_value ()); | |
173 } | |
174 | |
175 ComplexNDArray | |
176 octave_sparse_matrix::complex_array_value (bool) const | |
177 { | |
178 return ComplexNDArray (ComplexMatrix (matrix.matrix_value ())); | |
179 } | |
180 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
181 NDArray |
5164 | 182 octave_sparse_matrix::array_value (bool) const |
183 { | |
184 return NDArray (matrix.matrix_value ()); | |
185 } | |
186 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
187 SparseBoolMatrix |
9852
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
188 octave_sparse_matrix::sparse_bool_matrix_value (bool warn) const |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
189 { |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
190 if (matrix.any_element_is_nan ()) |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
191 gripe_nan_to_logical_conversion (); |
9852
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
192 else if (warn && matrix.any_element_not_one_or_zero ()) |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
193 gripe_logical_conversion (); |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
194 |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
195 return mx_el_ne (matrix, 0.0); |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
196 } |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9835
diff
changeset
|
197 |
5282 | 198 octave_value |
5322 | 199 octave_sparse_matrix::convert_to_str_internal (bool, bool, char type) const |
5282 | 200 { |
201 octave_value retval; | |
202 dim_vector dv = dims (); | |
203 octave_idx_type nel = dv.numel (); | |
204 | |
205 if (nel == 0) | |
206 { | |
207 char s = '\0'; | |
5322 | 208 retval = octave_value (&s, type); |
5282 | 209 } |
210 else | |
211 { | |
212 octave_idx_type nr = matrix.rows (); | |
213 octave_idx_type nc = matrix.cols (); | |
214 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
|
215 |
5282 | 216 bool warned = false; |
217 | |
218 for (octave_idx_type j = 0; j < nc; j++) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 for (octave_idx_type i = matrix.cidx(j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
220 i < matrix.cidx(j+1); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
221 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
222 octave_quit (); |
5282 | 223 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
224 double d = matrix.data (i); |
5282 | 225 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
226 if (xisnan (d)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
227 { |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
228 gripe_nan_to_character_conversion (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
229 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
230 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
231 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
232 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
233 int ival = NINT (d); |
5282 | 234 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 if (ival < 0 || ival > UCHAR_MAX) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 // FIXME -- is there something |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 // better we could do? |
5282 | 239 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 ival = 0; |
5282 | 241 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 if (! warned) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 ::warning ("range error for conversion to character value"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
245 warned = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 } |
5282 | 248 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
249 chm (matrix.ridx(i) + j * nr) = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
250 static_cast<char> (ival); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 } |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9470
diff
changeset
|
253 |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9470
diff
changeset
|
254 retval = octave_value (chm, type); |
5282 | 255 } |
256 | |
257 return retval; | |
258 } | |
259 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
260 bool |
5164 | 261 octave_sparse_matrix::save_binary (std::ostream& os, bool&save_as_floats) |
262 { | |
263 dim_vector d = this->dims (); | |
264 if (d.length() < 1) | |
265 return false; | |
266 | |
267 // Ensure that additional memory is deallocated | |
268 matrix.maybe_compress (); | |
269 | |
270 int nr = d(0); | |
271 int nc = d(1); | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10414
diff
changeset
|
272 int nz = nnz (); |
5164 | 273 |
5828 | 274 int32_t itmp; |
5164 | 275 // Use negative value for ndims to be consistent with other formats |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
276 itmp= -2; |
5760 | 277 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
|
278 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
279 itmp= nr; |
5760 | 280 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
|
281 |
5164 | 282 itmp= nc; |
5760 | 283 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
|
284 |
5164 | 285 itmp= nz; |
5760 | 286 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 287 |
288 save_type st = LS_DOUBLE; | |
289 if (save_as_floats) | |
290 { | |
291 if (matrix.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 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
|
294 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
295 } |
5164 | 296 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 st = LS_FLOAT; |
5164 | 298 } |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10414
diff
changeset
|
299 else if (matrix.nnz () > 8192) // FIXME -- make this configurable. |
5164 | 300 { |
301 double max_val, min_val; | |
302 if (matrix.all_integers (max_val, min_val)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 st = get_save_type (max_val, min_val); |
5164 | 304 } |
305 | |
306 // add one to the printed indices to go from | |
307 // zero-based to one-based arrays | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
308 for (int i = 0; i < nc+1; i++) |
5164 | 309 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
310 octave_quit (); |
5164 | 311 itmp = matrix.cidx(i); |
5760 | 312 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 313 } |
314 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
315 for (int i = 0; i < nz; i++) |
5164 | 316 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
317 octave_quit (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
318 itmp = matrix.ridx(i); |
5760 | 319 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 320 } |
321 | |
322 write_doubles (os, matrix.data(), st, nz); | |
323 | |
324 return true; | |
325 } | |
326 | |
327 bool | |
328 octave_sparse_matrix::load_binary (std::istream& is, bool swap, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 oct_mach_info::float_format fmt) |
5164 | 330 { |
5828 | 331 int32_t nz, nc, nr, tmp; |
5327 | 332 char ctmp; |
333 | |
5760 | 334 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164 | 335 return false; |
336 | |
337 if (swap) | |
338 swap_bytes<4> (&tmp); | |
339 | |
340 if (tmp != -2) { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
341 error ("load: only 2D sparse matrices are supported"); |
5164 | 342 return false; |
343 } | |
344 | |
5760 | 345 if (! is.read (reinterpret_cast<char *> (&nr), 4)) |
5164 | 346 return false; |
5760 | 347 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
5164 | 348 return false; |
5760 | 349 if (! is.read (reinterpret_cast<char *> (&nz), 4)) |
5164 | 350 return false; |
351 | |
352 if (swap) | |
353 { | |
354 swap_bytes<4> (&nr); | |
355 swap_bytes<4> (&nc); | |
356 swap_bytes<4> (&nz); | |
357 } | |
358 | |
5275 | 359 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
|
360 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
361 static_cast<octave_idx_type> (nz)); |
5164 | 362 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
363 for (int i = 0; i < nc+1; i++) |
5164 | 364 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
365 octave_quit (); |
5760 | 366 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
|
367 return false; |
5164 | 368 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 swap_bytes<4> (&tmp); |
5164 | 370 m.xcidx(i) = tmp; |
371 } | |
372 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
373 for (int i = 0; i < nz; i++) |
5164 | 374 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
375 octave_quit (); |
5760 | 376 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
|
377 return false; |
5164 | 378 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
379 swap_bytes<4> (&tmp); |
5164 | 380 m.xridx(i) = tmp; |
381 } | |
382 | |
5760 | 383 if (! is.read (reinterpret_cast<char *> (&ctmp), 1)) |
5164 | 384 return false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
385 |
5760 | 386 read_doubles (is, m.xdata (), static_cast<save_type> (ctmp), nz, swap, fmt); |
5164 | 387 |
388 if (error_state || ! is) | |
389 return false; | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
390 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
391 if (! m.indices_ok ()) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
392 return false; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
393 |
5164 | 394 matrix = m; |
395 | |
396 return true; | |
397 } | |
398 | |
399 #if defined (HAVE_HDF5) | |
5900 | 400 |
5164 | 401 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
402 octave_sparse_matrix::save_hdf5 (hid_t loc_id, const char *name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
403 bool save_as_floats) |
5164 | 404 { |
405 dim_vector dv = dims (); | |
406 int empty = save_hdf5_empty (loc_id, name, dv); | |
407 if (empty) | |
408 return (empty > 0); | |
409 | |
410 // Ensure that additional memory is deallocated | |
411 matrix.maybe_compress (); | |
412 | |
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
|
413 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
414 hid_t group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
415 #else |
5164 | 416 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
|
417 #endif |
5164 | 418 if (group_hid < 0) |
419 return false; | |
420 | |
421 hid_t space_hid = -1, data_hid = -1; | |
422 bool retval = true; | |
423 SparseMatrix m = sparse_matrix_value (); | |
5351 | 424 octave_idx_type tmp; |
5164 | 425 hsize_t hdims[2]; |
426 | |
5760 | 427 space_hid = H5Screate_simple (0, hdims, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
428 if (space_hid < 0) |
5164 | 429 { |
430 H5Gclose (group_hid); | |
431 return false; | |
432 } | |
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
|
433 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
434 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
435 H5P_DEFAULT, H5P_DEFAULT, 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
|
436 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
437 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
438 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
|
439 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
440 if (data_hid < 0) |
5164 | 441 { |
442 H5Sclose (space_hid); | |
443 H5Gclose (group_hid); | |
444 return false; | |
445 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
446 |
5164 | 447 tmp = m.rows (); |
5351 | 448 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
449 &tmp) >= 0; |
5164 | 450 H5Dclose (data_hid); |
451 if (!retval) | |
452 { | |
453 H5Sclose (space_hid); | |
454 H5Gclose (group_hid); | |
455 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
456 } |
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
|
457 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
458 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
459 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
460 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
461 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
462 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
463 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
464 if (data_hid < 0) |
5164 | 465 { |
466 H5Sclose (space_hid); | |
467 H5Gclose (group_hid); | |
468 return false; | |
469 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
470 |
5164 | 471 tmp = m.cols (); |
5351 | 472 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
473 &tmp) >= 0; |
5164 | 474 H5Dclose (data_hid); |
475 if (!retval) | |
476 { | |
477 H5Sclose (space_hid); | |
478 H5Gclose (group_hid); | |
479 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
480 } |
5164 | 481 |
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
|
482 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
483 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
484 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
485 #else |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
486 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
487 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
|
488 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
489 if (data_hid < 0) |
5164 | 490 { |
491 H5Sclose (space_hid); | |
492 H5Gclose (group_hid); | |
493 return false; | |
494 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
495 |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10414
diff
changeset
|
496 tmp = m.nnz (); |
5351 | 497 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 &tmp) >= 0; |
5164 | 499 H5Dclose (data_hid); |
500 if (!retval) | |
501 { | |
502 H5Sclose (space_hid); | |
503 H5Gclose (group_hid); | |
504 return false; | |
505 } | |
506 | |
507 H5Sclose (space_hid); | |
508 | |
509 hdims[0] = m.cols() + 1; | |
510 hdims[1] = 1; | |
511 | |
512 space_hid = H5Screate_simple (2, hdims, 0); | |
513 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
514 if (space_hid < 0) |
5164 | 515 { |
516 H5Gclose (group_hid); | |
517 return false; | |
518 } | |
519 | |
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
|
520 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
521 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 H5P_DEFAULT, H5P_DEFAULT, 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
|
523 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
524 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 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
|
526 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
527 if (data_hid < 0) |
5164 | 528 { |
529 H5Sclose (space_hid); | |
530 H5Gclose (group_hid); | |
531 return false; | |
532 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
533 |
5351 | 534 octave_idx_type * itmp = m.xcidx (); |
535 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
536 itmp) >= 0; |
5164 | 537 H5Dclose (data_hid); |
538 if (!retval) | |
539 { | |
540 H5Sclose (space_hid); | |
541 H5Gclose (group_hid); | |
542 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
543 } |
5164 | 544 |
545 H5Sclose (space_hid); | |
546 | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10414
diff
changeset
|
547 hdims[0] = m.nnz (); |
5164 | 548 hdims[1] = 1; |
549 | |
550 space_hid = H5Screate_simple (2, hdims, 0); | |
551 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
552 if (space_hid < 0) |
5164 | 553 { |
554 H5Gclose (group_hid); | |
555 return false; | |
556 } | |
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
|
557 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
558 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
559 H5P_DEFAULT, H5P_DEFAULT, 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
|
560 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
561 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 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
|
563 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
564 if (data_hid < 0) |
5164 | 565 { |
566 H5Sclose (space_hid); | |
567 H5Gclose (group_hid); | |
568 return false; | |
569 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
570 |
5164 | 571 itmp = m.xridx (); |
5351 | 572 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
573 itmp) >= 0; |
5164 | 574 H5Dclose (data_hid); |
575 if (!retval) | |
576 { | |
577 H5Sclose (space_hid); | |
578 H5Gclose (group_hid); | |
579 return false; | |
580 } | |
581 | |
582 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
583 | |
584 if (save_as_floats) | |
585 { | |
586 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 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
|
589 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 } |
5164 | 591 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
592 save_type_hid = H5T_NATIVE_FLOAT; |
5164 | 593 } |
594 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
595 // hdf5 currently doesn't support float/integer conversions | |
596 else | |
597 { | |
598 double max_val, min_val; | |
599 | |
600 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
|
601 save_type_hid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
602 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
5164 | 603 } |
604 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ | |
605 | |
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
|
606 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
607 data_hid = H5Dcreate (group_hid, "data", save_type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
608 H5P_DEFAULT, H5P_DEFAULT, 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
|
609 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
610 data_hid = H5Dcreate (group_hid, "data", save_type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
611 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
|
612 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
613 if (data_hid < 0) |
5164 | 614 { |
615 H5Sclose (space_hid); | |
616 H5Gclose (group_hid); | |
617 return false; | |
618 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
619 |
5164 | 620 double * dtmp = m.xdata (); |
621 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
622 H5P_DEFAULT, dtmp) >= 0; |
5164 | 623 H5Dclose (data_hid); |
624 H5Sclose (space_hid); | |
625 H5Gclose (group_hid); | |
626 | |
627 return retval; | |
628 } | |
629 | |
630 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9852
diff
changeset
|
631 octave_sparse_matrix::load_hdf5 (hid_t loc_id, const char *name) |
5164 | 632 { |
5351 | 633 octave_idx_type nr, nc, nz; |
5164 | 634 hid_t group_hid, data_hid, space_hid; |
635 hsize_t rank; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
636 |
5164 | 637 dim_vector dv; |
638 int empty = load_hdf5_empty (loc_id, name, dv); | |
639 if (empty > 0) | |
640 matrix.resize(dv); | |
641 if (empty) | |
642 return (empty > 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
643 |
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 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
645 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
646 #else |
5164 | 647 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
|
648 #endif |
5760 | 649 if (group_hid < 0) return false; |
5164 | 650 |
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
|
651 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
652 data_hid = H5Dopen (group_hid, "nr", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
653 #else |
5164 | 654 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
|
655 #endif |
5164 | 656 space_hid = H5Dget_space (data_hid); |
657 rank = H5Sget_simple_extent_ndims (space_hid); | |
658 | |
659 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
660 { |
5164 | 661 H5Dclose (data_hid); |
662 H5Gclose (group_hid); | |
663 return false; | |
664 } | |
665 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
666 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
667 H5P_DEFAULT, &nr) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
668 { |
5164 | 669 H5Dclose (data_hid); |
670 H5Gclose (group_hid); | |
671 return false; | |
672 } | |
673 | |
674 H5Dclose (data_hid); | |
675 | |
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
|
676 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
677 data_hid = H5Dopen (group_hid, "nc", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
678 #else |
5164 | 679 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
|
680 #endif |
5164 | 681 space_hid = H5Dget_space (data_hid); |
682 rank = H5Sget_simple_extent_ndims (space_hid); | |
683 | |
684 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
685 { |
5164 | 686 H5Dclose (data_hid); |
687 H5Gclose (group_hid); | |
688 return false; | |
689 } | |
690 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
691 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 H5P_DEFAULT, &nc) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
693 { |
5164 | 694 H5Dclose (data_hid); |
695 H5Gclose (group_hid); | |
696 return false; | |
697 } | |
698 | |
699 H5Dclose (data_hid); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
700 |
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
|
701 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
702 data_hid = H5Dopen (group_hid, "nz", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
703 #else |
5164 | 704 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
|
705 #endif |
5164 | 706 space_hid = H5Dget_space (data_hid); |
707 rank = H5Sget_simple_extent_ndims (space_hid); | |
708 | |
709 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
710 { |
5164 | 711 H5Dclose (data_hid); |
712 H5Gclose (group_hid); | |
713 return false; | |
714 } | |
715 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
716 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
717 H5P_DEFAULT, &nz) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
718 { |
5164 | 719 H5Dclose (data_hid); |
720 H5Gclose (group_hid); | |
721 return false; | |
722 } | |
723 | |
724 H5Dclose (data_hid); | |
725 | |
5275 | 726 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
|
727 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 static_cast<octave_idx_type> (nz)); |
5164 | 729 |
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
|
730 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
731 data_hid = H5Dopen (group_hid, "cidx", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
732 #else |
5164 | 733 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
|
734 #endif |
5164 | 735 space_hid = H5Dget_space (data_hid); |
736 rank = H5Sget_simple_extent_ndims (space_hid); | |
737 | |
738 if (rank != 2) | |
739 { | |
740 H5Sclose (space_hid); | |
741 H5Dclose (data_hid); | |
742 H5Gclose (group_hid); | |
743 return false; | |
744 } | |
745 | |
746 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
747 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
748 | |
749 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
750 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
751 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
|
752 || static_cast<int> (hdims[1]) != 1) |
5164 | 753 { |
754 H5Sclose (space_hid); | |
755 H5Dclose (data_hid); | |
756 H5Gclose (group_hid); | |
757 return false; | |
758 } | |
759 | |
5351 | 760 octave_idx_type *itmp = m.xcidx (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
761 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
762 H5P_DEFAULT, itmp) < 0) |
5164 | 763 { |
764 H5Sclose (space_hid); | |
765 H5Dclose (data_hid); | |
766 H5Gclose (group_hid); | |
767 return false; | |
768 } | |
769 | |
770 H5Sclose (space_hid); | |
771 H5Dclose (data_hid); | |
772 | |
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
|
773 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
774 data_hid = H5Dopen (group_hid, "ridx", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
775 #else |
5164 | 776 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
|
777 #endif |
5164 | 778 space_hid = H5Dget_space (data_hid); |
779 rank = H5Sget_simple_extent_ndims (space_hid); | |
780 | |
781 if (rank != 2) | |
782 { | |
783 H5Sclose (space_hid); | |
784 H5Dclose (data_hid); | |
785 H5Gclose (group_hid); | |
786 return false; | |
787 } | |
788 | |
789 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
790 | |
5322 | 791 if (static_cast<int> (hdims[0]) != nz || static_cast<int> (hdims[1]) != 1) |
5164 | 792 { |
793 H5Sclose (space_hid); | |
794 H5Dclose (data_hid); | |
795 H5Gclose (group_hid); | |
796 return false; | |
797 } | |
798 | |
799 itmp = m.xridx (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
800 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
801 H5P_DEFAULT, itmp) < 0) |
5164 | 802 { |
803 H5Sclose (space_hid); | |
804 H5Dclose (data_hid); | |
805 H5Gclose (group_hid); | |
806 return false; | |
807 } | |
808 | |
809 H5Sclose (space_hid); | |
810 H5Dclose (data_hid); | |
811 | |
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
|
812 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
813 data_hid = H5Dopen (group_hid, "data", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
814 #else |
5164 | 815 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
|
816 #endif |
5164 | 817 space_hid = H5Dget_space (data_hid); |
818 rank = H5Sget_simple_extent_ndims (space_hid); | |
819 | |
820 if (rank != 2) | |
821 { | |
822 H5Sclose (space_hid); | |
823 H5Dclose (data_hid); | |
824 H5Gclose (group_hid); | |
825 return false; | |
826 } | |
827 | |
828 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
829 | |
5322 | 830 if (static_cast<int> (hdims[0]) != nz || static_cast<int> (hdims[1]) != 1) |
5164 | 831 { |
832 H5Sclose (space_hid); | |
833 H5Dclose (data_hid); | |
834 H5Gclose (group_hid); | |
835 return false; | |
836 } | |
837 | |
838 double *dtmp = m.xdata (); | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
839 bool retval = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
840 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
841 H5P_DEFAULT, dtmp) >= 0 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
842 && m.indices_ok ()) |
5164 | 843 { |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
844 retval = true; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
845 matrix = m; |
5164 | 846 } |
847 | |
848 H5Sclose (space_hid); | |
849 H5Dclose (data_hid); | |
850 H5Gclose (group_hid); | |
851 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
852 return retval; |
5164 | 853 } |
5900 | 854 |
5164 | 855 #endif |
856 | |
5900 | 857 mxArray * |
858 octave_sparse_matrix::as_mxArray (void) const | |
859 { | |
6686 | 860 mwSize nz = nzmax(); |
861 mwSize nr = rows(); | |
862 mwSize nc = columns(); | |
5903 | 863 mxArray *retval = new mxArray (mxDOUBLE_CLASS, nr, nc, nz, mxREAL); |
864 double *pr = static_cast<double *> (retval->get_data ()); | |
6686 | 865 mwIndex *ir = retval->get_ir(); |
866 mwIndex *jc = retval->get_jc(); | |
5903 | 867 |
6686 | 868 for (mwIndex i = 0; i < nz; i++) |
5903 | 869 { |
870 pr[i] = matrix.data(i); | |
871 ir[i] = matrix.ridx(i); | |
872 } | |
873 | |
6686 | 874 for (mwIndex i = 0; i < nc + 1; i++) |
5903 | 875 jc[i] = matrix.cidx(i); |
876 | |
877 return retval; | |
5900 | 878 } |
879 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
880 octave_value |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
881 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
|
882 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
883 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
884 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
885 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
886 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
|
887 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
888 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
889 case umap_conj: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
890 return matrix; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
891 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
892 // Mappers handled specially. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
893 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
894 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
895 return octave_value (matrix.FCN ()) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
896 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
897 ARRAY_METHOD_MAPPER (abs, abs); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
898 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
899 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
900 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
901 return octave_value (matrix.map<TYPE> (FCN)) |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
902 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
903 ARRAY_MAPPER (acos, Complex, rc_acos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
904 ARRAY_MAPPER (acosh, Complex, rc_acosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
905 ARRAY_MAPPER (angle, double, ::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
906 ARRAY_MAPPER (arg, double, ::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
907 ARRAY_MAPPER (asin, Complex, rc_asin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
908 ARRAY_MAPPER (asinh, double, ::asinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
909 ARRAY_MAPPER (atan, double, ::atan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
910 ARRAY_MAPPER (atanh, Complex, rc_atanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
911 ARRAY_MAPPER (erf, double, ::erf); |
9835
1bb1ed717d2f
implement built-in erfinv
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
912 ARRAY_MAPPER (erfinv, double, ::erfinv); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
913 ARRAY_MAPPER (erfc, double, ::erfc); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
914 ARRAY_MAPPER (gamma, double, xgamma); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
915 ARRAY_MAPPER (lgamma, Complex, rc_lgamma); |
10414
2a8b1db1e2ca
implement built-in cbrt
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
916 ARRAY_MAPPER (cbrt, double, ::cbrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
917 ARRAY_MAPPER (ceil, double, ::ceil); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
918 ARRAY_MAPPER (cos, double, ::cos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
919 ARRAY_MAPPER (cosh, double, ::cosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
920 ARRAY_MAPPER (exp, double, ::exp); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
921 ARRAY_MAPPER (expm1, double, ::expm1); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
922 ARRAY_MAPPER (fix, double, ::fix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
923 ARRAY_MAPPER (floor, double, ::floor); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
924 ARRAY_MAPPER (log, Complex, rc_log); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
925 ARRAY_MAPPER (log2, Complex, rc_log2); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
926 ARRAY_MAPPER (log10, Complex, rc_log10); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
927 ARRAY_MAPPER (log1p, Complex, rc_log1p); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
928 ARRAY_MAPPER (round, double, xround); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
929 ARRAY_MAPPER (roundb, double, xroundb); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
930 ARRAY_MAPPER (signum, double, ::signum); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
931 ARRAY_MAPPER (sin, double, ::sin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
932 ARRAY_MAPPER (sinh, double, ::sinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
933 ARRAY_MAPPER (sqrt, Complex, rc_sqrt); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
934 ARRAY_MAPPER (tan, double, ::tan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
935 ARRAY_MAPPER (tanh, double, ::tanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
936 ARRAY_MAPPER (isnan, bool, xisnan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
937 ARRAY_MAPPER (isna, bool, octave_is_NA); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
938 ARRAY_MAPPER (isinf, bool, xisinf); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
939 ARRAY_MAPPER (finite, bool, xfinite); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
940 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
941 default: // Attempt to go via dense matrix. |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
942 return octave_base_sparse<SparseMatrix>::map (umap); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
943 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
944 } |