fn_ones.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_ones
00018 //! @{
00019 
00020 
00021 
00022 //! Delayed generation of a dense matrix with all elements set to one
00023 arma_inline
00024 const eOp<mat, eop_ones_full>
00025 ones(const u32 n_rows, const u32 n_cols)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   return eOp<mat, eop_ones_full>(n_rows, n_cols);
00030   }
00031 
00032 
00033 
00034 arma_inline
00035 const eOpCube<cube, eop_cube_ones_full>
00036 ones(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_ones_full>(n_rows, n_cols, n_slices);
00041   }
00042 
00043 
00044 
00045 template<typename mat_type>
00046 arma_inline
00047 const eOp<mat_type, eop_ones_full>
00048 ones(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_ones_full>(n_rows, n_cols);
00055   }
00056 
00057 
00058 
00059 template<typename cube_type>
00060 arma_inline
00061 const eOpCube<cube_type, eop_cube_ones_full>
00062 ones(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_ones_full>(n_rows, n_cols, n_slices);
00069   }
00070 
00071 
00072 
00073 //! Generate a vector with all elements set to one
00074 arma_inline
00075 const eOp<colvec, eop_ones_full>
00076 ones(const u32 n_elem)
00077   {
00078   arma_extra_debug_sigprint();
00079   
00080   return eOp<colvec, eop_ones_full>(n_elem, 1);
00081   }
00082 
00083 
00084 
00085 template<typename vec_type>
00086 arma_inline
00087 const eOp<vec_type, eop_ones_full>
00088 ones(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_ones_full>(1, n_elem);
00097     }
00098   else
00099     {
00100     return eOp<vec_type, eop_ones_full>(n_elem, 1);
00101     }
00102   }
00103 
00104 
00105 
00106 //! Delayed generation of a diagonal matrix with the diagonal elements set to one
00107 arma_inline
00108 const eOp<mat, eop_ones_diag>
00109 eye(const u32 n_rows, const u32 n_cols)
00110   {
00111   arma_extra_debug_sigprint();
00112   
00113   return eOp<mat, eop_ones_diag>(n_rows, n_cols);
00114   }
00115 
00116 
00117 
00118 template<typename mat_type>
00119 arma_inline
00120 const eOp<mat_type, eop_ones_diag>
00121 eye(const u32 n_rows, const u32 n_cols)
00122   {
00123   arma_extra_debug_sigprint();
00124   
00125   arma_type_check<is_Mat_only<mat_type>::value == false>::apply();
00126   
00127   return eOp<mat_type, eop_ones_diag>(n_rows, n_cols);
00128   }
00129 
00130 
00131 
00132 //! @}