Mercurial > octave
annotate liboctave/array/Sparse.h @ 29937:da7210e30f3e
move some utility functions inside octave namespace
* lo-utils.h, lo-utils.cc (is_one_or_zero): Rename from
xis_one_or_zero and move inside octave namespace. Change all uses.
(is_zero): Rename from xis_zero and move inside octave namespace.
Change all uses.
(is_int_or_inf_or_nan): Rename from xis_int_or_inf_or_nan and move
inside octave namespace. Change all uses.
(too_large_for_float): Rename from xtoo_large_for_float and move
inside octave namespace. Change all uses.
(too_large_for_float): Rename from xtoo_large_for_float and move
inside octave namespace. Change all uses.
(is_int_or_inf_or_nan): Rename from xis_int_or_inf_or_nan and move
inside octave namespace. Change all uses.
(fgets): Rename from octave_fgets and move inside octave namespace.
Change all uses.
(fgetl): Rename from octave_fgetl and move inside octave namespace.
Change all uses.
(any_all_test, strsave): Move inside octave namespace. Tag uses with
octave:: prefix as needed.
* lo-utils.h: Provide deprecated templates and inline functions to
preserve old names in global namespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 03 Aug 2021 12:34:52 -0400 |
parents | 6a8642d310c8 |
children | c92a4ebaa777 |
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 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 1998-2021 The Octave Project Developers |
27923
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 | 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 | 27 #define octave_Sparse_h 1 |
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 | 31 #include <cassert> |
32 #include <cstddef> | |
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 | 37 |
13030
b646413c3d0e
Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12125
diff
changeset
|
38 class PermMatrix; |
29897
7c7599ad9c5a
Sparse.h: Use forward declaration for Array class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
39 template <typename T> class Array; |
5164 | 40 |
41 // Two dimensional sparse class. Handles the reference counting for | |
42 // all the derived classes. | |
43 | |
29279
e4c152e827aa
Visibility: Forward declare template classes with visibility attributes (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29227
diff
changeset
|
44 // forward declare template with visibility attribute |
e4c152e827aa
Visibility: Forward declare template classes with visibility attributes (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29227
diff
changeset
|
45 template <typename T> class OCTAVE_API Sparse; |
e4c152e827aa
Visibility: Forward declare template classes with visibility attributes (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29227
diff
changeset
|
46 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
47 template <typename T> |
5164 | 48 class |
49 Sparse | |
50 { | |
8181
1ebcb9872ced
fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents:
7717
diff
changeset
|
51 public: |
1ebcb9872ced
fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents:
7717
diff
changeset
|
52 |
8918
f5408862892f
Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents:
8181
diff
changeset
|
53 typedef T element_type; |
8181
1ebcb9872ced
fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents:
7717
diff
changeset
|
54 |
5164 | 55 protected: |
56 //-------------------------------------------------------------------- | |
57 // The real representation of all Sparse arrays. | |
58 //-------------------------------------------------------------------- | |
59 | |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
60 class SparseRep |
5164 | 61 { |
62 public: | |
63 | |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
64 T *m_data; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
65 octave_idx_type *m_ridx; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
66 octave_idx_type *m_cidx; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
67 octave_idx_type m_nzmax; |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
68 octave_idx_type m_nrows; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
69 octave_idx_type m_ncols; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
70 octave::refcount<octave_idx_type> m_count; |
5164 | 71 |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
72 SparseRep (void) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
73 : m_data (new T [1]), m_ridx (new octave_idx_type [1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
74 m_cidx (new octave_idx_type [1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
75 m_nzmax (1), m_nrows (0), m_ncols (0), m_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
|
76 { } |
5164 | 77 |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
78 SparseRep (octave_idx_type n) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
79 : m_data (new T [1]), m_ridx (new octave_idx_type [1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
80 m_cidx (new octave_idx_type [n+1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
81 m_nzmax (1), m_nrows (n), m_ncols (n), m_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
|
82 { } |
5164 | 83 |
27081
c0d8ce61c1c9
Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
84 SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 1) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
85 : m_data (nz > 0 ? new T [nz] : new T [1]), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
86 m_ridx (nz > 0 ? new octave_idx_type [nz] {} : new octave_idx_type [1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
87 m_cidx (new octave_idx_type [nc+1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
88 m_nzmax (nz > 0 ? nz : 1), m_nrows (nr), m_ncols (nc), m_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
|
89 { } |
5164 | 90 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
91 SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz, |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
92 const T *d, const octave_idx_type *r, const octave_idx_type *c) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
93 : m_data (new T [nz]), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
94 m_ridx (new octave_idx_type [nz] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
95 m_cidx (new octave_idx_type [nc+1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
96 m_nzmax (nz), m_nrows (nr), m_ncols (nc), m_count (1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
97 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
98 std::copy_n (d, nz, m_data); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
99 std::copy_n (r, nz, m_ridx); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
100 std::copy_n (c, m_ncols + 1, m_cidx); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
101 } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
102 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
103 template <typename U> |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
104 SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz, |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
105 const U *d, const octave_idx_type *r, const octave_idx_type *c) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
106 : m_data (new T [nz]), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
107 m_ridx (new octave_idx_type [nz] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
108 m_cidx (new octave_idx_type [nc+1] {}), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
109 m_nzmax (nz), m_nrows (nr), m_ncols (nc), m_count (1) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
110 { |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
111 std::copy_n (d, nz, m_data); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
112 std::copy_n (r, nz, m_ridx); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
113 std::copy_n (c, nc + 1, m_cidx); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
114 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
115 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
116 SparseRep (const SparseRep& a) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
117 : m_data (new T [a.m_nzmax]), m_ridx (new octave_idx_type [a.m_nzmax]), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
118 m_cidx (new octave_idx_type [a.m_ncols + 1]), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
119 m_nzmax (a.m_nzmax), m_nrows (a.m_nrows), m_ncols (a.m_ncols), m_count (1) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
120 { |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
121 octave_idx_type nz = a.nnz (); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
122 std::copy_n (a.m_data, nz, m_data); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
123 std::copy_n (a.m_ridx, nz, m_ridx); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
124 std::copy_n (a.m_cidx, m_ncols + 1, m_cidx); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
125 } |
5164 | 126 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
127 ~SparseRep (void) { delete [] m_data; delete [] m_ridx; delete [] m_cidx; } |
5164 | 128 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
129 octave_idx_type nzmax (void) const { return m_nzmax; } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
130 octave_idx_type nnz (void) const { return m_cidx[m_ncols]; } |
5164 | 131 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
132 octave_idx_type rows (void) const { return m_nrows; } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
133 octave_idx_type cols (void) const { return m_ncols; } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
134 octave_idx_type columns (void) const { return m_ncols; } |
5164 | 135 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
136 OCTAVE_API T& elem (octave_idx_type r, octave_idx_type c); |
5164 | 137 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
138 OCTAVE_API T celem (octave_idx_type r, octave_idx_type c) const; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
139 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
140 T& data (octave_idx_type i) { return m_data[i]; } |
5164 | 141 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
142 T cdata (octave_idx_type i) const { return m_data[i]; } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
143 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
144 octave_idx_type& ridx (octave_idx_type i) { return m_ridx[i]; } |
5164 | 145 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
146 octave_idx_type cridx (octave_idx_type i) const { return m_ridx[i]; } |
5164 | 147 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
148 octave_idx_type& cidx (octave_idx_type i) { return m_cidx[i]; } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
149 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
150 octave_idx_type ccidx (octave_idx_type i) const { return m_cidx[i]; } |
5164 | 151 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
152 OCTAVE_API void maybe_compress (bool remove_zeros); |
5164 | 153 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
154 OCTAVE_API void change_length (octave_idx_type nz); |
5164 | 155 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
156 OCTAVE_API bool indices_ok (void) const; |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
157 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
158 OCTAVE_API bool any_element_is_nan (void) const; |
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
|
159 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
160 // Prefer nzmax. |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
161 octave_idx_type length (void) const { return m_nzmax; } |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
162 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
163 template <typename U> friend class Sparse; |
5164 | 164 |
165 // No assignment! | |
166 | |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
167 OCTAVE_API SparseRep& operator = (const SparseRep&) = delete; |
5164 | 168 }; |
169 | |
170 //-------------------------------------------------------------------- | |
171 | |
172 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
|
173 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
174 if (m_rep->m_count > 1) |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
175 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
176 SparseRep *r = new SparseRep (*m_rep); |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13030
diff
changeset
|
177 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
178 if (--m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
179 delete m_rep; |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13030
diff
changeset
|
180 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
181 m_rep = r; |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
182 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
183 } |
5164 | 184 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
185 protected: |
5164 | 186 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
187 typename Sparse<T>::SparseRep *m_rep; |
5164 | 188 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
189 dim_vector m_dimensions; |
5164 | 190 |
191 private: | |
192 | |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
193 static OCTAVE_API typename Sparse<T>::SparseRep *nil_rep (void); |
5164 | 194 |
195 public: | |
196 | |
197 Sparse (void) | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
198 : m_rep (nil_rep ()), m_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
|
199 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
200 m_rep->m_count++; |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
201 } |
5164 | 202 |
5275 | 203 explicit Sparse (octave_idx_type n) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
204 : m_rep (new typename Sparse<T>::SparseRep (n)), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
205 m_dimensions (dim_vector (n, n)) { } |
5164 | 206 |
5275 | 207 explicit Sparse (octave_idx_type nr, octave_idx_type nc) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
208 : m_rep (new typename Sparse<T>::SparseRep (nr, nc)), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
209 m_dimensions (dim_vector (nr, nc)) { } |
5164 | 210 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
211 explicit OCTAVE_API Sparse (octave_idx_type nr, octave_idx_type nc, T val); |
5164 | 212 |
5275 | 213 Sparse (const dim_vector& dv, octave_idx_type nz) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
214 : m_rep (new typename Sparse<T>::SparseRep (dv(0), dv(1), nz)), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
215 m_dimensions (dv) { } |
5164 | 216 |
5275 | 217 Sparse (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
218 : m_rep (new typename Sparse<T>::SparseRep (nr, nc, nz)), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
219 m_dimensions (dim_vector (nr, nc)) { } |
5164 | 220 |
13030
b646413c3d0e
Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12125
diff
changeset
|
221 // 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
|
222 // is their only common ancestor. |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
223 explicit OCTAVE_API Sparse (const PermMatrix& a); |
13030
b646413c3d0e
Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12125
diff
changeset
|
224 |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23796
diff
changeset
|
225 // 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
|
226 template <typename U> |
10515
189274f6c7c4
omissions from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
10514
diff
changeset
|
227 Sparse (const Sparse<U>& a) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
228 : m_rep (new typename Sparse<T>::SparseRep (a.rows (), a.cols (), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
229 a.nzmax (), a.data (), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
230 a.ridx (), a.cidx ())), |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
231 m_dimensions (a.dims ()) { } |
5164 | 232 |
233 // No type conversion case. | |
234 Sparse (const Sparse<T>& a) | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
235 : m_rep (a.m_rep), m_dimensions (a.m_dimensions) |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
236 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
237 m_rep->m_count++; |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
238 } |
5164 | 239 |
240 public: | |
241 | |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
242 OCTAVE_API Sparse (const dim_vector& dv); |
5164 | 243 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
244 OCTAVE_API Sparse (const Sparse<T>& a, const dim_vector& dv); |
5164 | 245 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
246 OCTAVE_API |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
247 Sparse (const Array<T>& a, const octave::idx_vector& r, const octave::idx_vector& c, |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
248 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
|
249 bool sum_terms = true, octave_idx_type nzm = -1); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
250 |
5164 | 251 // Sparsify a normal matrix |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
252 OCTAVE_API Sparse (const Array<T>& a); |
5164 | 253 |
254 virtual ~Sparse (void); | |
255 | |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
256 OCTAVE_API Sparse<T>& operator = (const Sparse<T>& a); |
5164 | 257 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
258 //! 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
|
259 //! This may differ from the actual number of elements, see nnz(). |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
260 octave_idx_type nzmax (void) const { return m_rep->nzmax (); } |
21134
2e5c1f766ac9
provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents:
21131
diff
changeset
|
261 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
262 //! Actual number of nonzero terms. |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
263 octave_idx_type nnz (void) const { return m_rep->nnz (); } |
5164 | 264 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
265 // 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
|
266 // 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
|
267 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
|
268 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
269 return m_dimensions.safe_numel (); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
270 } |
5164 | 271 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
272 octave_idx_type dim1 (void) const { return m_dimensions(0); } |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
273 octave_idx_type dim2 (void) const { return m_dimensions(1); } |
5164 | 274 |
5275 | 275 octave_idx_type rows (void) const { return dim1 (); } |
276 octave_idx_type cols (void) const { return dim2 (); } | |
277 octave_idx_type columns (void) const { return dim2 (); } | |
5164 | 278 |
5275 | 279 octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); } |
280 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
|
281 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
282 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
|
283 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
|
284 ret++; |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
285 return ret; |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
286 } |
10358
72fab01e5d68
improve some size_t queries
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
287 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
288 std::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
|
289 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
290 return (static_cast<std::size_t> (cols () + 1) * sizeof (octave_idx_type) |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
291 + static_cast<std::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
|
292 * (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
|
293 } |
5164 | 294 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
295 dim_vector dims (void) const { return m_dimensions; } |
5164 | 296 |
297 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
|
298 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
299 OCTAVE_API octave_idx_type |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
300 compute_index (const Array<octave_idx_type>& ra_idx) const; |
5164 | 301 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
302 OCTAVE_NORETURN OCTAVE_API T |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
303 range_error (const char *fcn, octave_idx_type n) const; |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
304 OCTAVE_NORETURN OCTAVE_API T& |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
305 range_error (const char *fcn, octave_idx_type n); |
5164 | 306 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
307 OCTAVE_NORETURN OCTAVE_API T |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
308 range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const; |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
309 OCTAVE_NORETURN OCTAVE_API T& |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
310 range_error (const char *fcn, octave_idx_type i, octave_idx_type j); |
5164 | 311 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
312 OCTAVE_NORETURN OCTAVE_API T |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
313 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) const; |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
314 OCTAVE_NORETURN OCTAVE_API T& |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
315 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx); |
5164 | 316 |
317 // No checking, even for multiple references, ever. | |
318 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
319 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
|
320 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 } |
5164 | 325 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
326 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
|
327 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
332 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
333 T& xelem (octave_idx_type i, octave_idx_type j) { return m_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
|
334 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
|
335 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
336 return m_rep->celem (i, j); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
337 } |
5164 | 338 |
5275 | 339 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
|
340 { return xelem (compute_index (ra_idx)); } |
5164 | 341 |
5275 | 342 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
|
343 { return xelem (compute_index (ra_idx)); } |
5164 | 344 |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23796
diff
changeset
|
345 // 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
|
346 // copy, but that is not so easy, and I see no clean way to do it. |
5164 | 347 |
5275 | 348 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
|
349 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
350 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
|
351 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
|
352 else |
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 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
357 } |
5164 | 358 |
5275 | 359 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
|
360 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
361 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
|
362 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
|
363 else |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
364 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
365 make_unique (); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
366 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
|
367 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
368 } |
5164 | 369 |
5275 | 370 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
|
371 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
372 octave_idx_type i = compute_index (ra_idx); |
5164 | 373 |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
374 if (i < 0) |
28976
4e1805033979
Sparse.h: remove return statements used with OCTAVE_NORETURN functions.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
375 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
|
376 else |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
377 return elem (i); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
378 } |
5164 | 379 |
5275 | 380 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
|
381 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
382 make_unique (); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
383 return xelem (n); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
384 } |
5164 | 385 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
386 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
|
387 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
388 make_unique (); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
389 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
|
390 } |
5164 | 391 |
5275 | 392 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
|
393 { return Sparse<T>::elem (compute_index (ra_idx)); } |
5164 | 394 |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
395 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
|
396 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
397 return elem (n); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
398 } |
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 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
|
401 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
402 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
|
403 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
404 |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
405 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
|
406 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
407 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
|
408 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
409 |
5275 | 410 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
|
411 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
412 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
|
413 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
|
414 else |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
415 return xelem (n); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
416 } |
5164 | 417 |
5275 | 418 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
|
419 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
420 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
|
421 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
|
422 else |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
423 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
|
424 } |
5164 | 425 |
5275 | 426 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
|
427 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
428 octave_idx_type i = compute_index (ra_idx); |
5164 | 429 |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
430 if (i < 0) |
28976
4e1805033979
Sparse.h: remove return statements used with OCTAVE_NORETURN functions.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
431 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
|
432 else |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
433 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
|
434 } |
5164 | 435 |
5275 | 436 T elem (octave_idx_type n) const { return xelem (n); } |
5164 | 437 |
5275 | 438 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); } |
5164 | 439 |
5275 | 440 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
|
441 { return Sparse<T>::elem (compute_index (ra_idx)); } |
5164 | 442 |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
443 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
|
444 |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
445 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
|
446 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
447 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
|
448 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
449 |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
450 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
|
451 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
452 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
|
453 } |
5164 | 454 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
455 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
|
456 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
457 if (remove_zeros) |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23796
diff
changeset
|
458 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
|
459 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
460 m_rep->maybe_compress (remove_zeros); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
461 return (*this); |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
462 } |
5164 | 463 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
464 OCTAVE_API Sparse<T> reshape (const dim_vector& new_dims) const; |
5164 | 465 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
466 OCTAVE_API Sparse<T> |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
467 permute (const Array<octave_idx_type>& vec, bool inv = false) const; |
5164 | 468 |
5275 | 469 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
|
470 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
471 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
|
472 } |
5164 | 473 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
474 OCTAVE_API void resize1 (octave_idx_type n); |
5164 | 475 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
476 OCTAVE_API void resize (octave_idx_type r, octave_idx_type c); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
477 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
478 OCTAVE_API void resize (const dim_vector& dv); |
5164 | 479 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
480 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
|
481 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
482 if (nz < nnz ()) |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23796
diff
changeset
|
483 make_unique (); // Unshare now because elements will be truncated. |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
484 m_rep->change_length (nz); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
485 } |
5164 | 486 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
487 OCTAVE_API Sparse<T>& |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
488 insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c); |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
489 OCTAVE_API Sparse<T>& |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
490 insert (const Sparse<T>& a, const Array<octave_idx_type>& idx); |
5164 | 491 |
23593
a8361bc2361a
maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
492 bool issquare (void) const { return (dim1 () == dim2 ()); } |
a8361bc2361a
maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
493 |
25810
7233dae64579
Stop segfault when concatening sparse matrices (bug #54527).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
494 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
|
495 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
496 OCTAVE_API Sparse<T> transpose (void) const; |
5164 | 497 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
498 T * data (void) { make_unique (); return m_rep->m_data; } |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
499 T& data (octave_idx_type i) { make_unique (); return m_rep->data (i); } |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
500 T * xdata (void) { return m_rep->m_data; } |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
501 T& xdata (octave_idx_type i) { return m_rep->data (i); } |
5164 | 502 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
503 T data (octave_idx_type i) const { return m_rep->data (i); } |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
504 // FIXME: shouldn't this be returning const T*? |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
505 T * data (void) const { return m_rep->m_data; } |
5164 | 506 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
507 octave_idx_type * ridx (void) { make_unique (); return m_rep->m_ridx; } |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
508 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
|
509 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
510 make_unique (); return m_rep->ridx (i); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
511 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
512 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
513 octave_idx_type * xridx (void) { return m_rep->m_ridx; } |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
514 octave_idx_type& xridx (octave_idx_type i) { return m_rep->ridx (i); } |
5164 | 515 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
516 octave_idx_type ridx (octave_idx_type i) const { return m_rep->cridx (i); } |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
517 // FIXME: shouldn't this be returning const octave_idx_type*? |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
518 octave_idx_type * ridx (void) const { return m_rep->m_ridx; } |
5164 | 519 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
520 octave_idx_type * cidx (void) { make_unique (); return m_rep->m_cidx; } |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
521 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
|
522 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
523 make_unique (); return m_rep->cidx (i); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
524 } |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
525 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
526 octave_idx_type * xcidx (void) { return m_rep->m_cidx; } |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
527 octave_idx_type& xcidx (octave_idx_type i) { return m_rep->cidx (i); } |
5164 | 528 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
529 octave_idx_type cidx (octave_idx_type i) const { return m_rep->ccidx (i); } |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
530 // FIXME: shouldn't this be returning const octave_idx_type*? |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29897
diff
changeset
|
531 octave_idx_type * cidx (void) const { return m_rep->m_cidx; } |
5164 | 532 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
533 octave_idx_type ndims (void) const { return m_dimensions.ndims (); } |
5164 | 534 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
535 OCTAVE_API void delete_elements (const octave::idx_vector& i); |
5164 | 536 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
537 OCTAVE_API void delete_elements (int dim, const octave::idx_vector& i); |
5164 | 538 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
539 OCTAVE_API void delete_elements (const octave::idx_vector& i, const octave::idx_vector& j); |
5164 | 540 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
541 OCTAVE_API Sparse<T> |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
542 index (const octave::idx_vector& i, bool resize_ok = false) const; |
5164 | 543 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
544 OCTAVE_API Sparse<T> |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
545 index (const octave::idx_vector& i, const octave::idx_vector& j, |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
546 bool resize_ok = false) const; |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
547 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
548 OCTAVE_API void assign (const octave::idx_vector& i, const Sparse<T>& rhs); |
5164 | 549 |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
550 OCTAVE_API void assign (const octave::idx_vector& i, const T& rhs); |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
551 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
552 OCTAVE_API void |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
553 assign (const octave::idx_vector& i, const octave::idx_vector& j, const Sparse<T>& rhs); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
554 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
555 OCTAVE_API void |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
556 assign (const octave::idx_vector& i, const octave::idx_vector& j, const T& rhs); |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
557 |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
558 OCTAVE_API void |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
559 print_info (std::ostream& os, const std::string& prefix) const; |
5164 | 560 |
5900 | 561 // Unsafe. These functions exist to support the MEX interface. |
562 // 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
|
563 void * mex_get_data (void) const { return const_cast<T *> (data ()); } |
5900 | 564 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
565 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
|
566 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
567 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
|
568 } |
5900 | 569 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
570 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
|
571 { |
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
572 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
|
573 } |
7433 | 574 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
575 OCTAVE_API Sparse<T> |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
576 sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
577 OCTAVE_API Sparse<T> |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
578 sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
579 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
|
580 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
581 OCTAVE_API Sparse<T> diag (octave_idx_type k = 0) const; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7602
diff
changeset
|
582 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10537
diff
changeset
|
583 // dim = -1 and dim = -2 are special; see Array<T>::cat description. |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
584 static OCTAVE_API Sparse<T> |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
585 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
|
586 |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
587 OCTAVE_API Array<T> array_value (void) const; |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
588 |
15212
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
589 // 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
|
590 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
|
591 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
|
592 { |
29937
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29927
diff
changeset
|
593 return octave::any_all_test<F, T, zero> (fcn, data (), nnz ()); |
15212
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
594 } |
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
595 |
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
596 // Simpler calls. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
597 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
|
598 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
|
599 { 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
|
600 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
601 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
|
602 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
|
603 { 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
|
604 |
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
605 // 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
|
606 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
|
607 { 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
|
608 |
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
609 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
|
610 { 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
|
611 |
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
612 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
|
613 { 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
|
614 |
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
615 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
|
616 { 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
|
617 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
618 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
|
619 Sparse<U> |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
620 map (F fcn) const |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
621 { |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
622 Sparse<U> result; |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23796
diff
changeset
|
623 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
|
624 |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23796
diff
changeset
|
625 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
|
626 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
627 octave_idx_type nr = rows (); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
628 octave_idx_type nc = cols (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
629 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
630 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
|
631 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
632 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
|
633 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
634 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
635 octave_quit (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
636 /* 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
|
637 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
|
638 } |
7602
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
639 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
640 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
|
641 } |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
642 else |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
643 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
644 octave_idx_type nz = nnz (); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
645 octave_idx_type nr = rows (); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
646 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
|
647 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
648 result = Sparse<U> (nr, nc, nz); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
649 octave_idx_type ii = 0; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
650 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
|
651 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
652 for (octave_idx_type j = 0; j < nc; j++) |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
653 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
654 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
|
655 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
656 U val = fcn (data (i)); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
657 if (val != 0.0) |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
658 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
659 result.data (ii) = val; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
660 result.ridx (ii++) = ridx (i); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
661 } |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
662 octave_quit (); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
663 } |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
664 result.cidx (j+1) = ii; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
665 } |
7602
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
666 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
667 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
|
668 } |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
669 |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
670 return result; |
7bfaa9611558
Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents:
7470
diff
changeset
|
671 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
672 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
673 // 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
|
674 template <typename U> |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
675 Sparse<U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
676 map (U (&fcn) (T)) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
677 { return map<U, U (&) (T)> (fcn); } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
678 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
679 template <typename U> |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
680 Sparse<U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
681 map (U (&fcn) (const T&)) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
682 { return map<U, U (&) (const T&)> (fcn); } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
683 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
684 bool indices_ok (void) const { return m_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
|
685 |
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
|
686 bool any_element_is_nan (void) const |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
687 { return m_rep->any_element_is_nan (); } |
5164 | 688 }; |
689 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
690 template <typename T> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28976
diff
changeset
|
691 OCTAVE_API |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
692 std::istream& |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
693 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
|
694 T (*read_fcn) (std::istream&)); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
695 |
5164 | 696 #endif |