| diagmat_proxy.hpp | | diagmat_proxy.hpp | |
|
| // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2011 Conrad Sanderson | | // Copyright (C) 2008-2012 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 24 | | skipping to change at line 24 | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| class diagmat_proxy | | class diagmat_proxy | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy(const Base<typename T1::elem_type,T1>& X) | | inline diagmat_proxy(const T1& X) | |
| : P ( X.get_ref() ) | | : P ( X ) | |
| , P_is_vec( (P.get_n_rows() == 1) || (P.get_n_cols() == 1) ) | | , P_is_vec( (P.get_n_rows() == 1) || (P.get_n_cols() == 1) ) | |
|
| | | , P_is_col( P.get_n_cols() == 1 ) | |
| , n_elem ( P_is_vec ? P.get_n_elem() : (std::min)(P.get_n_elem(), P.ge
t_n_rows()) ) | | , n_elem ( P_is_vec ? P.get_n_elem() : (std::min)(P.get_n_elem(), P.ge
t_n_rows()) ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (P_is_vec == false) && (P.get_n_rows() != P.get_n_cols()), | | (P_is_vec == false) && (P.get_n_rows() != P.get_n_cols()), | |
| "diagmat(): only vectors and square matrices are accepted" | | "diagmat(): only vectors and square matrices are accepted" | |
| ); | | ); | |
| } | | } | |
| | | | |
| arma_inline | | arma_inline | |
| elem_type | | elem_type | |
| operator[](const uword i) const | | operator[](const uword i) const | |
| { | | { | |
|
| if( (Proxy<T1>::prefer_at_accessor == true) || (P_is_vec == false) ) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| return P.at(i,i); | | return P_is_vec ? P[i] : P.at(i,i); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| return P[i]; | | if(P_is_vec) | |
| | | { | |
| | | return (P_is_col) ? P.at(i,0) : P.at(0,i); | |
| | | } | |
| | | else | |
| | | { | |
| | | return P.at(i,i); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| arma_inline | | arma_inline | |
| elem_type | | elem_type | |
| at(const uword row, const uword col) const | | at(const uword row, const uword col) const | |
| { | | { | |
| if(row == col) | | if(row == col) | |
| { | | { | |
|
| if( (Proxy<T1>::prefer_at_accessor == true) || (P_is_vec == false) ) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| return P.at(row,row); | | return (P_is_vec) ? P[row] : P.at(row,row); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| return P[row]; | | if(P_is_vec) | |
| | | { | |
| | | return (P_is_col) ? P.at(row,0) : P.at(0,row); | |
| | | } | |
| | | else | |
| | | { | |
| | | return P.at(row,row); | |
| | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| return elem_type(0); | | return elem_type(0); | |
| } | | } | |
| } | | } | |
| | | | |
| const Proxy<T1> P; | | const Proxy<T1> P; | |
| const bool P_is_vec; | | const bool P_is_vec; | |
|
| | | const bool P_is_col; | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy< Mat<eT> > | | class diagmat_proxy< Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| skipping to change at line 164 | | skipping to change at line 180 | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| class diagmat_proxy_check | | class diagmat_proxy_check | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy_check(const Base<typename T1::elem_type,T1>& X, cons | | inline diagmat_proxy_check(const T1& X, const Mat<typename T1::elem_type> | |
| t Mat<typename T1::elem_type>& out) | | & out) | |
| : P(X.get_ref()) | | : P(X) | |
| , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) | | , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) | |
| , n_elem( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | | , n_elem( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(out); | | arma_ignore(out); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (P_is_vec == false) && (P.n_rows != P.n_cols), | | (P_is_vec == false) && (P.n_rows != P.n_cols), | |
| "diagmat(): only vectors and square matrices are accepted" | | "diagmat(): only vectors and square matrices are accepted" | |
| | | | |
End of changes. 11 change blocks. |
| 13 lines changed or deleted | | 29 lines changed or added | |
|