Mercurial > hg > octave-lyh
annotate src/ov-base-sparse.cc @ 10421:99e9bae2d81e
improve sparse indexing interface
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 18 Mar 2010 14:55:52 +0100 |
parents | 12884915a8e4 |
children | fdccd69d26bd |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman |
7016 | 4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler |
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 | |
7644
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
28 #include <iomanip> |
5164 | 29 #include <iostream> |
30 | |
31 #include "oct-obj.h" | |
32 #include "ov-base.h" | |
33 #include "quit.h" | |
34 #include "pr-output.h" | |
35 | |
36 #include "byte-swap.h" | |
37 #include "ls-oct-ascii.h" | |
38 #include "ls-utils.h" | |
39 #include "ls-hdf5.h" | |
40 | |
41 #include "boolSparse.h" | |
42 #include "ov-base-sparse.h" | |
5731 | 43 #include "pager.h" |
5164 | 44 |
45 template <class T> | |
46 octave_value | |
47 octave_base_sparse<T>::do_index_op (const octave_value_list& idx, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
48 bool resize_ok) |
5164 | 49 { |
50 octave_value retval; | |
51 | |
5275 | 52 octave_idx_type n_idx = idx.length (); |
5164 | 53 |
54 switch (n_idx) | |
55 { | |
56 case 0: | |
5539 | 57 retval = matrix; |
5164 | 58 break; |
59 | |
60 case 1: | |
61 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
62 idx_vector i = idx (0).index_vector (); |
5164 | 63 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
65 retval = octave_value (matrix.index (i, resize_ok)); |
5164 | 66 } |
67 break; | |
68 | |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
69 case 2: |
5164 | 70 { |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
71 idx_vector i = idx (0).index_vector (); |
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
72 |
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
73 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
74 { |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
75 idx_vector j = idx (1).index_vector (); |
5164 | 76 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
77 if (! error_state) |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
78 retval = octave_value (matrix.index (i, j, resize_ok)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
79 } |
5164 | 80 } |
81 break; | |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
82 default: |
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
83 error ("sparse indexing needs 1 or 2 indices"); |
5164 | 84 } |
85 | |
86 return retval; | |
87 } | |
88 | |
89 template <class T> | |
90 octave_value | |
91 octave_base_sparse<T>::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 const std::list<octave_value_list>& idx) |
5164 | 93 { |
94 octave_value retval; | |
95 | |
96 switch (type[0]) | |
97 { | |
98 case '(': | |
99 retval = do_index_op (idx.front ()); | |
100 break; | |
101 | |
102 case '{': | |
103 case '.': | |
104 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
5164 | 107 } |
108 break; | |
109 | |
110 default: | |
111 panic_impossible (); | |
112 } | |
113 | |
114 return retval.next_subsref (type, idx); | |
115 } | |
116 | |
117 template <class T> | |
118 octave_value | |
119 octave_base_sparse<T>::subsasgn (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 const octave_value& rhs) |
5164 | 122 { |
123 octave_value retval; | |
124 | |
125 switch (type[0]) | |
126 { | |
127 case '(': | |
128 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
129 if (type.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 retval = numeric_assign (type, idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
131 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
133 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 error ("in indexed assignment of %s, last lhs index must be ()", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 nm.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 } |
5164 | 137 } |
138 break; | |
139 | |
140 case '{': | |
141 case '.': | |
142 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 if (is_empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 octave_value tmp = octave_value::empty_conv (type, rhs); |
5164 | 146 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
147 retval = tmp.subsasgn (type, idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 } |
5164 | 154 } |
155 break; | |
156 | |
157 default: | |
158 panic_impossible (); | |
159 } | |
160 | |
161 return retval; | |
162 } | |
163 | |
164 template <class T> | |
165 void | |
166 octave_base_sparse<T>::assign (const octave_value_list& idx, const T& rhs) | |
167 { | |
5275 | 168 octave_idx_type len = idx.length (); |
5164 | 169 |
5275 | 170 for (octave_idx_type i = 0; i < len; i++) |
5164 | 171 matrix.set_index (idx(i).index_vector ()); |
172 | |
173 ::assign (matrix, rhs); | |
5322 | 174 |
175 // Invalidate matrix type. | |
176 typ.invalidate_type (); | |
5164 | 177 } |
178 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
179 template <class MT> |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
180 void |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
181 octave_base_sparse<MT>::delete_elements (const octave_value_list& idx) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
182 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
183 octave_idx_type len = idx.length (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
184 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
185 Array<idx_vector> ra_idx (len, 1); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
186 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
187 for (octave_idx_type i = 0; i < len; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
188 ra_idx(i) = idx(i).index_vector (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
189 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
190 matrix.maybe_delete_elements (ra_idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
191 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
192 // Invalidate the matrix type |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
193 typ.invalidate_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
194 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
195 |
5731 | 196 template <class T> |
197 octave_value | |
198 octave_base_sparse<T>::resize (const dim_vector& dv, bool) const | |
199 { | |
200 T retval (matrix); | |
201 retval.resize (dv); | |
202 return retval; | |
203 } | |
5164 | 204 |
205 template <class T> | |
206 bool | |
207 octave_base_sparse<T>::is_true (void) const | |
208 { | |
209 bool retval = false; | |
210 dim_vector dv = matrix.dims (); | |
5275 | 211 octave_idx_type nel = dv.numel (); |
5604 | 212 octave_idx_type nz = nzmax (); |
5164 | 213 |
214 if (nz == nel && nel > 0) | |
215 { | |
216 T t1 (matrix.reshape (dim_vector (nel, 1))); | |
217 | |
218 SparseBoolMatrix t2 = t1.all (); | |
219 | |
220 retval = t2(0); | |
221 } | |
222 | |
223 return retval; | |
224 } | |
225 | |
226 template <class T> | |
227 bool | |
228 octave_base_sparse<T>::print_as_scalar (void) const | |
229 { | |
230 dim_vector dv = dims (); | |
231 | |
232 return (dv.all_ones () || dv.any_zero ()); | |
233 } | |
234 | |
235 template <class T> | |
236 void | |
237 octave_base_sparse<T>::print (std::ostream& os, bool pr_as_read_syntax) const | |
238 { | |
239 print_raw (os, pr_as_read_syntax); | |
240 newline (os); | |
241 } | |
242 | |
243 template <class T> | |
244 void | |
245 octave_base_sparse<T>::print_info (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 const std::string& prefix) const |
5164 | 247 { |
248 matrix.print_info (os, prefix); | |
249 } | |
250 | |
251 template <class T> | |
252 void | |
253 octave_base_sparse<T>::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 bool pr_as_read_syntax) const |
5164 | 255 { |
5275 | 256 octave_idx_type nr = matrix.rows (); |
257 octave_idx_type nc = matrix.cols (); | |
5604 | 258 octave_idx_type nz = nnz (); |
5164 | 259 |
5775 | 260 // FIXME -- this should probably all be handled by a |
5355 | 261 // separate octave_print_internal function that can handle format |
262 // compact, loose, etc. | |
263 | |
264 os << "Compressed Column Sparse (rows = " << nr | |
265 << ", cols = " << nc | |
7644
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
266 << ", nnz = " << nz; |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
267 |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
268 double dnel = matrix.numel (); |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
269 |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
270 if (dnel > 0) |
8848
7557cf34ffcd
ov-base-sparse.cc (octave_base_sparse<T>::print_raw): remove extra ")\n" from output
John W. Eaton <jwe@octave.org>
parents:
8676
diff
changeset
|
271 os << " [" << std::setprecision (2) << (nz / dnel * 100) << "%]"; |
7644
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
272 |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
273 os << ")\n"; |
5164 | 274 |
275 // add one to the printed indices to go from | |
276 // zero-based to one-based arrays | |
277 | |
278 if (nz != 0) | |
279 { | |
5275 | 280 for (octave_idx_type j = 0; j < nc; j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
281 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 octave_quit (); |
5355 | 283 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 // FIXME -- is there an easy way to get the max row |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 // and column indices so we can set the width appropriately |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 // and line up the columns here? Similarly, we should look |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 // at all the nonzero values and display them with the same |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 // formatting rules that apply to columns of a matrix. |
5355 | 289 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
290 for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 os << " (" << matrix.ridx(i)+1 << |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 ", " << j+1 << ") -> "; |
5355 | 295 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 octave_print_internal (os, matrix.data(i), pr_as_read_syntax); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 } |
5164 | 299 } |
300 } | |
301 | |
302 template <class T> | |
303 bool | |
6974 | 304 octave_base_sparse<T>::save_ascii (std::ostream& os) |
5164 | 305 { |
306 dim_vector dv = this->dims (); | |
307 | |
308 // Ensure that additional memory is deallocated | |
309 matrix.maybe_compress (); | |
310 | |
5604 | 311 os << "# nnz: " << nzmax () << "\n"; |
5164 | 312 os << "# rows: " << dv (0) << "\n"; |
313 os << "# columns: " << dv (1) << "\n"; | |
314 | |
315 os << this->matrix; | |
316 | |
317 return true; | |
318 } | |
319 | |
320 template <class T> | |
321 bool | |
322 octave_base_sparse<T>::load_ascii (std::istream& is) | |
323 { | |
5275 | 324 octave_idx_type nz = 0; |
325 octave_idx_type nr = 0; | |
326 octave_idx_type nc = 0; | |
5164 | 327 bool success = true; |
328 | |
329 if (extract_keyword (is, "nnz", nz, true) && | |
330 extract_keyword (is, "rows", nr, true) && | |
331 extract_keyword (is, "columns", nc, true)) | |
332 { | |
333 T tmp (nr, nc, nz); | |
334 | |
335 is >> tmp; | |
336 | |
337 if (!is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
338 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
340 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
341 } |
5164 | 342 |
343 matrix = tmp; | |
344 } | |
345 else | |
346 { | |
347 error ("load: failed to extract number of rows and columns"); | |
348 success = false; | |
349 } | |
350 | |
351 return success; | |
352 } | |
353 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
354 template <class T> |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
355 octave_value |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
356 octave_base_sparse<T>::map (octave_base_value::unary_mapper_t umap) const |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
357 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
358 // Try the map on the dense value. |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
359 octave_value retval = this->full_value ().map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
360 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
361 // Sparsify the result if possible. |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
362 // FIXME: intentionally skip this step for string mappers. Is this wanted? |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
363 if (umap >= umap_xisalnum && umap <= umap_xtoupper) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
364 return retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
365 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
366 switch (retval.builtin_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
367 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
368 case btyp_double: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
369 retval = retval.sparse_matrix_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
370 break; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
371 case btyp_complex: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
372 retval = retval.sparse_complex_matrix_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
373 break; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
374 case btyp_bool: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
375 retval = retval.sparse_bool_matrix_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
376 break; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
377 default: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
378 break; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
379 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
380 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
381 return retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
382 } |