fn_rand.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup fn_rand
00017 //! @{
00018 
00019 
00020 
00021 //! \brief
00022 //! Generate a dense matrix with all elements set to random values in the [0,1] interval (uniform distribution)
00023 
00024 inline
00025 const Op<mat, op_rand>
00026 rand(const u32 n_rows, const u32 n_cols)
00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   return Op<mat, op_rand>(n_rows, n_cols, 'j');
00031   }
00032 
00033 
00034 
00035 template<typename mat_type>
00036 inline
00037 const Op<mat_type,op_rand>
00038 rand(const u32 n_rows, const u32 n_cols)
00039   {
00040   arma_extra_debug_sigprint();
00041   
00042   arma_type_check<is_Mat<mat_type>::value == false>::apply();
00043   
00044   return Op<mat_type,op_rand>(n_rows, n_cols, 'j');
00045   }
00046 
00047 
00048 
00049 //! Generate a vector with all elements set to random values in the [0,1] interval (uniform distribution)
00050 inline
00051 const Op<colvec, op_rand>
00052 rand(const u32 n_elem)
00053   {
00054   arma_extra_debug_sigprint();
00055   
00056   return Op<colvec, op_rand>(n_elem, 1, 'j');
00057   }
00058 
00059 
00060 
00061 template<typename vec_type>
00062 inline
00063 const Op<vec_type,op_rand>
00064 rand(const u32 n_elem)
00065   {
00066   arma_extra_debug_sigprint();
00067   
00068   arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>::value == false) >::apply();
00069   
00070   if(is_Row<vec_type>::value == true)
00071     {
00072     return Op<vec_type,op_rand>(1, n_elem, 'j');
00073     }
00074   else
00075     {
00076     return Op<vec_type,op_rand>(n_elem, 1, 'j');
00077     }
00078   }
00079 
00080 
00081 
00082 //
00083 //
00084 // handling of cubes
00085 
00086 
00087 
00088 //! Generate a dense cube with all elements set to random values in the [0,1] interval (uniform distribution)
00089 inline
00090 const OpCube<cube, op_rand>
00091 rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
00092   {
00093   arma_extra_debug_sigprint();
00094   
00095   return OpCube<cube, op_rand>(n_rows, n_cols, n_slices);
00096   }
00097 
00098 
00099 
00100 template<typename cube_type>
00101 inline
00102 const OpCube<cube_type,op_rand>
00103 rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
00104   {
00105   arma_extra_debug_sigprint();
00106   
00107   arma_type_check<is_Cube<cube_type>::value == false>::apply();
00108   
00109   return OpCube<cube_type,op_rand>(n_rows, n_cols, n_slices);
00110   }
00111 
00112 
00113 
00114 //! @}