Chris@49: // Copyright (C) 2012 Conrad Sanderson Chris@49: // Chris@49: // This Source Code Form is subject to the terms of the Mozilla Public Chris@49: // License, v. 2.0. If a copy of the MPL was not distributed with this Chris@49: // file, You can obtain one at http://mozilla.org/MPL/2.0/. Chris@49: Chris@49: Chris@49: //! \addtogroup fn_sprandu Chris@49: //! @{ Chris@49: Chris@49: Chris@49: Chris@49: //! Generate a sparse matrix with a randomly selected subset of the elements Chris@49: //! set to random values in the [0,1] interval (uniform distribution) Chris@49: template Chris@49: inline Chris@49: obj_type Chris@49: sprandu Chris@49: ( Chris@49: const uword n_rows, Chris@49: const uword n_cols, Chris@49: const double density, Chris@49: const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0 Chris@49: ) Chris@49: { Chris@49: arma_extra_debug_sigprint(); Chris@49: arma_ignore(junk); Chris@49: Chris@49: if(is_SpCol::value == true) Chris@49: { Chris@49: arma_debug_check( (n_cols != 1), "sprandu(): incompatible size" ); Chris@49: } Chris@49: else Chris@49: if(is_SpRow::value == true) Chris@49: { Chris@49: arma_debug_check( (n_rows != 1), "sprandu(): incompatible size" ); Chris@49: } Chris@49: Chris@49: obj_type out; Chris@49: Chris@49: out.sprandu(n_rows, n_cols, density); Chris@49: Chris@49: return out; Chris@49: } Chris@49: Chris@49: Chris@49: Chris@49: inline Chris@49: sp_mat Chris@49: sprandu(const uword n_rows, const uword n_cols, const double density) Chris@49: { Chris@49: arma_extra_debug_sigprint(); Chris@49: Chris@49: sp_mat out; Chris@49: Chris@49: out.sprandu(n_rows, n_cols, density); Chris@49: Chris@49: return out; Chris@49: } Chris@49: Chris@49: Chris@49: Chris@49: //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, Chris@49: //! with the non-zero values set to random values in the [0,1] interval (uniform distribution) Chris@49: template Chris@49: inline Chris@49: SpMat Chris@49: sprandu(const SpBase& X) Chris@49: { Chris@49: arma_extra_debug_sigprint(); Chris@49: Chris@49: typedef typename T1::elem_type eT; Chris@49: Chris@49: SpMat out( X.get_ref() ); Chris@49: Chris@49: eop_aux_randu::fill( access::rwp(out.values), out.n_nonzero ); Chris@49: Chris@49: return out; Chris@49: } Chris@49: Chris@49: Chris@49: Chris@49: //! @}