source: mmcs/armadillo_bits/fn_sprandn.hpp @ 8daa049

matrices
Last change on this file since 8daa049 was 9dd61b1, checked in by rboet <rboet@…>, 9 years ago

Avance del proyecto 60%

  • Property mode set to 100644
File size: 1.8 KB
Line 
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_sprandn
9//! @{
10
11
12
13//! Generate a sparse matrix with a randomly selected subset of the elements
14//! set to random values from a Gaussian distribution with zero mean and unit variance
15template<typename obj_type>
16inline
17obj_type
18sprandn
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), "sprandn(): incompatible size" );
32    }
33  else
34  if(is_SpRow<obj_type>::value == true)
35    {
36    arma_debug_check( (n_rows != 1), "sprandn(): incompatible size" );
37    }
38 
39  obj_type out;
40 
41  out.sprandn(n_rows, n_cols, density);
42 
43  return out;
44  }
45
46
47
48inline
49sp_mat
50sprandn(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.sprandn(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 from a Gaussian distribution with zero mean and unit variance
65template<typename T1>
66inline
67SpMat<typename T1::elem_type>
68sprandn(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  arma_rng::randn<eT>::fill( access::rwp(out.values), out.n_nonzero );
77 
78  return out;
79  }
80
81
82
83//! @}
Note: See TracBrowser for help on using the repository browser.