annotate src/ov-base-sparse.cc @ 11586:12df7854fa7c

strip trailing whitespace from source files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:24:59 -0500
parents fd0a3ac60b0e
children 72c96de7a403
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
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11439
diff changeset
3 Copyright (C) 2004-2011 David Bateman
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
32 #include "oct-obj.h"
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"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 #include "ls-oct-ascii.h"
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"
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
44 #include "pager.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
45
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
47 octave_value
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
48 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
49 bool resize_ok)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
50 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
51 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
52
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
53 octave_idx_type n_idx = idx.length ();
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 switch (n_idx)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
57 case 0:
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5355
diff changeset
58 retval = matrix;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
59 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
60
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
61 case 1:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
62 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
63 idx_vector i = idx (0).index_vector ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
64
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
65 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
66 retval = octave_value (matrix.index (i, resize_ok));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
67 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
68 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
69
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
70 case 2:
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
71 {
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
72 idx_vector i = idx (0).index_vector ();
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
73
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
74 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
75 {
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
76 idx_vector j = idx (1).index_vector ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
77
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
78 if (! error_state)
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
79 retval = octave_value (matrix.index (i, j, resize_ok));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
80 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
81 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
82 break;
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
83 default:
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
84 error ("sparse indexing needs 1 or 2 indices");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
85 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
86
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
87 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
88 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
89
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
90 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
91 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
92 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
93 const std::list<octave_value_list>& idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
94 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
95 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
96
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
97 switch (type[0])
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
98 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
99 case '(':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
100 retval = do_index_op (idx.front ());
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
101 break;
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 case '{':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
104 case '.':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
105 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
106 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
107 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
108 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
109 break;
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 default:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
112 panic_impossible ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
113 }
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 return retval.next_subsref (type, idx);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
116 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
117
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
118 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
119 octave_value
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
120 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
121 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
122 const octave_value& rhs)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
123 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
124 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
126 switch (type[0])
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
127 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
128 case '(':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
129 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
130 if (type.length () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
131 retval = numeric_assign (type, idx, rhs);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
132 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
133 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
134 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
135 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
136 nm.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
137 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
138 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
139 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
140
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
141 case '{':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
142 case '.':
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
143 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
144 if (is_empty ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
145 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
146 octave_value tmp = octave_value::empty_conv (type, rhs);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
147
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
148 retval = tmp.subsasgn (type, idx, rhs);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
149 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
150 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
151 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
152 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
153 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
154 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
155 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
156 break;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
157
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
158 default:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
159 panic_impossible ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
160 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
161
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
162 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
163 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
165 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
166 void
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
167 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
168 {
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
169
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
170 octave_idx_type len = idx.length ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
171
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
172 switch (len)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
173 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
174 case 1:
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
175 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
176 idx_vector i = idx (0).index_vector ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
177
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
178 if (! error_state)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
179 matrix.assign (i, rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
180
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
181 break;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
182 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
183
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
184 case 2:
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
185 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
186 idx_vector i = idx (0).index_vector ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
187
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
188 if (! error_state)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
189 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
190 idx_vector j = idx (1).index_vector ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
191
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
192 if (! error_state)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
193 matrix.assign (i, j, rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
194 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
195
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
196 break;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
197 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
198
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
199 default:
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
200 error ("sparse indexing needs 1 or 2 indices");
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
201 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
202
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
203
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
204 // Invalidate matrix type.
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
205 typ.invalidate_type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
206 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
207
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
208 template <class MT>
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
209 void
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
210 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
211 {
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
212 octave_idx_type len = idx.length ();
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
213
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
214 switch (len)
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
215 {
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
216 case 1:
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
217 {
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
218 idx_vector i = idx (0).index_vector ();
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
219
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
220 if (! error_state)
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
221 matrix.delete_elements (i);
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
222
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
223 break;
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
224 }
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
225
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
226 case 2:
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
227 {
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
228 idx_vector i = idx (0).index_vector ();
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
229
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
230 if (! error_state)
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
231 {
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
232 idx_vector j = idx (1).index_vector ();
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
233
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
234 if (! error_state)
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
235 matrix.delete_elements (i, j);
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
236 }
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
237
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
238 break;
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
239 }
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
240
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
241 default:
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
242 error ("sparse indexing needs 1 or 2 indices");
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
243 }
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
244
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
245 // Invalidate the matrix type
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
246 typ.invalidate_type ();
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
247 }
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7644
diff changeset
248
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
249 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
250 octave_value
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
251 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
252 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
253 T retval (matrix);
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
254 retval.resize (dv);
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
255 return retval;
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5604
diff changeset
256 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
257
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
258 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
259 bool
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
260 octave_base_sparse<T>::is_true (void) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
261 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
262 bool retval = false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
263 dim_vector dv = matrix.dims ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
264 octave_idx_type nel = dv.numel ();
10513
c5005bc2b7a9 implement working spalloc
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
265 octave_idx_type nz = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
266
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
267 if (nz == nel && nel > 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
268 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
269 T t1 (matrix.reshape (dim_vector (nel, 1)));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
270
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
271 SparseBoolMatrix t2 = t1.all ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
272
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
273 retval = t2(0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
274 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
275
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
276 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
277 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
278
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
279 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
280 bool
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
281 octave_base_sparse<T>::print_as_scalar (void) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
282 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
283 dim_vector dv = dims ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
284
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
285 return (dv.all_ones () || dv.any_zero ());
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
286 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
287
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
288 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
289 void
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
290 octave_base_sparse<T>::print (std::ostream& os, bool pr_as_read_syntax) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
291 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
292 print_raw (os, pr_as_read_syntax);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
293 newline (os);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
294 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
295
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
296 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
297 void
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
298 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
299 const std::string& prefix) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
300 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
301 matrix.print_info (os, prefix);
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
304 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
305 void
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
306 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
307 bool pr_as_read_syntax) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
308 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
309 octave_idx_type nr = matrix.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
310 octave_idx_type nc = matrix.cols ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5539
diff changeset
311 octave_idx_type nz = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5731
diff changeset
313 // 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
314 // separate octave_print_internal function that can handle format
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
315 // compact, loose, etc.
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
316
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
317 os << "Compressed Column Sparse (rows = " << nr
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
318 << ", 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
319 << ", nnz = " << nz;
91d7440211e7 display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
320
91d7440211e7 display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
321 double dnel = matrix.numel ();
91d7440211e7 display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
322
91d7440211e7 display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
323 if (dnel > 0)
11439
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
324 {
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
325 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
326
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
327 int prec = 2;
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
328
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
329 // 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
330 // 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
331 // 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
332 // 100% full.
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
333
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
334 if (pct == 100)
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
335 prec = 3;
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
336 else
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
337 {
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
338 if (pct > 99.9)
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
339 prec = 4;
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
340 else if (pct > 99)
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
341 prec = 3;
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
342
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
343 if (pct > 99.99)
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
344 pct = 99.99;
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
345 }
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
346
c2f44cba24c9 improve display of percentage full when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 10527
diff changeset
347 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
348 }
7644
91d7440211e7 display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
349
91d7440211e7 display percentage of elements that are nonzero when printing sparse matrices
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
350 os << ")\n";
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
351
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
352 // add one to the printed indices to go from
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
353 // zero-based to one-based arrays
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
354
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
355 if (nz != 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
356 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
357 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
358 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
359 octave_quit ();
5355
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
360
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
361 // FIXME -- is there an easy way to get the max row
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
362 // 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
363 // 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
364 // 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
365 // 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
366
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
367 for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
368 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
369 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
370 os << " (" << matrix.ridx(i)+1 <<
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
371 ", " << j+1 << ") -> ";
5355
cf44c749ba52 [project @ 2005-05-18 11:43:37 by jwe]
jwe
parents: 5322
diff changeset
372
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
373 octave_print_internal (os, matrix.data(i), pr_as_read_syntax);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
374 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
375 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
376 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
377 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
378
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
379 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
380 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 5958
diff changeset
381 octave_base_sparse<T>::save_ascii (std::ostream& os)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
382 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
383 dim_vector dv = this->dims ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
384
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
385 // Ensure that additional memory is deallocated
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
386 matrix.maybe_compress ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
387
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
388 os << "# nnz: " << nnz () << "\n";
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
389 os << "# rows: " << dv (0) << "\n";
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
390 os << "# columns: " << dv (1) << "\n";
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
391
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
392 os << this->matrix;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
393
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
394 return true;
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
397 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
398 bool
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
399 octave_base_sparse<T>::load_ascii (std::istream& is)
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 octave_idx_type nz = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
402 octave_idx_type nr = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
403 octave_idx_type nc = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
404 bool success = true;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
405
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
406 if (extract_keyword (is, "nnz", nz, true) &&
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
407 extract_keyword (is, "rows", nr, true) &&
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
408 extract_keyword (is, "columns", nc, true))
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
409 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
410 T tmp (nr, nc, nz);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
411
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
412 is >> tmp;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
413
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
414 if (!is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
416 error ("load: failed to load matrix constant");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
417 success = false;
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 matrix = tmp;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
421 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
422 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
423 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
424 error ("load: failed to extract number of rows and columns");
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
425 success = false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
426 }
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 return success;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
429 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
430
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
431 template <class T>
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
432 octave_value
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
433 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
434 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
435 // Try the map on the dense value.
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
436 octave_value retval = this->full_value ().map (umap);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
437
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
438 // Sparsify the result if possible.
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
439 // FIXME: intentionally skip this step for string mappers. Is this wanted?
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
440 if (umap >= umap_xisalnum && umap <= umap_xtoupper)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
441 return retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
442
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
443 switch (retval.builtin_type ())
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
444 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
445 case btyp_double:
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
446 retval = retval.sparse_matrix_value ();
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
447 break;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
448 case btyp_complex:
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
449 retval = retval.sparse_complex_matrix_value ();
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
450 break;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
451 case btyp_bool:
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
452 retval = retval.sparse_bool_matrix_value ();
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
453 break;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
454 default:
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
455 break;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
456 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
457
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
458 return retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
459 }