Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-3.900.4/include/armadillo_bits/fn_sprandu.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) 2012 Conrad Sanderson | |
2 // | |
3 // This Source Code Form is subject to the terms of the Mozilla Public | |
4 // License, v. 2.0. If a copy of the MPL was not distributed with this | |
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
6 | |
7 | |
8 //! \addtogroup fn_sprandu | |
9 //! @{ | |
10 | |
11 | |
12 | |
13 //! Generate a sparse matrix with a randomly selected subset of the elements | |
14 //! set to random values in the [0,1] interval (uniform distribution) | |
15 template<typename obj_type> | |
16 inline | |
17 obj_type | |
18 sprandu | |
19 ( | |
20 const uword n_rows, | |
21 const uword n_cols, | |
22 const double density, | |
23 const typename arma_SpMat_SpCol_SpRow_only<obj_type>::result* junk = 0 | |
24 ) | |
25 { | |
26 arma_extra_debug_sigprint(); | |
27 arma_ignore(junk); | |
28 | |
29 if(is_SpCol<obj_type>::value == true) | |
30 { | |
31 arma_debug_check( (n_cols != 1), "sprandu(): incompatible size" ); | |
32 } | |
33 else | |
34 if(is_SpRow<obj_type>::value == true) | |
35 { | |
36 arma_debug_check( (n_rows != 1), "sprandu(): incompatible size" ); | |
37 } | |
38 | |
39 obj_type out; | |
40 | |
41 out.sprandu(n_rows, n_cols, density); | |
42 | |
43 return out; | |
44 } | |
45 | |
46 | |
47 | |
48 inline | |
49 sp_mat | |
50 sprandu(const uword n_rows, const uword n_cols, const double density) | |
51 { | |
52 arma_extra_debug_sigprint(); | |
53 | |
54 sp_mat out; | |
55 | |
56 out.sprandu(n_rows, n_cols, density); | |
57 | |
58 return out; | |
59 } | |
60 | |
61 | |
62 | |
63 //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, | |
64 //! with the non-zero values set to random values in the [0,1] interval (uniform distribution) | |
65 template<typename T1> | |
66 inline | |
67 SpMat<typename T1::elem_type> | |
68 sprandu(const SpBase<typename T1::elem_type, T1>& X) | |
69 { | |
70 arma_extra_debug_sigprint(); | |
71 | |
72 typedef typename T1::elem_type eT; | |
73 | |
74 SpMat<eT> out( X.get_ref() ); | |
75 | |
76 eop_aux_randu<eT>::fill( access::rwp(out.values), out.n_nonzero ); | |
77 | |
78 return out; | |
79 } | |
80 | |
81 | |
82 | |
83 //! @} |