annotate liboctave/array/Sparse.h @ 28976:4e1805033979

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