fn_randu.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_randu
00018 //! @{
00019 
00020 
00021 inline
00022 double
00023 randu()
00024   {
00025   return double(eop_aux_randu<double>());
00026   }
00027 
00028 
00029 template<typename eT>
00030 inline
00031 typename arma_scalar_only<eT>::result
00032 randu()
00033   {
00034   return eT(eop_aux_randu<eT>());
00035   }
00036 
00037 
00038 
00039 //! Generate a vector with all elements set to random values in the [0,1] interval (uniform distribution)
00040 arma_inline
00041 const eOp<colvec, eop_randu>
00042 randu(const u32 n_elem, const arma_Mat_Col_Row_only<colvec>::result* junk = 0)
00043   {
00044   arma_extra_debug_sigprint();
00045   
00046   return eOp<colvec, eop_randu>(n_elem, 1);
00047   }
00048 
00049 
00050 
00051 template<typename vec_type>
00052 arma_inline
00053 const eOp<vec_type, eop_randu>
00054 randu(const u32 n_elem, const typename arma_Mat_Col_Row_only<vec_type>::result* junk = 0)
00055   {
00056   arma_extra_debug_sigprint();
00057   
00058   if(is_Row<vec_type>::value == true)
00059     {
00060     return eOp<vec_type, eop_randu>(1, n_elem);
00061     }
00062   else
00063     {
00064     return eOp<vec_type, eop_randu>(n_elem, 1);
00065     }
00066   }
00067 
00068 
00069 
00070 //! Generate a dense matrix with all elements set to random values in the [0,1] interval (uniform distribution)
00071 arma_inline
00072 const eOp<mat, eop_randu>
00073 randu(const u32 n_rows, const u32 n_cols, const arma_Mat_Col_Row_only<mat>::result* junk = 0)
00074   {
00075   arma_extra_debug_sigprint();
00076   
00077   return eOp<mat, eop_randu>(n_rows, n_cols);
00078   }
00079 
00080 
00081 
00082 template<typename mat_type>
00083 arma_inline
00084 const eOp<mat_type, eop_randu>
00085 randu(const u32 n_rows, const u32 n_cols, const typename arma_Mat_Col_Row_only<mat_type>::result* junk = 0)
00086   {
00087   arma_extra_debug_sigprint();
00088   
00089   return eOp<mat_type, eop_randu>(n_rows, n_cols);
00090   }
00091 
00092 
00093 
00094 arma_inline
00095 const eOpCube<cube, eop_cube_randu>
00096 randu(const u32 n_rows, const u32 n_cols, const u32 n_slices, const arma_Cube_only<cube>::result* junk = 0)
00097   {
00098   arma_extra_debug_sigprint();
00099   
00100   return eOpCube<cube, eop_cube_randu>(n_rows, n_cols, n_slices);
00101   }
00102 
00103 
00104 
00105 template<typename cube_type>
00106 arma_inline
00107 const eOpCube<cube_type, eop_cube_randu>
00108 randu(const u32 n_rows, const u32 n_cols, const u32 n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
00109   {
00110   arma_extra_debug_sigprint();
00111   
00112   return eOpCube<cube_type, eop_cube_randu>(n_rows, n_cols, n_slices);
00113   }
00114 
00115 
00116 
00117 //
00118 // old functions, kept for compatibility with old user code
00119 
00120 
00121 //! Generate a dense matrix with all elements set to random values in the [0,1] interval (uniform distribution)
00122 inline
00123 arma_deprecated
00124 const eOp<mat, eop_randu>
00125 rand(const u32 n_rows, const u32 n_cols)
00126   {
00127   arma_extra_debug_sigprint();
00128   
00129   arma_print("rand() is deprecated; please use randu() instead");
00130   
00131   return eOp<mat, eop_randu>(n_rows, n_cols);
00132   }
00133 
00134 
00135 
00136 inline
00137 arma_deprecated
00138 const eOpCube<cube, eop_cube_randu>
00139 rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
00140   {
00141   arma_extra_debug_sigprint();
00142   
00143   arma_print("rand() is deprecated; please use randu() instead");
00144   
00145   return eOpCube<cube, eop_cube_randu>(n_rows, n_cols, n_slices);
00146   }
00147 
00148 
00149 
00150 template<typename mat_type>
00151 inline
00152 arma_deprecated
00153 const eOp<mat_type, eop_randu>
00154 rand(const u32 n_rows, const u32 n_cols)
00155   {
00156   arma_extra_debug_sigprint();
00157   
00158   arma_type_check<is_Mat<mat_type>::value == false>::apply();
00159   
00160   arma_print("rand() is deprecated; please use randu() instead");
00161   
00162   return eOp<mat_type, eop_randu>(n_rows, n_cols);
00163   }
00164 
00165 
00166 
00167 template<typename cube_type>
00168 inline
00169 arma_deprecated
00170 const eOpCube<cube_type, eop_cube_randu>
00171 rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
00172   {
00173   arma_extra_debug_sigprint();
00174   
00175   arma_type_check<is_Cube<cube_type>::value == false>::apply();
00176   
00177   arma_print("rand() is deprecated; please use randu() instead");
00178   
00179   return eOpCube<cube_type, eop_cube_randu>(n_rows, n_cols, n_slices);
00180   }
00181 
00182 
00183 
00184 //! Generate a vector with all elements set to random values in the [0,1] interval (uniform distribution)
00185 inline
00186 arma_deprecated
00187 const eOp<colvec, eop_randu>
00188 rand(const u32 n_elem)
00189   {
00190   arma_extra_debug_sigprint();
00191   
00192   arma_print("rand() is deprecated; please use randu() instead");
00193   
00194   return eOp<colvec, eop_randu>(n_elem, 1);
00195   }
00196 
00197 
00198 
00199 template<typename vec_type>
00200 inline
00201 arma_deprecated
00202 const eOp<vec_type, eop_randu>
00203 rand(const u32 n_elem)
00204   {
00205   arma_extra_debug_sigprint();
00206   
00207   arma_print("rand() is deprecated; please use randu() instead");
00208   
00209   arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>::value == false) >::apply();
00210   
00211   if(is_Row<vec_type>::value == true)
00212     {
00213     return eOp<vec_type, eop_randu>(1, n_elem);
00214     }
00215   else
00216     {
00217     return eOp<vec_type, eop_randu>(n_elem, 1);
00218     }
00219   }
00220 
00221 
00222 
00223 //! @}