max@0: // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2010 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup fn_conv_to max@0: //! @{ max@0: max@0: max@0: max@0: //! conversion from Armadillo Base and BaseCube objects to scalars max@0: //! (kept only for compatibility with old code; use as_scalar() instead for Base objects like Mat) max@0: template max@0: class conv_to max@0: { max@0: public: max@0: max@0: template max@0: inline static out_eT from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static out_eT from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: template max@0: inline static out_eT from(const BaseCube& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static out_eT from(const BaseCube& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: out_eT max@0: conv_to::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: arma_type_check(( is_supported_elem_type::value == false )); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); max@0: max@0: return out_eT(X.mem[0]); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: out_eT max@0: conv_to::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: arma_type_check(( is_supported_elem_type::value == false )); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); max@0: max@0: out_eT out; max@0: max@0: arrayops::convert_cx_scalar(out, X.mem[0]); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: out_eT max@0: conv_to::from(const BaseCube& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: arma_type_check(( is_supported_elem_type::value == false )); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: const Cube& X = tmp.M; max@0: max@0: arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); max@0: max@0: return out_eT(X.mem[0]); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: out_eT max@0: conv_to::from(const BaseCube& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: arma_type_check(( is_supported_elem_type::value == false )); max@0: max@0: const unwrap_cube tmp(in.get_ref()); max@0: const Cube& X = tmp.M; max@0: max@0: arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); max@0: max@0: out_eT out; max@0: max@0: arrayops::convert_cx_scalar(out, X.mem[0]); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! conversion to Armadillo matrices from Armadillo Base objects, max@0: //! as well as from std::vector, itpp::Mat and itpp::Vec max@0: template max@0: class conv_to< Mat > max@0: { max@0: public: max@0: max@0: template max@0: inline static Mat from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Mat from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Mat from(const std::vector& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Mat from(const std::vector& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Mat from(const itpp::Mat& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Mat from(const itpp::Mat& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Mat from(const itpp::Vec& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Mat from(const itpp::Vec& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: Mat out(X.n_rows, X.n_cols); max@0: max@0: arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: Mat out(X.n_rows, X.n_cols); max@0: max@0: arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const std::vector& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Mat out(in.size(), 1); max@0: max@0: typename std::vector::const_iterator in_begin = in.begin(); max@0: typename std::vector::const_iterator in_end = in.end(); max@0: max@0: typename Mat::iterator out_begin = out.begin(); max@0: typename Mat::iterator out_end = out.end(); max@0: max@0: typename std::vector::const_iterator in_it; max@0: typename Mat::iterator out_it; max@0: max@0: for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) max@0: { max@0: (*out_it) = out_eT(*in_it); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const std::vector& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Mat out(in.size(), 1); max@0: max@0: typename std::vector::const_iterator in_begin = in.begin(); max@0: typename std::vector::const_iterator in_end = in.end(); max@0: max@0: typename Mat::iterator out_begin = out.begin(); max@0: typename Mat::iterator out_end = out.end(); max@0: max@0: typename std::vector::const_iterator in_it; max@0: typename Mat::iterator out_it; max@0: max@0: for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) max@0: { max@0: out_eT& out_elem = (*out_it); max@0: const in_eT& in_elem = (*in_it); max@0: max@0: arrayops::convert_cx_scalar(out_elem, in_elem); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const itpp::Mat& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Mat out(in.rows(), in.cols()); max@0: max@0: arrayops::convert( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const itpp::Mat& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Mat out(in.rows(), in.cols()); max@0: max@0: arrayops::convert_cx( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const itpp::Vec& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Mat out(in.length(), 1); max@0: max@0: arrayops::convert( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Mat max@0: conv_to< Mat >::from(const itpp::Vec& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Mat out(in.length(), 1); max@0: max@0: arrayops::convert_cx( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! conversion to Armadillo row vectors from Armadillo Base objects, max@0: //! as well as from std::vector, itpp::Mat and itpp::Vec max@0: template max@0: class conv_to< Row > max@0: { max@0: public: max@0: max@0: template max@0: inline static Row from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Row from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Row from(const std::vector& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Row from(const std::vector& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Row from(const itpp::Mat& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Row from(const itpp::Mat& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Row from(const itpp::Vec& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Row from(const itpp::Vec& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: Row out(X.n_elem); max@0: max@0: arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: Row out(X.n_rows, X.n_cols); max@0: max@0: arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const std::vector& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Row out( in.size() ); max@0: max@0: typename std::vector::const_iterator in_begin = in.begin(); max@0: typename std::vector::const_iterator in_end = in.end(); max@0: max@0: typename Row::iterator out_begin = out.begin(); max@0: typename Row::iterator out_end = out.end(); max@0: max@0: typename std::vector::const_iterator in_it; max@0: typename Row::iterator out_it; max@0: max@0: for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) max@0: { max@0: (*out_it) = out_eT(*in_it); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const std::vector& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Row out( in.size() ); max@0: max@0: typename std::vector::const_iterator in_begin = in.begin(); max@0: typename std::vector::const_iterator in_end = in.end(); max@0: max@0: typename Row::iterator out_begin = out.begin(); max@0: typename Row::iterator out_end = out.end(); max@0: max@0: typename std::vector::const_iterator in_it; max@0: typename Row::iterator out_it; max@0: max@0: for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) max@0: { max@0: out_eT& out_elem = (*out_it); max@0: const in_eT& in_elem = (*in_it); max@0: max@0: arrayops::convert_cx_scalar(out_elem, in_elem); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const itpp::Mat& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) ); max@0: max@0: arma_debug_check( (is_vec == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: Row out(in.rows() * in.cols()); max@0: max@0: arrayops::convert( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const itpp::Mat& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: //const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) ); max@0: max@0: Row out(in.rows() * in.cols()); max@0: max@0: arrayops::convert_cx( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const itpp::Vec& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Row out(in.length()); max@0: max@0: arrayops::convert( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Row max@0: conv_to< Row >::from(const itpp::Vec& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Row out(in.length()); max@0: max@0: arrayops::convert_cx( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! conversion to Armadillo column vectors from Armadillo Base objects, max@0: //! as well as from std::vector, itpp::Mat and itpp::Vec max@0: template max@0: class conv_to< Col > max@0: { max@0: public: max@0: max@0: template max@0: inline static Col from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Col from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Col from(const std::vector& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Col from(const std::vector& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Col from(const itpp::Mat& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Col from(const itpp::Mat& in, const typename arma_cx_only::result* junk = 0); max@0: max@0: max@0: max@0: template max@0: inline static Col from(const itpp::Vec& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Col from(const itpp::Vec& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: Col out(X.n_elem); max@0: max@0: arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: Col out(X.n_rows, X.n_cols); max@0: max@0: arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const std::vector& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Col out( in.size() ); max@0: max@0: typename std::vector::const_iterator in_begin = in.begin(); max@0: typename std::vector::const_iterator in_end = in.end(); max@0: max@0: typename Col::iterator out_begin = out.begin(); max@0: typename Col::iterator out_end = out.end(); max@0: max@0: typename std::vector::const_iterator in_it; max@0: typename Col::iterator out_it; max@0: max@0: for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) max@0: { max@0: (*out_it) = out_eT(*in_it); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const std::vector& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Col out( in.size() ); max@0: max@0: typename std::vector::const_iterator in_begin = in.begin(); max@0: typename std::vector::const_iterator in_end = in.end(); max@0: max@0: typename Col::iterator out_begin = out.begin(); max@0: typename Col::iterator out_end = out.end(); max@0: max@0: typename std::vector::const_iterator in_it; max@0: typename Col::iterator out_it; max@0: max@0: for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) max@0: { max@0: out_eT& out_elem = (*out_it); max@0: const in_eT& in_elem = (*in_it); max@0: max@0: arrayops::convert_cx_scalar(out_elem, in_elem); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const itpp::Mat& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) ); max@0: max@0: arma_debug_check( (is_vec == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: Col out(in.rows() * in.cols()); max@0: max@0: arrayops::convert( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const itpp::Mat& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: //const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) ); max@0: max@0: Col out(in.rows() * in.cols()); max@0: max@0: arrayops::convert_cx( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const itpp::Vec& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Col out( in.length() ); max@0: max@0: arrayops::convert( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Col max@0: conv_to< Col >::from(const itpp::Vec& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: Col out( in.length() ); max@0: max@0: arrayops::convert_cx( out.memptr(), in._data(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! conversion to Armadillo cubes from Armadillo BaseCube objects max@0: template max@0: class conv_to< Cube > max@0: { max@0: public: max@0: max@0: template max@0: inline static Cube from(const BaseCube& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static Cube from(const BaseCube& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Cube max@0: conv_to< Cube >::from(const BaseCube& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap_cube tmp( in.get_ref() ); max@0: const Cube& X = tmp.M; max@0: max@0: Cube out(X.n_rows, X.n_cols, X.n_slices); max@0: max@0: arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: Cube max@0: conv_to< Cube >::from(const BaseCube& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap_cube tmp( in.get_ref() ); max@0: const Cube& X = tmp.M; max@0: max@0: Cube out(X.n_rows, X.n_cols, X.n_slices); max@0: max@0: arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! conversion to std::vector from Armadillo Base objects max@0: template max@0: class conv_to< std::vector > max@0: { max@0: public: max@0: max@0: template max@0: inline static std::vector from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static std::vector from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: std::vector max@0: conv_to< std::vector >::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: std::vector out(X.n_elem); max@0: max@0: typename Mat::const_iterator X_begin = X.begin(); max@0: typename Mat::const_iterator X_end = X.end(); max@0: max@0: typename std::vector::iterator out_begin = out.begin(); max@0: typename std::vector::iterator out_end = out.end(); max@0: max@0: typename Mat::const_iterator X_it; max@0: typename std::vector::iterator out_it; max@0: max@0: for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it) max@0: { max@0: (*out_it) = out_eT(*X_it); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: std::vector max@0: conv_to< std::vector >::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp(in.get_ref()); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: std::vector out(X.n_elem); max@0: max@0: typename Mat::const_iterator X_begin = X.begin(); max@0: typename Mat::const_iterator X_end = X.end(); max@0: max@0: typename std::vector::iterator out_begin = out.begin(); max@0: typename std::vector::iterator out_end = out.end(); max@0: max@0: typename Mat::const_iterator X_it; max@0: typename std::vector::iterator out_it; max@0: max@0: for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it) max@0: { max@0: out_eT& out_elem = (*out_it); max@0: const in_eT& X_elem = (*X_it); max@0: max@0: arrayops::convert_cx_scalar(out_elem, X_elem); max@0: } max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! conversion to itpp::Mat from Armadillo Base objects max@0: template max@0: class conv_to< itpp::Mat > max@0: { max@0: public: max@0: max@0: template max@0: inline static itpp::Mat from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static itpp::Mat from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: itpp::Mat max@0: conv_to< itpp::Mat >::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp( in.get_ref() ); max@0: const Mat& X = tmp.M; max@0: max@0: itpp::Mat out(X.n_rows, X.n_cols); max@0: max@0: arrayops::convert( out._data(), X.memptr(), X.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: itpp::Mat max@0: conv_to< itpp::Mat >::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp( in.get_ref() ); max@0: const Mat& X = tmp.M; max@0: max@0: itpp::Mat out(X.n_rows, X.n_cols); max@0: max@0: arrayops::convert_cx( out._data(), X.memptr(), X.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: max@0: //! conversion to itpp::Vec from Armadillo Base objects max@0: template max@0: class conv_to< itpp::Vec > max@0: { max@0: public: max@0: max@0: template max@0: inline static itpp::Vec from(const Base& in, const typename arma_not_cx::result* junk = 0); max@0: max@0: template max@0: inline static itpp::Vec from(const Base& in, const typename arma_cx_only::result* junk = 0); max@0: }; max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: itpp::Vec max@0: conv_to< itpp::Vec >::from(const Base& in, const typename arma_not_cx::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp( in.get_ref() ); max@0: const Mat& X = tmp.M; max@0: max@0: arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" ); max@0: max@0: itpp::Vec out(X.n_elem); max@0: max@0: arrayops::convert( out._data(), X.memptr(), X.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: itpp::Vec max@0: conv_to< itpp::Vec >::from(const Base& in, const typename arma_cx_only::result* junk) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_ignore(junk); max@0: max@0: const unwrap tmp( in.get_ref() ); max@0: const Mat& X = tmp.M; max@0: max@0: itpp::Vec out(X.n_elem); max@0: max@0: arrayops::convert_cx( out._data(), X.memptr(), X.n_elem ); max@0: max@0: return out; max@0: } max@0: max@0: max@0: max@0: //! @}