comparison armadillo-3.900.4/include/armadillo_bits/SpMat_bones.hpp @ 49:1ec0e2823891

Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author Chris Cannam
date Thu, 13 Jun 2013 10:25:24 +0100
parents
children
comparison
equal deleted inserted replaced
48:69251e11a913 49:1ec0e2823891
1 // Copyright (C) 2011-2013 Ryan Curtin
2 // Copyright (C) 2012-2013 Conrad Sanderson
3 // Copyright (C) 2011 Matthew Amidon
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9 //! \addtogroup SpMat
10 //! @{
11
12 //! Sparse matrix class, with data stored in compressed sparse column (CSC) format
13
14 template<typename eT>
15 class SpMat : public SpBase< eT, SpMat<eT> >
16 {
17 public:
18
19 typedef eT elem_type; //!< the type of elements stored in the matrix
20 typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-complex, pod_type is the same as eT; otherwise, pod_type is the underlying type used by std::complex
21
22 static const bool is_row = false;
23 static const bool is_col = false;
24
25 const uword n_rows; //!< number of rows in the matrix (read-only)
26 const uword n_cols; //!< number of columns in the matrix (read-only)
27 const uword n_elem; //!< number of elements in the matrix (read-only)
28 const uword n_nonzero; //!< number of nonzero elements in the matrix (read-only)
29 const uword vec_state; //!< 0: matrix; 1: column vector; 2: row vector
30
31 // So that SpValProxy can call add_element() and delete_element().
32 friend class SpValProxy<SpMat<eT> >;
33 friend class SpSubview<eT>;
34
35 /**
36 * The memory used to store the values of the matrix.
37 * In accordance with the CSC format, this stores only the actual values.
38 * The correct locations of the values are assembled from the row indices
39 * and the column pointers.
40 */
41 const eT* const values;
42
43 /**
44 * The row indices of each value. row_indices[i] is the row of values[i].
45 * The length of this array is n_nonzero + 1; the final value ensures the
46 * integrity of iterators.
47 */
48 const uword* const row_indices;
49
50 /**
51 * The column pointers. This stores the index of the first item in column i.
52 * That is, values[col_ptrs[i]] is the first value in column i, and it is in
53 * row row_indices[col_ptrs[i]].
54 */
55 const uword* const col_ptrs;
56
57 inline SpMat(); //! Size will be 0x0 (empty).
58 inline ~SpMat();
59
60 inline SpMat(const uword in_rows, const uword in_cols);
61
62 inline SpMat(const char* text);
63 inline const SpMat& operator=(const char* text);
64 inline SpMat(const std::string& text);
65 inline const SpMat& operator=(const std::string& text);
66 inline SpMat(const SpMat<eT>& x);
67
68 template<typename T1, typename T2> inline SpMat(const Base<uword,T1>& locations, const Base<eT,T2>& values, const bool sort_locations = true);
69 template<typename T1, typename T2> inline SpMat(const Base<uword,T1>& locations, const Base<eT,T2>& values, const uword n_rows, const uword n_cols, const bool sort_locations = true);
70
71 inline const SpMat& operator=(const eT val); //! Sets size to 1x1.
72 inline const SpMat& operator*=(const eT val);
73 inline const SpMat& operator/=(const eT val);
74 // operator+=(val) and operator-=(val) are not defined as they don't make sense for sparse matrices
75
76 /**
77 * Operators on other sparse matrices. These work as though you would expect.
78 */
79 inline const SpMat& operator=(const SpMat& m);
80 inline const SpMat& operator+=(const SpMat& m);
81 inline const SpMat& operator-=(const SpMat& m);
82 inline const SpMat& operator*=(const SpMat& m);
83 inline const SpMat& operator%=(const SpMat& m);
84 inline const SpMat& operator/=(const SpMat& m);
85
86 /**
87 * Operators on other regular matrices. These work as though you would expect.
88 */
89 template<typename T1> inline explicit SpMat(const Base<eT, T1>& m);
90 template<typename T1> inline const SpMat& operator=(const Base<eT, T1>& m);
91 template<typename T1> inline const SpMat& operator*=(const Base<eT, T1>& m);
92 template<typename T1> inline const SpMat& operator/=(const Base<eT, T1>& m);
93 template<typename T1> inline const SpMat& operator%=(const Base<eT, T1>& m);
94
95
96 //! construction of complex matrix out of two non-complex matrices;
97 template<typename T1, typename T2>
98 inline explicit SpMat(const SpBase<pod_type, T1>& A, const SpBase<pod_type, T2>& B);
99
100 /**
101 * Operations on sparse subviews.
102 */
103 inline SpMat(const SpSubview<eT>& X);
104 inline const SpMat& operator=(const SpSubview<eT>& X);
105 inline const SpMat& operator+=(const SpSubview<eT>& X);
106 inline const SpMat& operator-=(const SpSubview<eT>& X);
107 inline const SpMat& operator*=(const SpSubview<eT>& X);
108 inline const SpMat& operator%=(const SpSubview<eT>& X);
109 inline const SpMat& operator/=(const SpSubview<eT>& X);
110
111 /**
112 * Operations on regular subviews.
113 */
114 inline SpMat(const subview<eT>& x);
115 inline const SpMat& operator=(const subview<eT>& x);
116 inline const SpMat& operator+=(const subview<eT>& x);
117 inline const SpMat& operator-=(const subview<eT>& x);
118 inline const SpMat& operator*=(const subview<eT>& x);
119 inline const SpMat& operator%=(const subview<eT>& x);
120 inline const SpMat& operator/=(const subview<eT>& x);
121
122
123 // delayed unary ops
124 template<typename T1, typename spop_type> inline SpMat(const SpOp<T1, spop_type>& X);
125 template<typename T1, typename spop_type> inline const SpMat& operator=(const SpOp<T1, spop_type>& X);
126 template<typename T1, typename spop_type> inline const SpMat& operator+=(const SpOp<T1, spop_type>& X);
127 template<typename T1, typename spop_type> inline const SpMat& operator-=(const SpOp<T1, spop_type>& X);
128 template<typename T1, typename spop_type> inline const SpMat& operator*=(const SpOp<T1, spop_type>& X);
129 template<typename T1, typename spop_type> inline const SpMat& operator%=(const SpOp<T1, spop_type>& X);
130 template<typename T1, typename spop_type> inline const SpMat& operator/=(const SpOp<T1, spop_type>& X);
131
132 // delayed binary ops
133 template<typename T1, typename T2, typename spglue_type> inline SpMat(const SpGlue<T1, T2, spglue_type>& X);
134 template<typename T1, typename T2, typename spglue_type> inline const SpMat& operator=(const SpGlue<T1, T2, spglue_type>& X);
135 template<typename T1, typename T2, typename spglue_type> inline const SpMat& operator+=(const SpGlue<T1, T2, spglue_type>& X);
136 template<typename T1, typename T2, typename spglue_type> inline const SpMat& operator-=(const SpGlue<T1, T2, spglue_type>& X);
137 template<typename T1, typename T2, typename spglue_type> inline const SpMat& operator*=(const SpGlue<T1, T2, spglue_type>& X);
138 template<typename T1, typename T2, typename spglue_type> inline const SpMat& operator%=(const SpGlue<T1, T2, spglue_type>& X);
139 template<typename T1, typename T2, typename spglue_type> inline const SpMat& operator/=(const SpGlue<T1, T2, spglue_type>& X);
140
141 // delayed mixted-type unary ops
142 template<typename T1, typename spop_type> inline SpMat(const mtSpOp<eT, T1, spop_type>& X);
143 template<typename T1, typename spop_type> inline const SpMat& operator=(const mtSpOp<eT, T1, spop_type>& X);
144 template<typename T1, typename spop_type> inline const SpMat& operator+=(const mtSpOp<eT, T1, spop_type>& X);
145 template<typename T1, typename spop_type> inline const SpMat& operator-=(const mtSpOp<eT, T1, spop_type>& X);
146 template<typename T1, typename spop_type> inline const SpMat& operator*=(const mtSpOp<eT, T1, spop_type>& X);
147 template<typename T1, typename spop_type> inline const SpMat& operator%=(const mtSpOp<eT, T1, spop_type>& X);
148 template<typename T1, typename spop_type> inline const SpMat& operator/=(const mtSpOp<eT, T1, spop_type>& X);
149
150 /**
151 * Submatrix methods.
152 */
153 arma_inline SpSubview<eT> row(const uword row_num);
154 arma_inline const SpSubview<eT> row(const uword row_num) const;
155
156 inline SpSubview<eT> operator()(const uword row_num, const span& col_span);
157 inline const SpSubview<eT> operator()(const uword row_num, const span& col_span) const;
158
159
160 arma_inline SpSubview<eT> col(const uword col_num);
161 arma_inline const SpSubview<eT> col(const uword col_num) const;
162
163 inline SpSubview<eT> operator()(const span& row_span, const uword col_num);
164 inline const SpSubview<eT> operator()(const span& row_span, const uword col_num) const;
165
166 /**
167 * Row- and column-related functions.
168 */
169 inline void swap_rows(const uword in_row1, const uword in_row2);
170 inline void swap_cols(const uword in_col1, const uword in_col2);
171
172 inline void shed_row(const uword row_num);
173 inline void shed_col(const uword col_num);
174
175 inline void shed_rows(const uword in_row1, const uword in_row2);
176 inline void shed_cols(const uword in_col1, const uword in_col2);
177
178 arma_inline SpSubview<eT> rows(const uword in_row1, const uword in_row2);
179 arma_inline const SpSubview<eT> rows(const uword in_row1, const uword in_row2) const;
180
181 arma_inline SpSubview<eT> cols(const uword in_col1, const uword in_col2);
182 arma_inline const SpSubview<eT> cols(const uword in_col1, const uword in_col2) const;
183
184 arma_inline SpSubview<eT> submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2);
185 arma_inline const SpSubview<eT> submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const;
186
187
188 inline SpSubview<eT> submat (const span& row_span, const span& col_span);
189 inline const SpSubview<eT> submat (const span& row_span, const span& col_span) const;
190
191 inline SpSubview<eT> operator()(const span& row_span, const span& col_span);
192 inline const SpSubview<eT> operator()(const span& row_span, const span& col_span) const;
193
194 /**
195 * Element access; access the i'th element (works identically to the Mat accessors).
196 * If there is nothing at element i, 0 is returned.
197 *
198 * @param i Element to access.
199 */
200 arma_inline arma_warn_unused SpValProxy<SpMat<eT> > operator[] (const uword i);
201 arma_inline arma_warn_unused eT operator[] (const uword i) const;
202 arma_inline arma_warn_unused SpValProxy<SpMat<eT> > at (const uword i);
203 arma_inline arma_warn_unused eT at (const uword i) const;
204 arma_inline arma_warn_unused SpValProxy<SpMat<eT> > operator() (const uword i);
205 arma_inline arma_warn_unused eT operator() (const uword i) const;
206
207 /**
208 * Element access; access the element at row in_row and column in_col.
209 * If there is nothing at that position, 0 is returned.
210 */
211 arma_inline arma_warn_unused SpValProxy<SpMat<eT> > at (const uword in_row, const uword in_col);
212 arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col) const;
213 arma_inline arma_warn_unused SpValProxy<SpMat<eT> > operator() (const uword in_row, const uword in_col);
214 arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col) const;
215
216
217 /**
218 * Information boolean checks on matrices.
219 */
220 arma_inline arma_warn_unused bool is_empty() const;
221 arma_inline arma_warn_unused bool is_vec() const;
222 arma_inline arma_warn_unused bool is_rowvec() const;
223 arma_inline arma_warn_unused bool is_colvec() const;
224 arma_inline arma_warn_unused bool is_square() const;
225 inline arma_warn_unused bool is_finite() const;
226
227 arma_inline arma_warn_unused bool in_range(const uword i) const;
228 arma_inline arma_warn_unused bool in_range(const span& x) const;
229
230 arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const;
231 arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const;
232 arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const;
233 arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const;
234
235 /**
236 * Printing the matrix.
237 *
238 * @param extra_text Text to prepend to output.
239 */
240 inline void impl_print(const std::string& extra_text) const;
241 inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const;
242
243 inline void impl_raw_print(const std::string& extra_text) const;
244 inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const;
245
246 inline void impl_print_dense(const std::string& extra_text) const;
247 inline void impl_print_dense(std::ostream& user_stream, const std::string& extra_text) const;
248
249 inline void impl_raw_print_dense(const std::string& extra_text) const;
250 inline void impl_raw_print_dense(std::ostream& user_stream, const std::string& extra_text) const;
251
252 //! Copy the size of another matrix.
253 template<typename eT2> inline void copy_size(const SpMat<eT2>& m);
254 template<typename eT2> inline void copy_size(const Mat<eT2>& m);
255
256 /**
257 * Resize the matrix to a given size. The matrix will be resized to be a column vector (i.e. in_elem columns, 1 row).
258 *
259 * @param in_elem Number of elements to allow.
260 */
261 inline void set_size(const uword in_elem);
262
263 /**
264 * Resize the matrix to a given size.
265 *
266 * @param in_rows Number of rows to allow.
267 * @param in_cols Number of columns to allow.
268 */
269 inline void set_size(const uword in_rows, const uword in_cols);
270
271 inline void reshape(const uword in_rows, const uword in_cols, const uword dim = 0);
272
273 inline const SpMat& zeros();
274 inline const SpMat& zeros(const uword in_elem);
275 inline const SpMat& zeros(const uword in_rows, const uword in_cols);
276
277 inline const SpMat& eye();
278 inline const SpMat& eye(const uword in_rows, const uword in_cols);
279
280 inline const SpMat& speye();
281 inline const SpMat& speye(const uword in_rows, const uword in_cols);
282
283 inline const SpMat& sprandu(const uword in_rows, const uword in_cols, const double density);
284 inline const SpMat& sprandn(const uword in_rows, const uword in_cols, const double density);
285
286 inline void reset();
287
288 /**
289 * Get the minimum or maximum of the matrix.
290 */
291 inline arma_warn_unused eT min() const;
292 inline eT min(uword& index_of_min_val) const;
293 inline eT min(uword& row_of_min_val, uword& col_of_min_val) const;
294
295 inline arma_warn_unused eT max() const;
296 inline eT max(uword& index_of_max_val) const;
297 inline eT max(uword& row_of_min_val, uword& col_of_min_val) const;
298
299
300 // saving and loading
301
302 inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
303 inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
304
305 inline bool load(const std::string name, const file_type type = arma_binary, const bool print_status = true);
306 inline bool load( std::istream& is, const file_type type = arma_binary, const bool print_status = true);
307
308 inline bool quiet_save(const std::string name, const file_type type = arma_binary) const;
309 inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const;
310
311 inline bool quiet_load(const std::string name, const file_type type = arma_binary);
312 inline bool quiet_load( std::istream& is, const file_type type = arma_binary);
313
314 // TODO: speed up loading of sparse matrices stored as text files (ie. raw_ascii and coord_ascii)
315 // TODO: implement auto_detect for sparse matrices
316 // TODO: modify docs to specify which formats are not applicable to sparse matrices
317
318
319 // These forward declarations are necessary.
320 class iterator_base;
321 class iterator;
322 class const_iterator;
323 class row_iterator;
324 class const_row_iterator;
325
326 // Iterator base provides basic operators but not how to compare or how to
327 // iterate.
328 class iterator_base
329 {
330 public:
331
332 inline iterator_base(const SpMat& in_M);
333 inline iterator_base(const SpMat& in_M, const uword col, const uword pos);
334
335 inline arma_hot eT operator*() const;
336
337 // Don't hold location internally; call "dummy" methods to get that information.
338 arma_inline uword row() const { return M.row_indices[internal_pos]; }
339 arma_inline uword col() const { return internal_col; }
340 arma_inline uword pos() const { return internal_pos; }
341
342 arma_aligned const SpMat& M;
343 arma_aligned uword internal_col;
344 arma_aligned uword internal_pos;
345
346 // So that we satisfy the STL iterator types.
347 typedef std::bidirectional_iterator_tag iterator_category;
348 typedef eT value_type;
349 typedef uword difference_type; // not certain on this one
350 typedef const eT* pointer;
351 typedef const eT& reference;
352 };
353
354 class const_iterator : public iterator_base
355 {
356 public:
357
358 inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // Assumes initial_pos is valid.
359 //! Once initialized, will be at the first nonzero value after the given position (using forward columnwise traversal).
360 inline const_iterator(const SpMat& in_M, uword in_row, uword in_col);
361 //! If you know the exact position of the iterator. in_row is a dummy argument.
362 inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uword in_pos);
363 inline const_iterator(const const_iterator& other);
364
365 inline arma_hot const_iterator& operator++();
366 inline arma_hot const_iterator operator++(int);
367
368 inline arma_hot const_iterator& operator--();
369 inline arma_hot const_iterator operator--(int);
370
371 inline arma_hot bool operator==(const const_iterator& rhs) const;
372 inline arma_hot bool operator!=(const const_iterator& rhs) const;
373
374 inline arma_hot bool operator==(const typename SpSubview<eT>::const_iterator& rhs) const;
375 inline arma_hot bool operator!=(const typename SpSubview<eT>::const_iterator& rhs) const;
376
377 inline arma_hot bool operator==(const const_row_iterator& rhs) const;
378 inline arma_hot bool operator!=(const const_row_iterator& rhs) const;
379
380 inline arma_hot bool operator==(const typename SpSubview<eT>::const_row_iterator& rhs) const;
381 inline arma_hot bool operator!=(const typename SpSubview<eT>::const_row_iterator& rhs) const;
382 };
383
384 /**
385 * So that we can iterate over nonzero values, we need an iterator
386 * implementation. This can't be as simple as Mat's, which is just a pointer
387 * to an eT. If a value is set to 0 using this iterator, the iterator is no
388 * longer valid!
389 */
390 class iterator : public const_iterator
391 {
392 public:
393
394 inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in_M, initial_pos) { }
395 inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterator(in_M, in_row, in_col) { }
396 inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos) : const_iterator(in_M, in_row, in_col, in_pos) { }
397 inline iterator(const const_iterator& other) : const_iterator(other) { }
398
399 inline arma_hot SpValProxy<SpMat<eT> > operator*();
400
401 // overloads needed for return type correctness
402 inline arma_hot iterator& operator++();
403 inline arma_hot iterator operator++(int);
404
405 inline arma_hot iterator& operator--();
406 inline arma_hot iterator operator--(int);
407
408 // This has a different value_type than iterator_base.
409 typedef SpValProxy<SpMat<eT> > value_type;
410 typedef const SpValProxy<SpMat<eT> >* pointer;
411 typedef const SpValProxy<SpMat<eT> >& reference;
412 };
413
414 class const_row_iterator : public iterator_base
415 {
416 public:
417
418 inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0);
419 //! Once initialized, will be at the first nonzero value after the given position (using forward row-wise traversal).
420 inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col);
421 inline const_row_iterator(const const_row_iterator& other);
422
423 inline arma_hot const_row_iterator& operator++();
424 inline arma_hot const_row_iterator operator++(int);
425
426 inline arma_hot const_row_iterator& operator--();
427 inline arma_hot const_row_iterator operator--(int);
428
429 uword internal_row; // Hold row internally because we use internal_pos differently.
430 uword actual_pos; // Actual position in matrix.
431
432 arma_inline eT operator*() const { return iterator_base::M.values[actual_pos]; }
433
434 arma_inline uword row() const { return internal_row; }
435
436 inline arma_hot bool operator==(const const_iterator& rhs) const;
437 inline arma_hot bool operator!=(const const_iterator& rhs) const;
438
439 inline arma_hot bool operator==(const typename SpSubview<eT>::const_iterator& rhs) const;
440 inline arma_hot bool operator!=(const typename SpSubview<eT>::const_iterator& rhs) const;
441
442 inline arma_hot bool operator==(const const_row_iterator& rhs) const;
443 inline arma_hot bool operator!=(const const_row_iterator& rhs) const;
444
445 inline arma_hot bool operator==(const typename SpSubview<eT>::const_row_iterator& rhs) const;
446 inline arma_hot bool operator!=(const typename SpSubview<eT>::const_row_iterator& rhs) const;
447 };
448
449 class row_iterator : public const_row_iterator
450 {
451 public:
452
453 inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_iterator(in_M, initial_pos) { }
454 //! Once initialized, will be at the first nonzero value after the given position (using forward row-wise traversal).
455 inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_row_iterator(in_M, in_row, in_col) { }
456 inline row_iterator(const row_iterator& other) : const_row_iterator(other) { }
457
458 inline arma_hot SpValProxy<SpMat<eT> > operator*();
459
460 // overloads required for return type correctness
461 inline arma_hot row_iterator& operator++();
462 inline arma_hot row_iterator operator++(int);
463
464 inline arma_hot row_iterator& operator--();
465 inline arma_hot row_iterator operator--(int);
466
467 // This has a different value_type than iterator_base.
468 typedef SpValProxy<SpMat<eT> > value_type;
469 typedef const SpValProxy<SpMat<eT> >* pointer;
470 typedef const SpValProxy<SpMat<eT> >& reference;
471 };
472
473 inline iterator begin();
474 inline const_iterator begin() const;
475
476 inline iterator end();
477 inline const_iterator end() const;
478
479 inline iterator begin_col(const uword col_num);
480 inline const_iterator begin_col(const uword col_num) const;
481
482 inline iterator end_col(const uword col_num);
483 inline const_iterator end_col(const uword col_num) const;
484
485 inline row_iterator begin_row(const uword row_num = 0);
486 inline const_row_iterator begin_row(const uword row_num = 0) const;
487
488 inline row_iterator end_row();
489 inline const_row_iterator end_row() const;
490
491 inline row_iterator end_row(const uword row_num);
492 inline const_row_iterator end_row(const uword row_num) const;
493
494 inline void clear();
495 inline bool empty() const;
496 inline uword size() const;
497
498 /**
499 * Resize memory. You are responsible for updating the column pointers and
500 * filling the new memory (if the new size is larger). If the new size is
501 * smaller, the first new_n_nonzero elements will be copied. n_nonzero is
502 * updated.
503 */
504 inline void mem_resize(const uword new_n_nonzero);
505
506 //! don't use this unless you're writing internal Armadillo code
507 inline void steal_mem(SpMat& X);
508
509 //! don't use this unless you're writing internal Armadillo code
510 template< typename T1, typename Functor> arma_hot inline void init_xform (const SpBase<eT, T1>& x, const Functor& func);
511 template<typename eT2, typename T1, typename Functor> arma_hot inline void init_xform_mt(const SpBase<eT2,T1>& x, const Functor& func);
512
513
514 protected:
515
516 /**
517 * Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty).
518 */
519 inline void init(uword in_rows, uword in_cols);
520
521 /**
522 * Initialize the matrix from text. Data is (of course) not preserved, and
523 * the size will be reset.
524 */
525 inline void init(const std::string& text);
526
527 /**
528 * Initialize from another matrix (copy).
529 */
530 inline void init(const SpMat& x);
531
532
533 private:
534
535 /**
536 * Return the given element.
537 */
538 inline arma_hot arma_warn_unused SpValProxy<SpMat<eT> > get_value(const uword i);
539 inline arma_hot arma_warn_unused eT get_value(const uword i) const;
540
541 inline arma_hot arma_warn_unused SpValProxy<SpMat<eT> > get_value(const uword in_row, const uword in_col);
542 inline arma_hot arma_warn_unused eT get_value(const uword in_row, const uword in_col) const;
543
544 /**
545 * Given the index representing which of the nonzero values this is, return
546 * its actual location, either in row/col or just the index.
547 */
548 arma_inline arma_hot arma_warn_unused uword get_position(const uword i) const;
549 arma_inline arma_hot void get_position(const uword i, uword& row_of_i, uword& col_of_i) const;
550
551 /**
552 * Add an element at the given position, and return a reference to it. The
553 * element will be set to 0 (unless otherwise specified). If the element
554 * already exists, its value will be overwritten.
555 *
556 * @param in_row Row of new element.
557 * @param in_col Column of new element.
558 * @param in_val Value to set new element to (default 0.0).
559 */
560 inline arma_hot arma_warn_unused eT& add_element(const uword in_row, const uword in_col, const eT in_val = 0.0);
561
562 /**
563 * Delete an element at the given position.
564 *
565 * @param in_row Row of element to be deleted.
566 * @param in_col Column of element to be deleted.
567 */
568 inline arma_hot void delete_element(const uword in_row, const uword in_col);
569
570
571 public:
572
573 #ifdef ARMA_EXTRA_SPMAT_PROTO
574 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPMAT_PROTO)
575 #endif
576 };
577
578
579
580 #define ARMA_HAS_SPMAT
581
582
583
584 //! @}