1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
// SPDX-License-Identifier: Apache-2.0
//
// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
// Copyright 2008-2016 National ICT Australia (NICTA)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
//! \addtogroup MapMat
//! @{
// this class is for internal use only; subject to change and/or removal without notice
template<typename eT>
class MapMat
{
public:
typedef eT elem_type; //!< the type of elements stored in the matrix
typedef typename get_pod_type<eT>::result pod_type; //!< if eT is std::complex<T>, pod_type is T; otherwise pod_type is eT
static constexpr bool is_row = false;
static constexpr bool is_col = false;
static constexpr bool is_xvec = false;
const uword n_rows; //!< number of rows (read-only)
const uword n_cols; //!< number of columns (read-only)
const uword n_elem; //!< number of elements (read-only)
private:
typedef typename std::map<uword, eT> map_type;
arma_aligned map_type* map_ptr;
public:
inline ~MapMat();
inline MapMat();
inline explicit MapMat(const uword in_n_rows, const uword in_n_cols);
inline explicit MapMat(const SizeMat& s);
inline MapMat(const MapMat<eT>& x);
inline void operator=(const MapMat<eT>& x);
inline explicit MapMat(const SpMat<eT>& x);
inline void operator=(const SpMat<eT>& x);
inline MapMat(MapMat<eT>&& x);
inline void operator=(MapMat<eT>&& x);
inline void reset();
inline void set_size(const uword in_n_rows);
inline void set_size(const uword in_n_rows, const uword in_n_cols);
inline void set_size(const SizeMat& s);
inline void zeros();
inline void zeros(const uword in_n_rows);
inline void zeros(const uword in_n_rows, const uword in_n_cols);
inline void zeros(const SizeMat& s);
inline void eye();
inline void eye(const uword in_n_rows, const uword in_n_cols);
inline void eye(const SizeMat& s);
inline void speye();
inline void speye(const uword in_n_rows, const uword in_n_cols);
inline void speye(const SizeMat& s);
arma_warn_unused arma_inline MapMat_val<eT> operator[](const uword index);
arma_warn_unused inline eT operator[](const uword index) const;
arma_warn_unused arma_inline MapMat_val<eT> operator()(const uword index);
arma_warn_unused inline eT operator()(const uword index) const;
arma_warn_unused arma_inline MapMat_val<eT> at(const uword in_row, const uword in_col);
arma_warn_unused inline eT at(const uword in_row, const uword in_col) const;
arma_warn_unused arma_inline MapMat_val<eT> operator()(const uword in_row, const uword in_col);
arma_warn_unused inline eT operator()(const uword in_row, const uword in_col) const;
arma_warn_unused inline bool is_empty() const;
arma_warn_unused inline bool is_vec() const;
arma_warn_unused inline bool is_rowvec() const;
arma_warn_unused inline bool is_colvec() const;
arma_warn_unused inline bool is_square() const;
inline void sprandu(const uword in_n_rows, const uword in_n_cols, const double density);
inline void print(const std::string& extra_text) const;
inline uword get_n_nonzero() const;
inline void get_locval_format(umat& locs, Col<eT>& vals) const;
private:
inline void init_cold();
inline void init_warm(const uword in_n_rows, const uword in_n_cols);
arma_inline void set_val(const uword index, const eT& in_val);
inline void erase_val(const uword index);
friend class SpMat<eT>;
friend class MapMat_val<eT>;
friend class SpMat_MapMat_val<eT>;
friend class SpSubview_MapMat_val<eT>;
};
template<typename eT>
class MapMat_val
{
private:
arma_aligned MapMat<eT>& parent;
arma_aligned const uword index;
inline MapMat_val(MapMat<eT>& in_parent, const uword in_index);
friend class MapMat<eT>;
public:
arma_inline operator eT() const;
arma_inline typename get_pod_type<eT>::result real() const;
arma_inline typename get_pod_type<eT>::result imag() const;
arma_inline void operator= (const MapMat_val<eT>& x);
arma_inline void operator= (const eT in_val);
arma_inline void operator+=(const eT in_val);
arma_inline void operator-=(const eT in_val);
arma_inline void operator*=(const eT in_val);
arma_inline void operator/=(const eT in_val);
arma_inline void operator++();
arma_inline void operator++(int);
arma_inline void operator--();
arma_inline void operator--(int);
};
template<typename eT>
class SpMat_MapMat_val
{
private:
arma_aligned SpMat<eT>& s_parent;
arma_aligned MapMat<eT>& m_parent;
arma_aligned const uword row;
arma_aligned const uword col;
inline SpMat_MapMat_val(SpMat<eT>& in_s_parent, MapMat<eT>& in_m_parent, const uword in_row, const uword in_col);
friend class SpMat<eT>;
friend class MapMat<eT>;
friend class SpSubview_MapMat_val<eT>;
public:
inline operator eT() const;
inline typename get_pod_type<eT>::result real() const;
inline typename get_pod_type<eT>::result imag() const;
inline SpMat_MapMat_val<eT>& operator= (const SpMat_MapMat_val<eT>& x);
inline SpMat_MapMat_val<eT>& operator= (const eT in_val);
inline SpMat_MapMat_val<eT>& operator+=(const eT in_val);
inline SpMat_MapMat_val<eT>& operator-=(const eT in_val);
inline SpMat_MapMat_val<eT>& operator*=(const eT in_val);
inline SpMat_MapMat_val<eT>& operator/=(const eT in_val);
inline SpMat_MapMat_val<eT>& operator++();
arma_warn_unused inline eT operator++(int);
inline SpMat_MapMat_val<eT>& operator--();
arma_warn_unused inline eT operator--(int);
inline void set(const eT in_val);
inline void add(const eT in_val);
inline void sub(const eT in_val);
inline void mul(const eT in_val);
inline void div(const eT in_val);
};
template<typename eT>
class SpSubview_MapMat_val : public SpMat_MapMat_val<eT>
{
private:
arma_inline SpSubview_MapMat_val(SpSubview<eT>& in_sv_parent, MapMat<eT>& in_m_parent, const uword in_row, const uword in_col);
arma_aligned SpSubview<eT>& sv_parent;
friend class SpMat<eT>;
friend class MapMat<eT>;
friend class SpSubview<eT>;
friend class SpMat_MapMat_val<eT>;
public:
inline SpSubview_MapMat_val<eT>& operator= (const SpSubview_MapMat_val<eT>& x);
inline SpSubview_MapMat_val<eT>& operator= (const eT in_val);
inline SpSubview_MapMat_val<eT>& operator+=(const eT in_val);
inline SpSubview_MapMat_val<eT>& operator-=(const eT in_val);
inline SpSubview_MapMat_val<eT>& operator*=(const eT in_val);
inline SpSubview_MapMat_val<eT>& operator/=(const eT in_val);
inline SpSubview_MapMat_val<eT>& operator++();
arma_warn_unused inline eT operator++(int);
inline SpSubview_MapMat_val<eT>& operator--();
arma_warn_unused inline eT operator--(int);
};
//! @}
|