fn_ones.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_ones
00017 //! @{
00018 
00019 
00020 
00021 //! Delayed generation of a dense matrix with all elements set to one
00022 
00023 inline
00024 const Op<mat,op_ones_full>
00025 ones(const u32 n_rows, const u32 n_cols)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   return Op<mat,op_ones_full>(n_rows, n_cols, 'j');
00030   }
00031 
00032 
00033 
00034 template<typename mat_type>
00035 inline
00036 const Op<mat_type,op_ones_full>
00037 ones(const u32 n_rows, const u32 n_cols)
00038   {
00039   arma_extra_debug_sigprint();
00040   
00041   arma_type_check<is_Mat<mat_type>::value == false>::apply();
00042   
00043   return Op<mat_type,op_ones_full>(n_rows, n_cols, 'j');
00044   }
00045 
00046 
00047 
00048 //! Generate a vector with all elements set to one
00049 inline
00050 const Op<colvec, op_ones_full>
00051 ones(const u32 n_elem)
00052   {
00053   arma_extra_debug_sigprint();
00054   
00055   return Op<colvec, op_ones_full>(n_elem, 1, 'j');
00056   }
00057 
00058 
00059 
00060 template<typename vec_type>
00061 inline
00062 const Op<vec_type, op_ones_full>
00063 ones(const u32 n_elem)
00064   {
00065   arma_extra_debug_sigprint();
00066   
00067   arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>::value == false) >::apply();
00068 
00069   if(is_Row<vec_type>::value == true)
00070     {
00071     return Op<vec_type, op_ones_full>(1, n_elem, 'j');
00072     }
00073   else
00074     {
00075     return Op<vec_type, op_ones_full>(n_elem, 1, 'j');
00076     }
00077   }
00078 
00079 
00080 
00081 //! Delayed generation of a diagonal matrix with the diagonal elements set to one
00082 inline
00083 const Op<mat,op_ones_diag>
00084 eye(const u32 n_rows, const u32 n_cols)
00085   {
00086   arma_extra_debug_sigprint();
00087   
00088   return Op<mat,op_ones_diag>(n_rows, n_cols, 'j');
00089   }
00090 
00091 
00092 
00093 template<typename mat_type>
00094 inline
00095 const Op<mat_type,op_ones_diag>
00096 eye(const u32 n_rows, const u32 n_cols)
00097   {
00098   arma_extra_debug_sigprint();
00099   
00100   arma_type_check<is_Mat_only<mat_type>::value == false>::apply();
00101   
00102   return Op<mat_type,op_ones_diag>(n_rows, n_cols, 'j');
00103   }
00104 
00105 
00106 
00107 //
00108 //
00109 // handling of cubes
00110 
00111 
00112 
00113 
00114 //! Delayed generation of a dense cube with all elements set to one
00115 
00116 inline
00117 const OpCube<cube,op_ones_full>
00118 ones(const u32 n_rows, const u32 n_cols, const u32 n_slices)
00119   {
00120   arma_extra_debug_sigprint();
00121   
00122   return OpCube<cube,op_ones_full>(n_rows, n_cols, n_slices);
00123   }
00124 
00125 
00126 
00127 template<typename cube_type>
00128 inline
00129 const OpCube<cube_type,op_ones_full>
00130 ones(const u32 n_rows, const u32 n_cols, const u32 n_slices)
00131   {
00132   arma_extra_debug_sigprint();
00133   
00134   arma_type_check<is_Cube<cube_type>::value == false>::apply();
00135   
00136   return OpCube<cube_type,op_ones_full>(n_rows, n_cols, n_slices);
00137   }
00138 
00139 
00140 
00141 //! @}