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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1 /*
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11439
diff changeset
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
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
6
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
7 This file is part of Octave.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
8
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
12 option) any later version.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
13
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
17 for more details.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
18
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
21 <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
22
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
23 */
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
24
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25 #ifdef HAVE_CONFIG_H
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
26 #include <config.h>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27 #endif
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
30 #include <iostream>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
33 #include "ov-base.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
34 #include "quit.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
35 #include "pr-output.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
39 #include "ls-utils.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40 #include "ls-hdf5.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
42 #include "boolSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
54 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
55 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
57 octave_idx_type n_idx = idx.length ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
101 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
102
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
103 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
104 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
107 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
110 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
111 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
112
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
113 switch (type[0])
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
114 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
115 case '(':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
116 retval = do_index_op (idx.front ());
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
117 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
118
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
119 case '{':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
120 case '.':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
124 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
126
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
127 default:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
128 panic_impossible ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
129 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131 return retval.next_subsref (type, idx);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
139 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
140 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
141
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
142 switch (type[0])
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
143 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
144 case '(':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
154 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
155 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
156
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
157 case '{':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
158 case '.':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
169 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
170 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
171
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
172 default:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
173 panic_impossible ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
174 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
175
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
176 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
177 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
181 octave_base_sparse<T>::assign (const octave_value_list& idx, const T& rhs)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
182 {
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
183
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
184 octave_idx_type len = idx.length ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
228
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
229 // Invalidate matrix type.
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
230 typ.invalidate_type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
231 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
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
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
292 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
296 octave_base_sparse<T>::is_true (void) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
297 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
298 bool retval = false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
299 dim_vector dv = matrix.dims ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
302
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
303 if (nz == nel && nel > 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
304 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
305 T t1 (matrix.reshape (dim_vector (nel, 1)));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
306
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
307 SparseBoolMatrix t2 = t1.all ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
308
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
309 retval = t2(0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
310 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
311
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
313 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
317 octave_base_sparse<T>::print_as_scalar (void) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
318 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
319 dim_vector dv = dims ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
320
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
321 return (dv.all_ones () || dv.any_zero ());
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
322 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
327 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
328 print_raw (os, pr_as_read_syntax);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
329 newline (os);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
330 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
336 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
337 matrix.print_info (os, prefix);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
338 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
341 void
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
347 octave_idx_type nr = matrix.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
348 octave_idx_type nc = matrix.cols ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5539
diff changeset
349 octave_idx_type nz = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
352 // separate octave_print_internal function that can handle format
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
353 // compact, loose, etc.
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
354
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
355 os << "Compressed Column Sparse (rows = " << nr
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
395
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
396 // add one to the printed indices to go from
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
397 // zero-based to one-based arrays
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
398
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
399 if (nz != 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
400 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
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
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
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
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
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
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
419 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
420 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
423 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 5958
diff changeset
424 octave_base_sparse<T>::save_ascii (std::ostream& os)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
425 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
426 dim_vector dv = this->dims ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
427
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
428 // Ensure that additional memory is deallocated
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
429 matrix.maybe_compress ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
434
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
435 os << this->matrix;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
436
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
437 return true;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
438 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
442 octave_base_sparse<T>::load_ascii (std::istream& is)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
443 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
444 octave_idx_type nz = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
445 octave_idx_type nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
446 octave_idx_type nc = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
454
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
455 is >> tmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
461
21124
95f8c8cdbffe maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents: 21100
diff changeset
462 return true;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
463 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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 }