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   return Op<vec_type, op_ones_full>(n_elem, 0, 'j');
00070   }
00071 
00072 
00073 
00074 //! Delayed generation of a diagonal matrix with the diagonal elements set to one
00075 inline
00076 const Op<mat,op_ones_diag>
00077 eye(const u32 n_rows, const u32 n_cols)
00078   {
00079   arma_extra_debug_sigprint();
00080   
00081   return Op<mat,op_ones_diag>(n_rows, n_cols, 'j');
00082   }
00083 
00084 
00085 
00086 template<typename mat_type>
00087 inline
00088 const Op<mat_type,op_ones_diag>
00089 eye(const u32 n_rows, const u32 n_cols)
00090   {
00091   arma_extra_debug_sigprint();
00092   
00093   arma_type_check<is_Mat_only<mat_type>::value == false>::apply();
00094   
00095   return Op<mat_type,op_ones_diag>(n_rows, n_cols, 'j');
00096   }
00097 
00098 
00099 //! @}