fn_rand.hpp

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