annotate liboctave/array/Sparse.h @ 27081:c0d8ce61c1c9 stable

Always reserve at least 1 element of storage for sparse matrices (bug #56232). * Sparse.h (SparseRep (void), SparseRep (octave_idx_type n), SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 1)): Rewrite constructors to always create valid d and r pointers with enough memory for 1 value. Always initialize nzmx to at least 1. * Sparse.cc (SparseRep::change_length): Check for nz == 0 and change value to 1 so that sparse array always maintains memory for at least one value. * amd.cc (Famd): Re-write failing BIST test that now works. * data.cc (Fnzmax): Document that nzmax will always return at least 1. * sparse.cc (Fspalloc): Document that 1 element will always be allocated.
author Rik <rik@octave.org>
date Wed, 08 May 2019 15:18:32 -0700
parents 00f796120a6d
children 9a5b6b929f75
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
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25810
diff changeset
3 Copyright (C) 2004-2019 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10716
diff changeset
4 Copyright (C) 1998-2004 Andy Adler
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10515
diff changeset
5 Copyright (C) 2010 VZLU Prague
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
6
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24208
diff changeset
9 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24208
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 (at your option) any later version.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
13
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
17 GNU General Public License for more details.
5164
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: 6708
diff changeset
20 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24208
diff changeset
21 <https://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
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20232
diff changeset
25 #if ! defined (octave_Sparse_h)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
26 #define octave_Sparse_h 1
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
28 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
29
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
30 #include <cassert>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31 #include <cstddef>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
32
23408
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
33 #include <algorithm>
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
34 #include <iosfwd>
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23420
diff changeset
35 #include <string>
5164
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 "Array.h"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
38
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
39 class idx_vector;
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
40 class PermMatrix;
5164
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 // Two dimensional sparse class. Handles the reference counting for
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43 // all the derived classes.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
44
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
45 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 class
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
47 Sparse
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
48 {
8181
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
49 public:
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
50
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8181
diff changeset
51 typedef T element_type;
8181
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
52
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
53 protected:
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 // The real representation of all Sparse arrays.
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
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5900
diff changeset
58 class OCTAVE_API SparseRep
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
59 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
60 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
61
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
62 T *d;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
63 octave_idx_type *r;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
64 octave_idx_type *c;
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
65 octave_idx_type nzmx;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
66 octave_idx_type nrows;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
67 octave_idx_type ncols;
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
68 octave::refcount<int> count;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
69
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
70 SparseRep (void)
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
71 : d (new T [1]), r (new octave_idx_type [1] {}),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
72 c (new octave_idx_type [1] {}),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
73 nzmx (1), nrows (0), ncols (0), count (1)
23408
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
74 { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
75
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
76 SparseRep (octave_idx_type n)
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
77 : d (new T [1]), r (new octave_idx_type [1] {}),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
78 c (new octave_idx_type [n+1] {}),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
79 nzmx (1), nrows (n), ncols (n), count (1)
23408
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
80 { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
81
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
82 SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 1)
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
83 : d (nz > 0 ? new T [nz] : new T [1]),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
84 r (nz > 0 ? new octave_idx_type [nz] {} : new octave_idx_type [1] {}),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
85 c (new octave_idx_type [nc+1] {}),
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
86 nzmx (nz > 0 ? nz : 1), nrows (nr), ncols (nc), count (1)
23408
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
87 { }
5164
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 SparseRep (const SparseRep& a)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
90 : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
91 c (new octave_idx_type [a.ncols + 1]),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
93 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
94 octave_idx_type nz = a.nnz ();
23408
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
95 std::copy_n (a.d, nz, d);
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
96 std::copy_n (a.r, nz, r);
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
97 std::copy_n (a.c, ncols + 1, c);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
98 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
99
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
100 ~SparseRep (void) { delete [] d; delete [] r; delete [] c; }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
101
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
102 octave_idx_type length (void) const { return nzmx; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
103
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
104 octave_idx_type nnz (void) const { return c[ncols]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
105
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
106 T& elem (octave_idx_type _r, octave_idx_type _c);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
107
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
108 T celem (octave_idx_type _r, octave_idx_type _c) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
109
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
110 T& data (octave_idx_type i) { return d[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
111
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
112 T cdata (octave_idx_type i) const { return d[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
113
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
114 octave_idx_type& ridx (octave_idx_type i) { return r[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
115
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
116 octave_idx_type cridx (octave_idx_type i) const { return r[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
117
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
118 octave_idx_type& cidx (octave_idx_type i) { return c[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
119
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
120 octave_idx_type ccidx (octave_idx_type i) const { return c[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
121
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
122 void maybe_compress (bool remove_zeros);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
123
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
124 void change_length (octave_idx_type nz);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
126 bool indices_ok (void) const;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
127
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
128 bool any_element_is_nan (void) const;
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
129
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130 private:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132 // No assignment!
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
133
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
134 SparseRep& operator = (const SparseRep& a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
135 };
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
136
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
137 //--------------------------------------------------------------------
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 void make_unique (void)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
140 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
141 if (rep->count > 1)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
142 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
143 SparseRep *r = new SparseRep (*rep);
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13030
diff changeset
144
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
145 if (--rep->count == 0)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
146 delete rep;
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13030
diff changeset
147
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
148 rep = r;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
149 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
150 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
151
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
152 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
153
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
154 // !!! WARNING !!! -- these should be protected, not public. You
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
155 // should not access these data members directly!
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 typename Sparse<T>::SparseRep *rep;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
158
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
159 dim_vector dimensions;
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 private:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
162
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
163 static typename Sparse<T>::SparseRep *nil_rep (void);
5164
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 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
166
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
167 Sparse (void)
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
168 : rep (nil_rep ()), dimensions (dim_vector (0,0))
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
169 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
170 rep->count++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
171 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
172
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
173 explicit Sparse (octave_idx_type n)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
174 : rep (new typename Sparse<T>::SparseRep (n)),
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
175 dimensions (dim_vector (n, n)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
176
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
177 explicit Sparse (octave_idx_type nr, octave_idx_type nc)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
178 : rep (new typename Sparse<T>::SparseRep (nr, nc)),
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
179 dimensions (dim_vector (nr, nc)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
180
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
181 explicit Sparse (octave_idx_type nr, octave_idx_type nc, T val);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
182
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
183 Sparse (const dim_vector& dv, octave_idx_type nz)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
184 : rep (new typename Sparse<T>::SparseRep (dv(0), dv(1), nz)),
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
185 dimensions (dv) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
186
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
187 Sparse (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
188 : rep (new typename Sparse<T>::SparseRep (nr, nc, nz)),
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
189 dimensions (dim_vector (nr, nc)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
190
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
191 // Both SparseMatrix and SparseBoolMatrix need this ctor, and this
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
192 // is their only common ancestor.
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
193 explicit Sparse (const PermMatrix& a);
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
194
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
195 // Type conversion case. Preserves nzmax.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
196 template <typename U>
10515
189274f6c7c4 omissions from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10514
diff changeset
197 Sparse (const Sparse<U>& a)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
198 : rep (new typename Sparse<T>::SparseRep (a.rep->nrows, a.rep->ncols,
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
199 a.rep->nzmx)),
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
200 dimensions (a.dimensions)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
201 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
202 octave_idx_type nz = a.nnz ();
23420
1fee389bd04b Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents: 23408
diff changeset
203 std::copy_n (a.rep->d, nz, rep->d);
1fee389bd04b Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents: 23408
diff changeset
204 std::copy_n (a.rep->r, nz, rep->r);
1fee389bd04b Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents: 23408
diff changeset
205 std::copy_n (a.rep->c, rep->ncols + 1, rep->c);
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
206 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
207
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
208 // No type conversion case.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
209 Sparse (const Sparse<T>& a)
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
210 : rep (a.rep), dimensions (a.dimensions)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
211 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
212 rep->count++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
213 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
214
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
215 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
216
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
217 Sparse (const dim_vector& dv);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
218
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
219 Sparse (const Sparse<T>& a, const dim_vector& dv);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
220
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
221 Sparse (const Array<T>& a, const idx_vector& r, const idx_vector& c,
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
222 octave_idx_type nr = -1, octave_idx_type nc = -1,
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
223 bool sum_terms = true, octave_idx_type nzm = -1);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
224
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
225 // Sparsify a normal matrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
226 Sparse (const Array<T>& a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
227
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
228 virtual ~Sparse (void);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
229
7717
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
230 Sparse<T>& operator = (const Sparse<T>& a);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
231
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
232 //! Amount of storage for nonzero elements.
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
233 //! This may differ from the actual number of elements, see nnz().
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
234 octave_idx_type nzmax (void) const { return rep->length (); }
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
235
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
236 //! Amount of storage for nonzero elements.
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
237 //! Synonymous with nzmax().
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23593
diff changeset
238 OCTAVE_DEPRECATED (4.4, "use 'nzmax' instead")
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
239 octave_idx_type capacity (void) const { return nzmax (); }
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
240
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
241 //! Actual number of nonzero terms.
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
242 octave_idx_type nnz (void) const { return rep->nnz (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
243
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
244 // Querying the number of elements (incl. zeros) may overflow the index type,
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
245 // so don't do it unless you really need it.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
246 octave_idx_type numel (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
247 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
248 return dimensions.safe_numel ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
249 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
250
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23593
diff changeset
251 OCTAVE_DEPRECATED (4.4, "use 'nzmax' instead")
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
252 octave_idx_type nelem (void) const { return nzmax (); }
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
253
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23593
diff changeset
254 OCTAVE_DEPRECATED (4.4, "use 'numel' instead")
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
255 octave_idx_type length (void) const { return numel (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
256
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
257 octave_idx_type dim1 (void) const { return dimensions(0); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
258 octave_idx_type dim2 (void) const { return dimensions(1); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
259
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
260 octave_idx_type rows (void) const { return dim1 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
261 octave_idx_type cols (void) const { return dim2 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
262 octave_idx_type columns (void) const { return dim2 (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
263
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
264 octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
265 octave_idx_type get_col_index (octave_idx_type k)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
266 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
267 octave_idx_type ret = 0;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
268 while (cidx (ret+1) < k)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
269 ret++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
270 return ret;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
271 }
10358
72fab01e5d68 improve some size_t queries
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
272
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
273 size_t byte_size (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
274 {
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
275 return (static_cast<size_t> (cols () + 1) * sizeof (octave_idx_type)
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
276 + static_cast<size_t> (nzmax ())
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
277 * (sizeof (T) + sizeof (octave_idx_type)));
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
278 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
279
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
280 dim_vector dims (void) const { return dimensions; }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
281
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
282 Sparse<T> squeeze (void) const { return *this; }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
283
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
284 octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
285
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
286 // FIXME: Functions are marked as NORETURN, but they are used with
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
287 // a return statement in following code. Shouldn't that be fixed?
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
288 OCTAVE_NORETURN T range_error (const char *fcn, octave_idx_type n) const;
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
289 OCTAVE_NORETURN T& range_error (const char *fcn, octave_idx_type n);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
290
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
291 OCTAVE_NORETURN T range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
292 octave_idx_type i, octave_idx_type j) const;
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
293 OCTAVE_NORETURN T& range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
294 octave_idx_type i, octave_idx_type j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
295
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
296 OCTAVE_NORETURN T range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
297 const Array<octave_idx_type>& ra_idx) const;
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
298 OCTAVE_NORETURN T& range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
299 const Array<octave_idx_type>& ra_idx);
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 // No checking, even for multiple references, ever.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
302
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
303 T& xelem (octave_idx_type n)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
304 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
305 octave_idx_type i = n % rows ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
306 octave_idx_type j = n / rows ();
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
307 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
308 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
309
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
310 T xelem (octave_idx_type n) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
311 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
312 octave_idx_type i = n % rows ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
313 octave_idx_type j = n / rows ();
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
314 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
315 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
316
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
317 T& xelem (octave_idx_type i, octave_idx_type j) { return rep->elem (i, j); }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
318 T xelem (octave_idx_type i, octave_idx_type j) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
319 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
320 return rep->celem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
321 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
322
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
323 T& xelem (const Array<octave_idx_type>& ra_idx)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
324 { return xelem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
325
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
326 T xelem (const Array<octave_idx_type>& ra_idx) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
327 { return xelem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
328
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
329 // FIXME: would be nice to fix this so that we don't unnecessarily force a
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
330 // copy, but that is not so easy, and I see no clean way to do it.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
331
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
332 T& checkelem (octave_idx_type n)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
333 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
334 if (n < 0 || n >= numel ())
24208
eec262017c6a maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 24018
diff changeset
335 // FIXME: Why should we "return" when range_error is OCTAVE_NORETURN?
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
336 return range_error ("T& Sparse<T>::checkelem", n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
337 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
338 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
339 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
340 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
341 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
342 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
343
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
344 T& checkelem (octave_idx_type i, octave_idx_type j)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
345 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
346 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
347 return range_error ("T& Sparse<T>::checkelem", i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
348 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
349 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
350 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
351 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
352 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
353 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
354
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
355 T& checkelem (const Array<octave_idx_type>& ra_idx)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
356 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
357 octave_idx_type i = compute_index (ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
358
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
359 if (i < 0)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
360 return range_error ("T& Sparse<T>::checkelem", ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
361 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
362 return elem (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
363 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
364
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
365 T& elem (octave_idx_type n)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
366 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
367 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
368 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
369 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
370
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
371 T& elem (octave_idx_type i, octave_idx_type j)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
372 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
373 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
374 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
375 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
376
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
377 T& elem (const Array<octave_idx_type>& ra_idx)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
378 { return Sparse<T>::elem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
379
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
380 T& operator () (octave_idx_type n)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
381 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
382 return elem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
383 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
384
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
385 T& operator () (octave_idx_type i, octave_idx_type j)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
386 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
387 return elem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
388 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
389
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
390 T& operator () (const Array<octave_idx_type>& ra_idx)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
391 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
392 return elem (ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
393 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
394
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
395 T checkelem (octave_idx_type n) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
396 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
397 if (n < 0 || n >= numel ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
398 return range_error ("T Sparse<T>::checkelem", n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
399 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
400 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
401 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
402
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
403 T checkelem (octave_idx_type i, octave_idx_type j) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
404 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
405 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
406 return range_error ("T Sparse<T>::checkelem", i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
407 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
408 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
409 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
410
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
411 T checkelem (const Array<octave_idx_type>& ra_idx) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
412 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
413 octave_idx_type i = compute_index (ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
414
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
415 if (i < 0)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
416 return range_error ("T Sparse<T>::checkelem", ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
417 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
418 return Sparse<T>::elem (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
419 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
420
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
421 T elem (octave_idx_type n) const { return xelem (n); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
422
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
423 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
424
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
425 T elem (const Array<octave_idx_type>& ra_idx) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
426 { return Sparse<T>::elem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
427
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23449
diff changeset
428 T operator () (octave_idx_type n) const { return elem (n); }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
429
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
430 T operator () (octave_idx_type i, octave_idx_type j) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
431 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
432 return elem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
433 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
434
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
435 T operator () (const Array<octave_idx_type>& ra_idx) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
436 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
437 return elem (ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
438 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
439
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
440 Sparse<T> maybe_compress (bool remove_zeros = false)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
441 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
442 if (remove_zeros)
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
443 make_unique (); // Need to unshare because elements are removed.
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
444
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
445 rep->maybe_compress (remove_zeros);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
446 return (*this);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
447 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
448
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
449 Sparse<T> reshape (const dim_vector& new_dims) const;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
450
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
451 Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
452
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
453 Sparse<T> ipermute (const Array<octave_idx_type>& vec) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
454 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
455 return permute (vec, true);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
456 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
457
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
458 void resize1 (octave_idx_type n);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
459
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
460 void resize (octave_idx_type r, octave_idx_type c);
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
461
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
462 void resize (const dim_vector& dv);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
463
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
464 void change_capacity (octave_idx_type nz)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
465 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
466 if (nz < nnz ())
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
467 make_unique (); // Unshare now because elements will be truncated.
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
468 rep->change_length (nz);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
469 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
470
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
471 Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
472 Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
473
23593
a8361bc2361a maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents: 23577
diff changeset
474 bool issquare (void) const { return (dim1 () == dim2 ()); }
a8361bc2361a maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents: 23577
diff changeset
475
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23593
diff changeset
476 OCTAVE_DEPRECATED (4.4, "use 'issquare' instead")
23593
a8361bc2361a maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents: 23577
diff changeset
477 bool is_square (void) const
a8361bc2361a maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents: 23577
diff changeset
478 { return issquare (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
479
25810
7233dae64579 Stop segfault when concatening sparse matrices (bug #54527).
Rik <rik@octave.org>
parents: 25054
diff changeset
480 bool isempty (void) const { return (rows () < 1 || cols () < 1); }
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23487
diff changeset
481
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23593
diff changeset
482 OCTAVE_DEPRECATED (4.4, "use 'isempty' instead")
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23487
diff changeset
483 bool is_empty (void) const
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23487
diff changeset
484 { return isempty (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
485
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
486 Sparse<T> transpose (void) const;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
487
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
488 T * data (void) { make_unique (); return rep->d; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
489 T& data (octave_idx_type i) { make_unique (); return rep->data (i); }
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
490 T * xdata (void) { return rep->d; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
491 T& xdata (octave_idx_type i) { return rep->data (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
492
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
493 T data (octave_idx_type i) const { return rep->data (i); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
494 // FIXME: shouldn't this be returning const T*?
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
495 T * data (void) const { return rep->d; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
496
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
497 octave_idx_type * ridx (void) { make_unique (); return rep->r; }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
498 octave_idx_type& ridx (octave_idx_type i)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
499 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
500 make_unique (); return rep->ridx (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
501 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
502
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
503 octave_idx_type * xridx (void) { return rep->r; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
504 octave_idx_type& xridx (octave_idx_type i) { return rep->ridx (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
505
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
506 octave_idx_type ridx (octave_idx_type i) const { return rep->cridx (i); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
507 // FIXME: shouldn't this be returning const octave_idx_type*?
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
508 octave_idx_type * ridx (void) const { return rep->r; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
509
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
510 octave_idx_type * cidx (void) { make_unique (); return rep->c; }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
511 octave_idx_type& cidx (octave_idx_type i)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
512 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
513 make_unique (); return rep->cidx (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
514 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
515
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
516 octave_idx_type * xcidx (void) { return rep->c; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
517 octave_idx_type& xcidx (octave_idx_type i) { return rep->cidx (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
518
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
519 octave_idx_type cidx (octave_idx_type i) const { return rep->ccidx (i); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
520 // FIXME: shouldn't this be returning const octave_idx_type*?
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
521 octave_idx_type * cidx (void) const { return rep->c; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
522
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
523 octave_idx_type ndims (void) const { return dimensions.ndims (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
524
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
525 void delete_elements (const idx_vector& i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
526
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
527 void delete_elements (int dim, const idx_vector& i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
528
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
529 void delete_elements (const idx_vector& i, const idx_vector& j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
530
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
531 Sparse<T> index (const idx_vector& i, bool resize_ok = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
532
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
533 Sparse<T> index (const idx_vector& i, const idx_vector& j,
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
534 bool resize_ok = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
535
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
536 void assign (const idx_vector& i, const Sparse<T>& rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
537
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
538 void assign (const idx_vector& i, const idx_vector& j, const Sparse<T>& rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
539
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
540 void print_info (std::ostream& os, const std::string& prefix) const;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
541
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
542 // Unsafe. These functions exist to support the MEX interface.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
543 // You should not use them anywhere else.
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23443
diff changeset
544 void * mex_get_data (void) const { return const_cast<T *> (data ()); }
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
545
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23443
diff changeset
546 octave_idx_type * mex_get_ir (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
547 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
548 return const_cast<octave_idx_type *> (ridx ());
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
549 }
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
550
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23443
diff changeset
551 octave_idx_type * mex_get_jc (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
552 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
553 return const_cast<octave_idx_type *> (cidx ());
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
554 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
555
7463
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
556 Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
557 Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
558 sortmode mode = ASCENDING) const;
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
559
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7602
diff changeset
560 Sparse<T> diag (octave_idx_type k = 0) const;
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7602
diff changeset
561
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10537
diff changeset
562 // dim = -1 and dim = -2 are special; see Array<T>::cat description.
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
563 static Sparse<T>
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
564 cat (int dim, octave_idx_type n, const Sparse<T> *sparse_list);
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
565
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
566 Array<T> array_value (void) const;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
567
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
568 // Generic any/all test functionality with arbitrary predicate.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
569 template <typename F, bool zero>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
570 bool test (F fcn) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
571 {
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
572 return any_all_test<F, T, zero> (fcn, data (), nnz ());
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
573 }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
574
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
575 // Simpler calls.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
576 template <typename F>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
577 bool test_any (F fcn) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
578 { return test<F, false> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
579
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
580 template <typename F>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
581 bool test_all (F fcn) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
582 { return test<F, true> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
583
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
584 // Overloads for function references.
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
585 bool test_any (bool (&fcn) (T)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
586 { return test<bool (&) (T), false> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
587
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
588 bool test_any (bool (&fcn) (const T&)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
589 { return test<bool (&) (const T&), false> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
590
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
591 bool test_all (bool (&fcn) (T)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
592 { return test<bool (&) (T), true> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
593
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
594 bool test_all (bool (&fcn) (const T&)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
595 { return test<bool (&) (const T&), true> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
596
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
597 template <typename U, typename F>
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
598 Sparse<U>
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
599 map (F fcn) const
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
600 {
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
601 Sparse<U> result;
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
602 U f_zero = fcn (0.0);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
603
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
604 if (f_zero != 0.0)
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
605 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
606 octave_idx_type nr = rows ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
607 octave_idx_type nc = cols ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
608
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
609 result = Sparse<U> (nr, nc, f_zero);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
610
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
611 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
612 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
613 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
614 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
615 /* Use data instead of elem for better performance. */
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
616 result.data (ridx (i) + j * nr) = fcn (data (i));
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
617 }
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
618
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
619 result.maybe_compress (true);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
620 }
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
621 else
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
622 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
623 octave_idx_type nz = nnz ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
624 octave_idx_type nr = rows ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
625 octave_idx_type nc = cols ();
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
626
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
627 result = Sparse<U> (nr, nc, nz);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
628 octave_idx_type ii = 0;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
629 result.cidx (ii) = 0;
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
630
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
631 for (octave_idx_type j = 0; j < nc; j++)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
632 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
633 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
634 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
635 U val = fcn (data (i));
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
636 if (val != 0.0)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
637 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
638 result.data (ii) = val;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
639 result.ridx (ii++) = ridx (i);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
640 }
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
641 octave_quit ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
642 }
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
643 result.cidx (j+1) = ii;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
644 }
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
645
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
646 result.maybe_compress (false);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
647 }
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
648
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
649 return result;
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
650 }
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
651
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
652 // Overloads for function references.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
653 template <typename U>
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
654 Sparse<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
655 map (U (&fcn) (T)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
656 { return map<U, U (&) (T)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
657
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
658 template <typename U>
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
659 Sparse<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
660 map (U (&fcn) (const T&)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
661 { return map<U, U (&) (const T&)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
662
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
663 bool indices_ok (void) const { return rep->indices_ok (); }
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
664
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
665 bool any_element_is_nan (void) const
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
666 { return rep->any_element_is_nan (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
667 };
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
668
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
669 template <typename T>
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
670 std::istream&
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
671 read_sparse_matrix (std::istream& is, Sparse<T>& a,
21704
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21660
diff changeset
672 T (*read_fcn) (std::istream&));
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
673
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
674 #endif