Mercurial > jwe > octave
annotate libinterp/octave-value/ov-base-sparse.cc @ 21139:538b57866b90
consistently use "typename" intead of "class" in template declarations
* Object.h, QtHandlesUtils.cc, QtHandlesUtils.h, ToolBarButton.cc,
ToolBarButton.h, Cell.h, __lin_interpn__.cc, bitfcns.cc, bsxfun.cc,
cellfun.cc, data.cc, filter.cc, gcd.cc, graphics.cc, help.cc, kron.cc,
lookup.cc, ls-mat5.cc, ls-oct-text.h, lu.cc, max.cc, mgorth.cc,
oct-map.cc, oct-map.h, oct-stream.cc, oct-stream.h, octave-link.h,
pr-output.cc, profiler.h, schur.cc, sparse-xdiv.cc, sparse-xpow.cc,
sqrtm.cc, symtab.h, tril.cc, typecast.cc, variables.cc, xdiv.cc,
zfstream.h, __init_fltk__.cc, __magick_read__.cc, chol.cc, qr.cc,
ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h,
ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h,
ov-base-sparse.cc, ov-base-sparse.h, ov-base.h, ov-classdef.cc,
ov-int-traits.h, ov-java.h, ov-usr-fcn.h, ov.cc, ov.h,
op-dms-template.cc, oct-parse.in.yy, parse.h, pt-mat.cc, Array-b.cc,
Array.cc, Array.h, CDiagMatrix.h, CMatrix.h, CNDArray.h,
DiagArray2.cc, DiagArray2.h, MArray.cc, MArray.h, MDiagArray2.cc,
MDiagArray2.h, MSparse.cc, MSparse.h, MatrixType.cc, Sparse.cc,
Sparse.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, fCDiagMatrix.h,
fCMatrix.h, fCNDArray.h, fDiagMatrix.h, fMatrix.h, fNDArray.h,
idx-vector.cc, idx-vector.h, intNDArray.cc, intNDArray.h, DET.h,
base-aepbal.h, base-lu.cc, base-lu.h, base-qr.cc, base-qr.h,
bsxfun-defs.cc, eigs-base.cc, lo-mappers.h, lo-specfun.cc,
lo-specfun.h, oct-convn.cc, oct-fftw.cc, oct-norm.cc,
sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc,
sparse-base-lu.h, sparse-dmsolve.cc, mx-inlines.cc,
action-container.h, base-list.h, lo-traits.h, lo-utils.h,
oct-base64.h, oct-binmap.h, oct-cmplx.h, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.h, oct-refcount.h, oct-sort.cc, oct-sort.h:
Use "typename" instead of "class" in template declarations.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 24 Jan 2016 13:50:04 -0500 |
parents | 95f8c8cdbffe |
children | fcac5dbbf9ed |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18650
diff
changeset
|
3 Copyright (C) 2004-2015 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10513
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
7016 | 6 |
7 This file is part of Octave. | |
5164 | 8 |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
5164 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
5164 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
7644
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
29 #include <iomanip> |
5164 | 30 #include <iostream> |
31 | |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
32 #include "ovl.h" |
5164 | 33 #include "ov-base.h" |
34 #include "quit.h" | |
35 #include "pr-output.h" | |
36 | |
37 #include "byte-swap.h" | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20218
diff
changeset
|
38 #include "ls-oct-text.h" |
5164 | 39 #include "ls-utils.h" |
40 #include "ls-hdf5.h" | |
41 | |
42 #include "boolSparse.h" | |
43 #include "ov-base-sparse.h" | |
20925
667861ffffab
Extracted header class octave-preserve-stream-state from utils.{cc/h}.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20555
diff
changeset
|
44 #include "octave-preserve-stream-state.h" |
5731 | 45 #include "pager.h" |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
46 #include "utils.h" |
5164 | 47 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20978
diff
changeset
|
48 #include "lo-array-errwarn.h" |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
49 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
50 template <typename T> |
5164 | 51 octave_value |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
52 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
|
53 bool resize_ok) |
5164 | 54 { |
55 octave_value retval; | |
56 | |
5275 | 57 octave_idx_type n_idx = idx.length (); |
5164 | 58 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
59 // If we catch an indexing error in index_vector, we flag an error in |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
60 // index k. Ensure it is the right value befor each idx_vector call. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
61 // Same variable as used in the for loop in the default case. |
5164 | 62 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
63 octave_idx_type k = 0; |
5164 | 64 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
65 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
66 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
67 switch (n_idx) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
68 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
69 case 0: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
70 retval = matrix; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
71 break; |
5164 | 72 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
73 case 1: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
74 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
75 idx_vector i = idx (0).index_vector (); |
5164 | 76 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
77 retval = octave_value (matrix.index (i, resize_ok)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
79 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
80 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
81 case 2: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
82 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
83 idx_vector i = idx (0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
84 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
85 k = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
86 idx_vector j = idx (1).index_vector (); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
87 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
88 retval = octave_value (matrix.index (i, j, resize_ok)); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
89 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
90 break; |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
91 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
92 default: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
93 error ("sparse indexing needs 1 or 2 indices"); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
94 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
95 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
96 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
97 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
98 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
99 e.set_pos_if_unset (n_idx, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
100 throw; |
5164 | 101 } |
102 | |
103 return retval; | |
104 } | |
105 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
106 template <typename T> |
5164 | 107 octave_value |
108 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
|
109 const std::list<octave_value_list>& idx) |
5164 | 110 { |
111 octave_value retval; | |
112 | |
113 switch (type[0]) | |
114 { | |
115 case '(': | |
116 retval = do_index_op (idx.front ()); | |
117 break; | |
118 | |
119 case '{': | |
120 case '.': | |
121 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
123 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
5164 | 124 } |
125 break; | |
126 | |
127 default: | |
128 panic_impossible (); | |
129 } | |
130 | |
131 return retval.next_subsref (type, idx); | |
132 } | |
133 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
134 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
135 octave_value |
5164 | 136 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
|
137 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 const octave_value& rhs) |
5164 | 139 { |
140 octave_value retval; | |
141 | |
142 switch (type[0]) | |
143 { | |
144 case '(': | |
145 { | |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
146 if (type.length () != 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
147 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 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
|
150 nm.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 } |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
152 |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
153 retval = numeric_assign (type, idx, rhs); |
5164 | 154 } |
155 break; | |
156 | |
157 case '{': | |
158 case '.': | |
159 { | |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
160 if (! is_empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 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
|
164 } |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
165 |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
166 octave_value tmp = octave_value::empty_conv (type, rhs); |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
167 |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
168 retval = tmp.subsasgn (type, idx, rhs); |
5164 | 169 } |
170 break; | |
171 | |
172 default: | |
173 panic_impossible (); | |
174 } | |
175 | |
176 return retval; | |
177 } | |
178 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
179 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
180 void |
5164 | 181 octave_base_sparse<T>::assign (const octave_value_list& idx, const T& rhs) |
182 { | |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
183 |
5275 | 184 octave_idx_type len = idx.length (); |
5164 | 185 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
186 // If we catch an indexing error in index_vector, we flag an error in |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
187 // index k. Ensure it is the right value befor each idx_vector call. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
188 // Same variable as used in the for loop in the default case. |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
189 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
190 octave_idx_type k = 0; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
191 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
192 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
193 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
194 switch (len) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
195 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
196 case 1: |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
197 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
198 idx_vector i = idx (0).index_vector (); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
199 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
200 matrix.assign (i, rhs); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
201 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
202 break; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
203 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
204 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
205 case 2: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
206 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
207 idx_vector i = idx (0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
208 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
209 k = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
210 idx_vector j = idx (1).index_vector (); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
211 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
212 matrix.assign (i, j, rhs); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
213 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
214 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
215 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
216 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
217 default: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
218 error ("sparse indexing needs 1 or 2 indices"); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
219 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
220 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
221 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
222 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
223 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
224 e.set_pos_if_unset (len, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
225 throw; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
226 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
227 |
5322 | 228 |
229 // Invalidate matrix type. | |
230 typ.invalidate_type (); | |
5164 | 231 } |
232 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
233 template <typename MT> |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
234 void |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
235 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
|
236 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
237 octave_idx_type len = idx.length (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
238 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
239 // If we catch an indexing error in index_vector, we flag an error in |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
240 // index k. Ensure it is the right value befor each idx_vector call. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
241 // Same variable as used in the for loop in the default case. |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
242 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
243 octave_idx_type k = 0; |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
244 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
245 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
246 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
247 switch (len) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
248 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
249 case 1: |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
250 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
251 idx_vector i = idx (0).index_vector (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
252 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
253 matrix.delete_elements (i); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
254 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
255 break; |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
256 } |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
257 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
258 case 2: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
259 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
260 idx_vector i = idx (0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
261 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
262 k = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
263 idx_vector j = idx (1).index_vector (); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
264 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
265 matrix.delete_elements (i, j); |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
266 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
267 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
268 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
269 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
270 default: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
271 error ("sparse indexing needs 1 or 2 indices"); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
272 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
273 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
274 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
275 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
276 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
277 e.set_pos_if_unset (len, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20447
diff
changeset
|
278 throw; |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
279 } |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
280 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
281 // Invalidate the matrix type |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
282 typ.invalidate_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
283 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7644
diff
changeset
|
284 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
285 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
286 octave_value |
5731 | 287 octave_base_sparse<T>::resize (const dim_vector& dv, bool) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
288 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
289 T retval (matrix); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
290 retval.resize (dv); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
291 return retval; |
5731 | 292 } |
5164 | 293 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
294 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
295 bool |
5164 | 296 octave_base_sparse<T>::is_true (void) const |
297 { | |
298 bool retval = false; | |
299 dim_vector dv = matrix.dims (); | |
5275 | 300 octave_idx_type nel = dv.numel (); |
10513
c5005bc2b7a9
implement working spalloc
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
301 octave_idx_type nz = nnz (); |
5164 | 302 |
303 if (nz == nel && nel > 0) | |
304 { | |
305 T t1 (matrix.reshape (dim_vector (nel, 1))); | |
306 | |
307 SparseBoolMatrix t2 = t1.all (); | |
308 | |
309 retval = t2(0); | |
310 } | |
311 | |
312 return retval; | |
313 } | |
314 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
315 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
316 bool |
5164 | 317 octave_base_sparse<T>::print_as_scalar (void) const |
318 { | |
319 dim_vector dv = dims (); | |
320 | |
321 return (dv.all_ones () || dv.any_zero ()); | |
322 } | |
323 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
324 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
325 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18200
diff
changeset
|
326 octave_base_sparse<T>::print (std::ostream& os, bool pr_as_read_syntax) |
5164 | 327 { |
328 print_raw (os, pr_as_read_syntax); | |
329 newline (os); | |
330 } | |
331 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
332 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
333 void |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
334 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
|
335 const std::string& prefix) const |
5164 | 336 { |
337 matrix.print_info (os, prefix); | |
338 } | |
339 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
340 template <typename T> |
5164 | 341 void |
342 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
|
343 bool pr_as_read_syntax) const |
5164 | 344 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
345 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
346 |
5275 | 347 octave_idx_type nr = matrix.rows (); |
348 octave_idx_type nc = matrix.cols (); | |
5604 | 349 octave_idx_type nz = nnz (); |
5164 | 350 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
351 // FIXME: this should probably all be handled by a |
5355 | 352 // separate octave_print_internal function that can handle format |
353 // compact, loose, etc. | |
354 | |
355 os << "Compressed Column Sparse (rows = " << nr | |
356 << ", 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
|
357 << ", nnz = " << nz; |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
358 |
14566
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
359 // Avoid calling numel here since it can easily overflow |
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
360 // octave_idx_type even when there is no real problem storing the |
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
361 // sparse array. |
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
362 |
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
363 double dnr = nr; |
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
364 double dnc = nc; |
aa491bd9e19b
avoid unnecessary index overflow error when printing sparse array (bug #35148)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
365 double dnel = dnr * dnc; |
7644
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
366 |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
367 if (dnel > 0) |
11439
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
368 { |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
369 double pct = (nz / dnel * 100); |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
370 |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
371 int prec = 2; |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
372 |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
373 // Display at least 2 significant figures and up to 4 as we |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
374 // approach 100%. Avoid having limited precision of the display |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
375 // result in reporting 100% for matrices that are not actually |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
376 // 100% full. |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
377 |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
378 if (pct == 100) |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
379 prec = 3; |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
380 else |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
381 { |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
382 if (pct > 99.9) |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
383 prec = 4; |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
384 else if (pct > 99) |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
385 prec = 3; |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
386 |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
387 if (pct > 99.99) |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
388 pct = 99.99; |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
389 } |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
390 |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
391 os << " [" << std::setprecision (prec) << pct << "%]"; |
c2f44cba24c9
improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
10527
diff
changeset
|
392 } |
7644
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
393 |
91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
394 os << ")\n"; |
5164 | 395 |
396 // add one to the printed indices to go from | |
397 // zero-based to one-based arrays | |
398 | |
399 if (nz != 0) | |
400 { | |
5275 | 401 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
|
402 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
403 octave_quit (); |
5355 | 404 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
405 // FIXME: is there an easy way to get the max row |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 // 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
|
407 // 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
|
408 // 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
|
409 // formatting rules that apply to columns of a matrix. |
5355 | 410 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14566
diff
changeset
|
411 for (octave_idx_type i = matrix.cidx (j); i < matrix.cidx (j+1); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 os << "\n"; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
414 os << " (" << matrix.ridx (i)+1 << ", " << j+1 << ") -> "; |
5355 | 415 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14566
diff
changeset
|
416 octave_print_internal (os, matrix.data (i), pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
417 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
418 } |
5164 | 419 } |
420 } | |
421 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
422 template <typename T> |
5164 | 423 bool |
6974 | 424 octave_base_sparse<T>::save_ascii (std::ostream& os) |
5164 | 425 { |
426 dim_vector dv = this->dims (); | |
427 | |
428 // Ensure that additional memory is deallocated | |
429 matrix.maybe_compress (); | |
430 | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
431 os << "# nnz: " << nnz () << "\n"; |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
432 os << "# rows: " << dv(0) << "\n"; |
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
433 os << "# columns: " << dv(1) << "\n"; |
5164 | 434 |
435 os << this->matrix; | |
436 | |
437 return true; | |
438 } | |
439 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
440 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
441 bool |
5164 | 442 octave_base_sparse<T>::load_ascii (std::istream& is) |
443 { | |
5275 | 444 octave_idx_type nz = 0; |
445 octave_idx_type nr = 0; | |
446 octave_idx_type nc = 0; | |
5164 | 447 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
448 if (! extract_keyword (is, "nnz", nz, true) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
449 || ! extract_keyword (is, "rows", nr, true) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
450 || ! extract_keyword (is, "columns", nc, true)) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
451 error ("load: failed to extract number of rows and columns"); |
5164 | 452 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
453 T tmp (nr, nc, nz); |
5164 | 454 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
455 is >> tmp; |
5164 | 456 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
457 if (! is) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
458 error ("load: failed to load matrix constant"); |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
459 |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
460 matrix = tmp; |
5164 | 461 |
21124
95f8c8cdbffe
maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
462 return true; |
5164 | 463 } |
464 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
465 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
466 template <typename T> |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
467 octave_value |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
468 octave_base_sparse<T>::fast_elem_extract (octave_idx_type n) const |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
469 { |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
470 octave_idx_type nr = matrix.rows (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
471 octave_idx_type nc = matrix.cols (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
472 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
473 octave_idx_type i = n % nr; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
474 octave_idx_type j = n / nr; |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
475 |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
476 return (i < nr && j < nc) ? octave_value (matrix(i,j)) : octave_value (); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
477 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
478 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21124
diff
changeset
|
479 template <typename T> |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
480 octave_value |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
481 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
|
482 { |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
483 if (umap == umap_xtolower || umap == umap_xtoupper) |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
484 return matrix; |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
485 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
486 // Try the map on the dense value. |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
487 // FIXME: We should probably be smarter about this, especially for the |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
488 // cases that are expected to return sparse matrices. |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
489 octave_value retval = this->full_value ().map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
490 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
491 // Sparsify the result if possible. |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
492 |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
493 switch (umap) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
494 { |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
495 case umap_xisalnum: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
496 case umap_xisalpha: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
497 case umap_xisascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
498 case umap_xiscntrl: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
499 case umap_xisdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
500 case umap_xisgraph: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
501 case umap_xislower: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
502 case umap_xisprint: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
503 case umap_xispunct: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
504 case umap_xisspace: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
505 case umap_xisupper: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
506 case umap_xisxdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
507 case umap_xtoascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
508 // FIXME: intentionally skip this step for string mappers. |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
509 // Is this wanted? |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
510 break; |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
511 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
512 default: |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
513 { |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
514 switch (retval.builtin_type ()) |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
515 { |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
516 case btyp_double: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
517 retval = retval.sparse_matrix_value (); |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
518 break; |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
519 |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
520 case btyp_complex: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
521 retval = retval.sparse_complex_matrix_value (); |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
522 break; |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
523 |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
524 case btyp_bool: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
525 retval = retval.sparse_bool_matrix_value (); |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
526 break; |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
527 |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
528 default: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
529 break; |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
530 } |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
531 } |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
532 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
533 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
534 return retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
535 } |