annotate liboctave/array/Sparse.h @ 33652:6e87ac495446 bytecode-interpreter tip

maint: merge default to bytecode-interpreter
author John W. Eaton <jwe@octave.org>
date Tue, 04 Jun 2024 18:05:04 -0400
parents 7f73e4805a1f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32590
diff changeset
3 // Copyright (C) 1998-2024 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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20232
diff changeset
26 #if ! defined (octave_Sparse_h)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27 #define octave_Sparse_h 1
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
30
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31 #include <cstddef>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
32
23408
0af9a1ae0912 maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents: 23401
diff changeset
33 #include <algorithm>
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
34 #include <iosfwd>
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23420
diff changeset
35 #include <string>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36
30429
e38202d3628d provide header file for forward declaration of Array<T> template
John W. Eaton <jwe@octave.org>
parents: 30394
diff changeset
37 #include "Array-fwd.h"
30433
c6cd2f582254 Provide header file for forward declaration of Sparse<T> template (bug #59820).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30429
diff changeset
38 #include "Sparse-fwd.h"
30508
6f07492c9c20 Provide header file with forward declarations of matrix types (bug #59820).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30433
diff changeset
39 #include "mx-fwd.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41 // Two dimensional sparse class. Handles the reference counting for
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
42 // all the derived classes.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
44 template <typename T, typename Alloc>
32628
ae4e19c0a2b1 maint: Place class name and class keyword on one line.
Rik <rik@octave.org>
parents: 32590
diff changeset
45 class OCTAVE_API Sparse
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 {
8181
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
47 public:
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
48
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8181
diff changeset
49 typedef T element_type;
8181
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
50
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
51 protected:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
52 //--------------------------------------------------------------------
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
53 // The real representation of all Sparse arrays.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
54 //--------------------------------------------------------------------
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
55
32590
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 31771
diff changeset
56 class SparseRep : public Alloc
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
57 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
58 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
59
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
60 typedef std::allocator_traits<Alloc> Alloc_traits;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
61
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
62 typedef typename Alloc_traits::template rebind_traits<T> T_Alloc_traits;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
63 typedef typename T_Alloc_traits::pointer T_pointer;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
64
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
65 typedef typename Alloc_traits::template rebind_traits<octave_idx_type> idx_type_Alloc_traits;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
66 typedef typename idx_type_Alloc_traits::pointer idx_type_pointer;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
67
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
68 T_pointer m_data;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
69 idx_type_pointer m_ridx;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
70 idx_type_pointer m_cidx;
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
71 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
72 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
73 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
74 octave::refcount<octave_idx_type> m_count;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
75
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
76 SparseRep ()
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
77 : Alloc (), m_data (T_allocate (1)), m_ridx (idx_type_allocate (1)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
78 m_cidx (idx_type_allocate (1)),
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
79 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
80 { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
81
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
82 SparseRep (octave_idx_type n)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
83 : Alloc (), m_data (T_allocate (1)), m_ridx (idx_type_allocate (1)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
84 m_cidx (idx_type_allocate (n+1)),
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
85 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
86 { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
87
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 26376
diff changeset
88 SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 1)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
89 : Alloc (), m_data (T_allocate (nz > 0 ? nz : 1)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
90 m_ridx (idx_type_allocate (nz > 0 ? nz : 1)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
91 m_cidx (idx_type_allocate (nc+1)),
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
92 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
93 { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
94
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
95 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
96 const T *d, const octave_idx_type *r, const octave_idx_type *c)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
97 : Alloc (), m_data (T_allocate (nz)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
98 m_ridx (idx_type_allocate (nz)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
99 m_cidx (idx_type_allocate (nc+1)),
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
100 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
101 {
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
102 std::copy_n (d, nz, m_data);
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
103 std::copy_n (r, nz, m_ridx);
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
104 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
105 }
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
106
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
107 template <typename U>
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
108 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
109 const U *d, const octave_idx_type *r, const octave_idx_type *c)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
110 : Alloc (), m_data (T_allocate (nz)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
111 m_ridx (idx_type_allocate (nz)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
112 m_cidx (idx_type_allocate (nc+1)),
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
113 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
114 {
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
115 std::copy_n (d, nz, m_data);
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
116 std::copy_n (r, nz, m_ridx);
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
117 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
118 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
119
30227
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
120 template <typename U>
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
121 SparseRep (const dim_vector& dv, octave_idx_type nz,
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
122 U *d, octave_idx_type *r, octave_idx_type *c,
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
123 const Alloc& xallocator = Alloc ())
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
124 : Alloc (xallocator), m_data (d), m_ridx (r), m_cidx (c),
30227
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
125 m_nzmax (nz), m_nrows (dv(0)), m_ncols (dv(1)), m_count (1)
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
126 { }
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
127
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
128 SparseRep (const SparseRep& a)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
129 : Alloc (), m_data (T_allocate (a.m_nzmax)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
130 m_ridx (idx_type_allocate (a.m_nzmax)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
131 m_cidx (idx_type_allocate (a.m_ncols + 1)),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
132 m_nzmax (a.m_nzmax), m_nrows (a.m_nrows), m_ncols (a.m_ncols),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
133 m_count (1)
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
134 {
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
135 octave_idx_type nz = a.nnz ();
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
136 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
137 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
138 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
139 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
140
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
141 ~SparseRep ()
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
142 {
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
143 T_deallocate (m_data, m_nzmax);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
144 idx_type_deallocate (m_ridx, m_nzmax);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
145 idx_type_deallocate (m_cidx, m_ncols + 1);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
146 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
147
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
148 octave_idx_type nzmax () const { return m_nzmax; }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
149 octave_idx_type nnz () const { return m_cidx[m_ncols]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
150
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
151 octave_idx_type rows () const { return m_nrows; }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
152 octave_idx_type cols () const { return m_ncols; }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
153 octave_idx_type columns () const { return m_ncols; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
154
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
155 OCTAVE_API T& elem (octave_idx_type r, octave_idx_type c);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
156
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
157 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
158
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
159 T& data (octave_idx_type i) { return m_data[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
160
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
161 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
162
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
163 octave_idx_type& ridx (octave_idx_type i) { return m_ridx[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
164
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
165 octave_idx_type cridx (octave_idx_type i) const { return m_ridx[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
166
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
167 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
168
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
169 octave_idx_type ccidx (octave_idx_type i) const { return m_cidx[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
170
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
171 OCTAVE_API void maybe_compress (bool remove_zeros);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
172
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
173 OCTAVE_API void change_length (octave_idx_type nz);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
174
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
175 OCTAVE_API bool indices_ok () const;
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
176
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
177 OCTAVE_API bool any_element_is_nan () 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
178
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
179 // Prefer nzmax.
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
180 octave_idx_type length () const { return m_nzmax; }
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
181
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
182 template <typename U, typename A> friend class Sparse;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
183
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
184 // No assignment!
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
185
29948
c92a4ebaa777 Remove OCTAVE_API from functions that are tagged with =delete or =default.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29937
diff changeset
186 SparseRep& operator = (const SparseRep&) = delete;
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
187
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
188 T_pointer T_allocate (size_t len)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
189 {
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
190 typename T_Alloc_traits::allocator_type& alloc = *this;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
191
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
192 T_pointer data = T_Alloc_traits::allocate (alloc, len);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
193 for (size_t i = 0; i < len; i++)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
194 T_Alloc_traits::construct (alloc, data+i);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
195
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
196 return data;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
197 }
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
198
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
199 void T_deallocate (T_pointer data, size_t len)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
200 {
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
201 typename T_Alloc_traits::allocator_type& alloc = *this;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
202
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
203 for (size_t i = 0; i < len; i++)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
204 T_Alloc_traits::destroy (alloc, data+i);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
205 T_Alloc_traits::deallocate (alloc, data, len);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
206 }
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
207
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
208 idx_type_pointer idx_type_allocate (size_t len)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
209 {
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
210 typename idx_type_Alloc_traits::allocator_type alloc = *this;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
211
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
212 idx_type_pointer idx = idx_type_Alloc_traits::allocate (alloc, len);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
213 for (size_t i = 0; i < len; i++)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
214 idx_type_Alloc_traits::construct (alloc, idx+i);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
215
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
216 return idx;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
217 }
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
218
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
219 void idx_type_deallocate (idx_type_pointer idx, size_t len)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
220 {
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
221 typename idx_type_Alloc_traits::allocator_type alloc = *this;
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
222
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
223 for (size_t i = 0; i < len; i++)
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
224 idx_type_Alloc_traits::destroy (alloc, idx+i);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
225 idx_type_Alloc_traits::deallocate (alloc, idx, len);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
226 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
227 };
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
228
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
229 //--------------------------------------------------------------------
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
230
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
231 void make_unique ()
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
232 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
233 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
234 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
235 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
236
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
237 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
238 delete m_rep;
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13030
diff changeset
239
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
240 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
241 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
242 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
243
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
244 protected:
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
245
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
246 typename Sparse<T, Alloc>::SparseRep *m_rep;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
247
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
248 dim_vector m_dimensions;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
249
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
250 private:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
251
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
252 static OCTAVE_API typename Sparse<T, Alloc>::SparseRep * nil_rep ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
253
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
254 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
255
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
256 Sparse ()
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30232
diff changeset
257 : 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
258 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
259 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
260 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
261
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
262 explicit Sparse (octave_idx_type n)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
263 : m_rep (new typename Sparse<T, Alloc>::SparseRep (n)),
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
264 m_dimensions (dim_vector (n, n)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
265
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
266 explicit Sparse (octave_idx_type nr, octave_idx_type nc)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
267 : m_rep (new typename Sparse<T, Alloc>::SparseRep (nr, nc)),
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
268 m_dimensions (dim_vector (nr, nc)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
269
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
270 explicit OCTAVE_API Sparse (octave_idx_type nr, octave_idx_type nc, T val);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
271
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
272 Sparse (const dim_vector& dv, octave_idx_type nz)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
273 : m_rep (new typename Sparse<T, Alloc>::SparseRep (dv(0), dv(1), nz)),
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
274 m_dimensions (dv) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
275
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
276 Sparse (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
277 : m_rep (new typename Sparse<T, Alloc>::SparseRep (nr, nc, nz)),
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
278 m_dimensions (dim_vector (nr, nc)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
279
30227
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
280 // Construct a Sparse array from pointers to externally allocated
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
281 // arrays of values and indices. PTR, RIDX, and CIDX must be
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
282 // allocated with operator new. The Sparse object takes ownership of
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
283 // these arrays and will delete them when the Sparse object is
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
284 // deleted. The dimension vector DV must be consistent with the sizes
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
285 // of the allocated PTR, CIDX, and RIDX arrays.
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
286
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
287 Sparse (const dim_vector& dv, octave_idx_type nz,
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
288 T *ptr, octave_idx_type *ridx, octave_idx_type *cidx,
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
289 const Alloc& xallocator = Alloc ())
32590
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 31771
diff changeset
290 : m_rep (new typename Sparse<T, Alloc>::SparseRep (dv, nz, ptr, ridx, cidx, xallocator)),
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 31771
diff changeset
291 m_dimensions (dv)
30227
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
292 { }
b00ff462e0f2 improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents: 29948
diff changeset
293
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
294 // 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
295 // 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
296 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
297
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
298 // 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
299 template <typename U>
10515
189274f6c7c4 omissions from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10514
diff changeset
300 Sparse (const Sparse<U>& a)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
301 : m_rep (new typename Sparse<T, Alloc>::SparseRep (a.rows (), a.cols (),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
302 a.nzmax (), a.data (),
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
303 a.ridx (), a.cidx ())),
29927
6a8642d310c8 style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents: 29897
diff changeset
304 m_dimensions (a.dims ()) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
305
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
306 // No type conversion case.
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
307 Sparse (const Sparse<T, Alloc>& a)
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
308 : 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
309 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
310 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
311 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
313 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
314
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
315 OCTAVE_API Sparse (const dim_vector& dv);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
316
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
317 OCTAVE_API Sparse (const Sparse<T, Alloc>& a, const dim_vector& dv);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
318
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
319 OCTAVE_API
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
320 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
321 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
322 bool sum_terms = true, octave_idx_type nzm = -1);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
323
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
324 // 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
325 OCTAVE_API Sparse (const Array<T>& a);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
326
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
327 virtual ~Sparse ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
328
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
329 OCTAVE_API Sparse<T, Alloc>& operator = (const Sparse<T, Alloc>& a);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
330
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
331 //! 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
332 //! This may differ from the actual number of elements, see nnz().
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
333 octave_idx_type nzmax () const { return m_rep->nzmax (); }
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
334
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
335 //! Actual number of nonzero terms.
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
336 octave_idx_type nnz () const { return m_rep->nnz (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
337
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
338 // 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
339 // so don't do it unless you really need it.
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
340 octave_idx_type numel () const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
341 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
342 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
343 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
344
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
345 octave_idx_type dim1 () const { return m_dimensions(0); }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
346 octave_idx_type dim2 () const { return m_dimensions(1); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
347
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
348 octave_idx_type rows () const { return dim1 (); }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
349 octave_idx_type cols () const { return dim2 (); }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
350 octave_idx_type columns () const { return dim2 (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
351
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
352 octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
353 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
354 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
355 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
356 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
357 ret++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
358 return ret;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
359 }
10358
72fab01e5d68 improve some size_t queries
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
360
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
361 std::size_t byte_size () const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
362 {
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
363 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
364 + 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
365 * (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
366 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
367
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
368 dim_vector dims () const { return m_dimensions; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
369
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
370 Sparse<T, Alloc> squeeze () const { return *this; }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
371
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
372 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
373 compute_index (const Array<octave_idx_type>& ra_idx) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
374
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
375 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
376 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
377 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
378 range_error (const char *fcn, octave_idx_type n);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
379
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
380 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
381 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
382 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
383 range_error (const char *fcn, octave_idx_type i, octave_idx_type j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
384
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
385 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
386 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
387 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
388 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
389
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
390 // No checking, even for multiple references, ever.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
391
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
392 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
393 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
394 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
395 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
396 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
397 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
398
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
399 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
400 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
401 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
402 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
403 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
404 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
405
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
406 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
407 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
408 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
409 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
410 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
411
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
412 T& 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
413 { return xelem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
414
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
415 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
416 { return xelem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
417
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
418 // 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
419 // copy, but that is not so easy, and I see no clean way to do it.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
420
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
421 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
422 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
423 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
424 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
425 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
426 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
427 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
428 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
429 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
430 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
431
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
432 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
433 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
434 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
435 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
436 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
437 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
438 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
439 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
440 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
441 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
442
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
443 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
444 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
445 octave_idx_type i = compute_index (ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
446
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
447 if (i < 0)
28976
4e1805033979 Sparse.h: remove return statements used with OCTAVE_NORETURN functions.
Rik <rik@octave.org>
parents: 27923
diff changeset
448 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
449 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
450 return elem (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
451 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
452
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
453 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
454 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
455 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
456 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
457 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
458
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
459 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
460 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
461 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
462 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
463 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
464
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
465 T& elem (const Array<octave_idx_type>& ra_idx)
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
466 { return Sparse<T, Alloc>::elem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
467
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
468 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
469 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
470 return elem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
471 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
472
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
473 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
474 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
475 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
476 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
477
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
478 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
479 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
480 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
481 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
482
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
483 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
484 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
485 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
486 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
487 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
488 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
489 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
490
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
491 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
492 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
493 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
494 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
495 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
496 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
497 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
498
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
499 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
500 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
501 octave_idx_type i = compute_index (ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
502
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
503 if (i < 0)
28976
4e1805033979 Sparse.h: remove return statements used with OCTAVE_NORETURN functions.
Rik <rik@octave.org>
parents: 27923
diff changeset
504 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
505 else
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
506 return Sparse<T, Alloc>::elem (i);
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
507 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
508
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
509 T elem (octave_idx_type n) const { return xelem (n); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
510
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
511 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
512
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
513 T elem (const Array<octave_idx_type>& ra_idx) const
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
514 { return Sparse<T, Alloc>::elem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
515
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23449
diff changeset
516 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
517
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
518 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
519 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
520 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
521 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
522
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
523 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
524 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
525 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
526 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
527
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
528 Sparse<T, Alloc> 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
529 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
530 if (remove_zeros)
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
531 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
532
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
533 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
534 return (*this);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
535 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
536
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
537 OCTAVE_API Sparse<T, Alloc> reshape (const dim_vector& new_dims) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
538
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
539 OCTAVE_API Sparse<T, Alloc>
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
540 permute (const Array<octave_idx_type>& vec, bool inv = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
541
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
542 Sparse<T, Alloc> 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
543 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
544 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
545 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
546
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
547 OCTAVE_API void resize1 (octave_idx_type n);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
548
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
549 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
550
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
551 OCTAVE_API void resize (const dim_vector& dv);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
552
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
553 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
554 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
555 if (nz < nnz ())
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
556 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
557 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
558 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
559
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
560 OCTAVE_API Sparse<T, Alloc>&
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
561 insert (const Sparse<T, Alloc>& a, octave_idx_type r, octave_idx_type c);
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
562 OCTAVE_API Sparse<T, Alloc>&
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
563 insert (const Sparse<T, Alloc>& a, const Array<octave_idx_type>& idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
564
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
565 bool issquare () const { return (dim1 () == dim2 ()); }
23593
a8361bc2361a maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents: 23577
diff changeset
566
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
567 bool isempty () const { return (rows () < 1 || cols () < 1); }
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23487
diff changeset
568
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
569 OCTAVE_API Sparse<T, Alloc> transpose () const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
570
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
571 T * data () { 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
572 T& data (octave_idx_type i) { make_unique (); return m_rep->data (i); }
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
573 T * xdata () { 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
574 T& xdata (octave_idx_type i) { return m_rep->data (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
575
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
576 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
577 // FIXME: shouldn't this be returning const T*?
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
578 T * data () const { return m_rep->m_data; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
579
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
580 octave_idx_type * ridx () { 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
581 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
582 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
583 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
584 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
585
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
586 octave_idx_type * xridx () { 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
587 octave_idx_type& xridx (octave_idx_type i) { return m_rep->ridx (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
588
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
589 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
590 // FIXME: shouldn't this be returning const octave_idx_type*?
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
591 octave_idx_type * ridx () const { return m_rep->m_ridx; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
592
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
593 octave_idx_type * cidx () { 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
594 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
595 {
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
596 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
597 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
598
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
599 octave_idx_type * xcidx () { 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
600 octave_idx_type& xcidx (octave_idx_type i) { return m_rep->cidx (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
601
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
602 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
603 // FIXME: shouldn't this be returning const octave_idx_type*?
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
604 octave_idx_type * cidx () const { return m_rep->m_cidx; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
605
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
606 octave_idx_type ndims () const { return m_dimensions.ndims (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
607
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
608 OCTAVE_API void delete_elements (const octave::idx_vector& i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
609
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
610 OCTAVE_API void delete_elements (int dim, const octave::idx_vector& i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
611
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
612 OCTAVE_API void delete_elements (const octave::idx_vector& i, const octave::idx_vector& j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
613
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
614 OCTAVE_API Sparse<T, Alloc>
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
615 index (const octave::idx_vector& i, bool resize_ok = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
616
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
617 OCTAVE_API Sparse<T, Alloc>
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
618 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
619 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
620
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
621 OCTAVE_API void assign (const octave::idx_vector& i,
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
622 const Sparse<T, Alloc>& rhs);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
623
29845
2ef9080ca017 allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
624 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
625
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
626 OCTAVE_API void
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
627 assign (const octave::idx_vector& i, const octave::idx_vector& j,
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
628 const Sparse<T, Alloc>& rhs);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
629
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
630 OCTAVE_API void
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
631 assign (const octave::idx_vector& i, const octave::idx_vector& j,
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
632 const T& rhs);
29845
2ef9080ca017 allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
633
2ef9080ca017 allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
634 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
635 print_info (std::ostream& os, const std::string& prefix) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
636
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
637 OCTAVE_API Sparse<T, Alloc>
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
638 sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
639 OCTAVE_API Sparse<T, Alloc>
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30232
diff changeset
640 sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
29227
a009cb8ef68f Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28976
diff changeset
641 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
642
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
643 OCTAVE_API Sparse<T, Alloc> 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
644
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10537
diff changeset
645 // dim = -1 and dim = -2 are special; see Array<T>::cat description.
30791
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
646 static OCTAVE_API Sparse<T, Alloc>
b1301358b040 allocators for Sparse<T>
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
647 cat (int dim, octave_idx_type n, const Sparse<T, Alloc> *sparse_list);
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
648
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
649 OCTAVE_API Array<T> array_value () const;
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
650
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
651 // 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
652 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
653 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
654 {
29937
da7210e30f3e move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29927
diff changeset
655 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
656 }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
657
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
658 // Simpler calls.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
659 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
660 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
661 { 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
662
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
663 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
664 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
665 { 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
666
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
667 // 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
668 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
669 { 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
670
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
671 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
672 { 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
673
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
674 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
675 { 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
676
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
677 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
678 { 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
679
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
680 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
681 Sparse<U>
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
682 map (F fcn) const
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
683 {
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
684 Sparse<U> result;
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
685 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
686
24010
584971932def Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents: 23796
diff changeset
687 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
688 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
689 octave_idx_type nr = rows ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
690 octave_idx_type nc = cols ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
691
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
692 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
693
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
694 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
695 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
696 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
697 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
698 /* 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
699 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
700 }
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
701
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
702 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
703 }
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
704 else
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
705 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
706 octave_idx_type nz = nnz ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
707 octave_idx_type nr = rows ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
708 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
709
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
710 result = Sparse<U> (nr, nc, nz);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
711 octave_idx_type ii = 0;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
712 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
713
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
714 for (octave_idx_type j = 0; j < nc; j++)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
715 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
716 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
717 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
718 U val = fcn (data (i));
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
719 if (val != 0.0)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
720 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
721 result.data (ii) = val;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
722 result.ridx (ii++) = ridx (i);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
723 }
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
724 octave_quit ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
725 }
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
726 result.cidx (j+1) = ii;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
727 }
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
728
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
729 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
730 }
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
731
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
732 return result;
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
733 }
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
734
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
735 // 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
736 template <typename U>
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
737 Sparse<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
738 map (U (&fcn) (T)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
739 { return map<U, U (&) (T)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
740
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
741 template <typename U>
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
742 Sparse<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
743 map (U (&fcn) (const T&)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
744 { return map<U, U (&) (const T&)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
745
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
746 bool indices_ok () 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
747
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
748 bool any_element_is_nan () const
29887
be669d935fb6 use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents: 29845
diff changeset
749 { return m_rep->any_element_is_nan (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
750 };
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
751
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
752 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
753 OCTAVE_API
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
754 std::istream&
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
755 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
756 T (*read_fcn) (std::istream&));
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
757
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
758 #endif