diff --git a/include/armadillo_bits/fn_conv_to.hpp b/include/armadillo_bits/fn_conv_to.hpp index 801b2032..ed56c7d6 100644 --- a/include/armadillo_bits/fn_conv_to.hpp +++ b/include/armadillo_bits/fn_conv_to.hpp @@ -198,6 +198,20 @@ struct conv_to_helper_Mat_same_type return Mat(in.get_ref()); } + + inline + static + Mat + apply(const std::vector& in) + { + arma_debug_sigprint(); + + const uword N = uword( in.size() ); + + const in_eT* in_memptr = (N > 0) ? &(in[0]) : nullptr; + + return Mat(in_memptr, N, 1); + } }; @@ -220,6 +234,22 @@ struct conv_to_helper_Mat_diff_type arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); + return out; + } + + inline + static + Mat + apply(const std::vector& in) + { + arma_debug_sigprint(); + + const uword N = uword( in.size() ); + + Mat out(N, 1, arma_nozeros_indicator()); + + if(N > 0) { arrayops::convert( out.memptr(), &(in[0]), N ); } + return out; } }; @@ -344,16 +374,9 @@ conv_to< Mat >::from(const std::vector& in, const typename arma_n arma_debug_sigprint(); arma_ignore(junk); - const uword N = uword( in.size() ); + typedef typename conv_to_helper_Mat_redirect::value>::result helper_type; - Mat out(N, 1, arma_nozeros_indicator()); - - if(N > 0) - { - arrayops::convert( out.memptr(), &(in[0]), N ); - } - - return out; + return helper_type::apply(in); } @@ -426,6 +449,20 @@ struct conv_to_helper_Row_same_type return out; } + + inline + static + Row + apply(const std::vector& in) + { + arma_debug_sigprint(); + + const uword N = uword( in.size() ); + + const in_eT* in_memptr = (N > 0) ? &(in[0]) : nullptr; + + return Row(in_memptr, N); + } }; @@ -450,6 +487,22 @@ struct conv_to_helper_Row_diff_type arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); + return out; + } + + inline + static + Row + apply(const std::vector& in) + { + arma_debug_sigprint(); + + const uword N = uword( in.size() ); + + Row out(N, arma_nozeros_indicator()); + + if(N > 0) { arrayops::convert( out.memptr(), &(in[0]), N ); } + return out; } }; @@ -518,16 +571,9 @@ conv_to< Row >::from(const std::vector& in, const typename arma_n arma_debug_sigprint(); arma_ignore(junk); - const uword N = uword( in.size() ); + typedef typename conv_to_helper_Row_redirect::value>::result helper_type; - Row out(N, arma_nozeros_indicator()); - - if(N > 0) - { - arrayops::convert( out.memptr(), &(in[0]), N ); - } - - return out; + return helper_type::apply(in); } @@ -600,6 +646,20 @@ struct conv_to_helper_Col_same_type return out; } + + inline + static + Col + apply(const std::vector& in) + { + arma_debug_sigprint(); + + const uword N = uword( in.size() ); + + const in_eT* in_memptr = (N > 0) ? &(in[0]) : nullptr; + + return Col(in_memptr, N); + } }; @@ -624,6 +684,22 @@ struct conv_to_helper_Col_diff_type arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); + return out; + } + + inline + static + Col + apply(const std::vector& in) + { + arma_debug_sigprint(); + + const uword N = uword( in.size() ); + + Col out(N, arma_nozeros_indicator()); + + if(N > 0) { arrayops::convert( out.memptr(), &(in[0]), N ); } + return out; } }; @@ -692,16 +768,9 @@ conv_to< Col >::from(const std::vector& in, const typename arma_n arma_debug_sigprint(); arma_ignore(junk); - const uword N = uword( in.size() ); + typedef typename conv_to_helper_Col_redirect::value>::result helper_type; - Col out(N, arma_nozeros_indicator()); - - if(N > 0) - { - arrayops::convert( out.memptr(), &(in[0]), N ); - } - - return out; + return helper_type::apply(in); }