Mercurial > hg > octave-lyh
annotate liboctave/boolSparse.cc @ 11287:d81b79c1bd5d
fixes for --enable-64
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 22 Nov 2010 03:27:41 -0500 |
parents | 4b51c0a20a98 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2004, 2005, 2006, 2007, 2008 David Bateman |
7016 | 4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
7016 | 6 |
7 This file is part of Octave. | |
5164 | 8 |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
5164 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
5164 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include <iostream> | |
30 #include <vector> | |
31 | |
32 #include "config.h" | |
33 #include "quit.h" | |
34 #include "lo-ieee.h" | |
35 #include "lo-mappers.h" | |
36 | |
37 #include "boolSparse.h" | |
10983
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
38 #include "dSparse.h" |
10976
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
39 #include "oct-mem.h" |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
40 #include "oct-locbuf.h" |
5164 | 41 |
42 // SparseBoolMatrix class. | |
43 | |
44 bool | |
45 SparseBoolMatrix::operator == (const SparseBoolMatrix& a) const | |
46 { | |
5275 | 47 octave_idx_type nr = rows (); |
48 octave_idx_type nc = cols (); | |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
49 octave_idx_type nz = nnz (); |
5275 | 50 octave_idx_type nr_a = a.rows (); |
51 octave_idx_type nc_a = a.cols (); | |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
52 octave_idx_type nz_a = a.nnz (); |
5164 | 53 |
54 if (nr != nr_a || nc != nc_a || nz != nz_a) | |
55 return false; | |
56 | |
5275 | 57 for (octave_idx_type i = 0; i < nc + 1; i++) |
5164 | 58 if (cidx(i) != a.cidx(i)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
59 return false; |
5164 | 60 |
5275 | 61 for (octave_idx_type i = 0; i < nz; i++) |
5164 | 62 if (data(i) != a.data(i) || ridx(i) != a.ridx(i)) |
63 return false; | |
64 | |
65 return true; | |
66 } | |
67 | |
68 bool | |
69 SparseBoolMatrix::operator != (const SparseBoolMatrix& a) const | |
70 { | |
71 return !(*this == a); | |
72 } | |
73 | |
74 SparseBoolMatrix& | |
5275 | 75 SparseBoolMatrix::insert (const SparseBoolMatrix& a, octave_idx_type r, octave_idx_type c) |
5164 | 76 { |
77 Sparse<bool>::insert (a, r, c); | |
78 return *this; | |
79 } | |
80 | |
6823 | 81 SparseBoolMatrix& |
82 SparseBoolMatrix::insert (const SparseBoolMatrix& a, const Array<octave_idx_type>& indx) | |
83 { | |
84 Sparse<bool>::insert (a, indx); | |
85 return *this; | |
86 } | |
87 | |
5164 | 88 SparseBoolMatrix |
5275 | 89 SparseBoolMatrix::concat (const SparseBoolMatrix& rb, const Array<octave_idx_type>& ra_idx) |
5164 | 90 { |
91 // Don't use numel to avoid all possiblity of an overflow | |
92 if (rb.rows () > 0 && rb.cols () > 0) | |
93 insert (rb, ra_idx(0), ra_idx(1)); | |
94 return *this; | |
95 } | |
96 | |
97 // unary operations | |
98 | |
99 SparseBoolMatrix | |
100 SparseBoolMatrix::operator ! (void) const | |
101 { | |
5275 | 102 octave_idx_type nr = rows (); |
103 octave_idx_type nc = cols (); | |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
104 octave_idx_type nz1 = nnz (); |
5275 | 105 octave_idx_type nz2 = nr*nc - nz1; |
5164 | 106 |
107 SparseBoolMatrix r (nr, nc, nz2); | |
108 | |
5275 | 109 octave_idx_type ii = 0; |
110 octave_idx_type jj = 0; | |
6217 | 111 r.cidx (0) = 0; |
5275 | 112 for (octave_idx_type i = 0; i < nc; i++) |
5164 | 113 { |
5275 | 114 for (octave_idx_type j = 0; j < nr; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
116 if (jj < cidx(i+1) && ridx(jj) == j) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
117 jj++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
118 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
119 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
120 r.data(ii) = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
121 r.ridx(ii++) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
122 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
123 } |
6217 | 124 r.cidx (i+1) = ii; |
5164 | 125 } |
126 | |
127 return r; | |
128 } | |
129 | |
130 // other operations | |
131 | |
5775 | 132 // FIXME Do these really belong here? Maybe they should be |
5164 | 133 // in a base class? |
134 | |
135 SparseBoolMatrix | |
136 SparseBoolMatrix::all (int dim) const | |
137 { | |
138 SPARSE_ALL_OP (dim); | |
139 } | |
140 | |
141 SparseBoolMatrix | |
142 SparseBoolMatrix::any (int dim) const | |
143 { | |
10976
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
144 Sparse<bool> retval; |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
145 octave_idx_type nr = rows (), nc = cols (), nz = nnz (); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
146 if (dim == -1) |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
147 dim = (nr == 1 && nc != 1) ? 1 : 0; |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
148 |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
149 if (dim == 0) |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
150 { |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
151 // Result is a row vector. |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
152 retval = Sparse<bool> (1, nc); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
153 for(octave_idx_type i = 0; i < nc; i++) |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
154 retval.xcidx(i+1) = retval.xcidx(i) + (cidx(i+1) > cidx(i)); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
155 octave_idx_type new_nz = retval.xcidx(nc); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
156 retval.change_capacity (new_nz); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
157 fill_or_memset (new_nz, static_cast<octave_idx_type> (0), retval.ridx ()); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
158 fill_or_memset (new_nz, true, retval.data ()); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
159 } |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
160 else if (dim == 1) |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
161 { |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
162 // Result is a column vector. |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
163 if (nz > nr/4) |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
164 { |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
165 // We can use O(nr) memory. |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
166 Array<bool> tmp (nr, 1, false); |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
167 for (octave_idx_type i = 0; i < nz; i++) |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
168 tmp.xelem(ridx(i)) = true; |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
169 retval = tmp; |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
170 } |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
171 else |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
172 { |
10983
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
173 Array<octave_idx_type> tmp (nz, 1); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
174 copy_or_memcpy (nz, ridx (), tmp.fortran_vec ()); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
175 retval = Sparse<bool> (Array<bool> (1, 1, true), |
11287 | 176 idx_vector (tmp), |
177 idx_vector (static_cast<octave_idx_type> (0)), | |
178 nr, 1, false); | |
10983
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
179 } |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
180 } |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
181 |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
182 return retval; |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
183 } |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
184 |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
185 SparseMatrix |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
186 SparseBoolMatrix::sum (int dim) const |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
187 { |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
188 Sparse<double> retval; |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
189 octave_idx_type nr = rows (), nc = cols (), nz = nnz (); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
190 if (dim == -1) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
191 dim = (nr == 1 && nc != 1) ? 1 : 0; |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
192 |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
193 if (dim == 0) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
194 { |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
195 // Result is a row vector. |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
196 retval = Sparse<double> (1, nc); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
197 for(octave_idx_type i = 0; i < nc; i++) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
198 retval.xcidx(i+1) = retval.xcidx(i) + (cidx(i+1) > cidx(i)); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
199 octave_idx_type new_nz = retval.xcidx(nc); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
200 retval.change_capacity (new_nz); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
201 fill_or_memset (new_nz, static_cast<octave_idx_type> (0), retval.ridx ()); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
202 for(octave_idx_type i = 0, k = 0; i < nc; i++) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
203 { |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
204 octave_idx_type c = cidx(i+1) - cidx(i); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
205 if (c > 0) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
206 retval.xdata(k++) = c; |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
207 } |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
208 } |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
209 else if (dim == 1) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
210 { |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
211 // Result is a column vector. |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
212 if (nz > nr) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
213 { |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
214 // We can use O(nr) memory. |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
215 Array<double> tmp (nr, 1, 0); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
216 for (octave_idx_type i = 0; i < nz; i++) |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
217 tmp.xelem(ridx(i)) += 1.0; |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
218 retval = tmp; |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
219 } |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
220 else |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
221 { |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
222 Array<octave_idx_type> tmp (nz, 1); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
223 copy_or_memcpy (nz, ridx (), tmp.fortran_vec ()); |
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10976
diff
changeset
|
224 retval = Sparse<double> (Array<double> (1, 1, 1.0), |
11287 | 225 idx_vector (tmp), |
226 idx_vector (static_cast<octave_idx_type> (0)), | |
227 nr, 1); | |
10976
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
228 } |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
229 } |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
230 |
80653e42a551
optimize any for sparse bool matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
231 return retval; |
5164 | 232 } |
233 | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
234 SparseBoolMatrix |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
235 SparseBoolMatrix::diag (octave_idx_type k) const |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
236 { |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7515
diff
changeset
|
237 return Sparse<bool>::diag (k); |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
238 } |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
239 |
5164 | 240 boolMatrix |
241 SparseBoolMatrix::matrix_value (void) const | |
242 { | |
5275 | 243 octave_idx_type nr = rows (); |
244 octave_idx_type nc = cols (); | |
5164 | 245 |
246 boolMatrix retval (nr, nc, false); | |
5275 | 247 for (octave_idx_type j = 0; j < nc; j++) |
248 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) | |
5164 | 249 retval.elem (ridx(i), j) = data (i); |
250 | |
251 return retval; | |
252 } | |
253 | |
254 std::ostream& | |
255 operator << (std::ostream& os, const SparseBoolMatrix& a) | |
256 { | |
5275 | 257 octave_idx_type nc = a.cols (); |
5164 | 258 |
259 // add one to the printed indices to go from | |
260 // zero-based to one-based arrays | |
5275 | 261 for (octave_idx_type j = 0; j < nc; j++) |
5164 | 262 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
263 octave_quit (); |
5275 | 264 for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
265 os << a.ridx(i) + 1 << " " << j + 1 << " " << a.data(i) << "\n"; |
5164 | 266 } |
267 | |
268 return os; | |
269 } | |
270 | |
271 std::istream& | |
272 operator >> (std::istream& is, SparseBoolMatrix& a) | |
273 { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8999
diff
changeset
|
274 typedef SparseBoolMatrix::element_type elt_type; |
5164 | 275 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8999
diff
changeset
|
276 return read_sparse_matrix<elt_type> (is, a, octave_read_value<bool>); |
5164 | 277 } |
278 | |
279 SparseBoolMatrix | |
280 SparseBoolMatrix::squeeze (void) const | |
281 { | |
282 return Sparse<bool>::squeeze (); | |
283 } | |
284 | |
285 SparseBoolMatrix | |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
286 SparseBoolMatrix::index (const idx_vector& i, bool resize_ok) const |
5164 | 287 { |
288 return Sparse<bool>::index (i, resize_ok); | |
289 } | |
290 | |
291 SparseBoolMatrix | |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
292 SparseBoolMatrix::index (const idx_vector& i, const idx_vector& j, bool resize_ok) const |
5164 | 293 { |
294 return Sparse<bool>::index (i, j, resize_ok); | |
295 } | |
296 | |
297 SparseBoolMatrix | |
298 SparseBoolMatrix::reshape (const dim_vector& new_dims) const | |
299 { | |
300 return Sparse<bool>::reshape (new_dims); | |
301 } | |
302 | |
303 SparseBoolMatrix | |
5275 | 304 SparseBoolMatrix::permute (const Array<octave_idx_type>& vec, bool inv) const |
5164 | 305 { |
306 return Sparse<bool>::permute (vec, inv); | |
307 } | |
308 | |
309 SparseBoolMatrix | |
5275 | 310 SparseBoolMatrix::ipermute (const Array<octave_idx_type>& vec) const |
5164 | 311 { |
312 return Sparse<bool>::ipermute (vec); | |
313 } | |
314 | |
315 SPARSE_SMS_EQNE_OPS (SparseBoolMatrix, false, , bool, false, ) | |
316 SPARSE_SMS_BOOL_OPS (SparseBoolMatrix, bool, false) | |
317 | |
318 SPARSE_SSM_EQNE_OPS (bool, false, , SparseBoolMatrix, false, ) | |
319 SPARSE_SSM_BOOL_OPS (bool, SparseBoolMatrix, false) | |
320 | |
321 SPARSE_SMSM_EQNE_OPS (SparseBoolMatrix, false, , SparseBoolMatrix, false, ) | |
322 SPARSE_SMSM_BOOL_OPS (SparseBoolMatrix, SparseBoolMatrix, false) |