// SPDX-License-Identifier: Apache-2.0 // // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) // Copyright 2008-2016 National ICT Australia (NICTA) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ //! \addtogroup unwrap //! @{ // TODO: document the conditions and restrictions for the use of each unwrap variant: // TODO: unwrap, unwrap_check, quasi_unwrap, partial_unwrap, partial_unwrap_check template struct unwrap_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_fixed { typedef T1 stored_type; inline explicit unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const T1& M; }; template struct unwrap_redirect {}; template struct unwrap_redirect { typedef unwrap_default result; }; template struct unwrap_redirect { typedef unwrap_fixed result; }; template struct unwrap : public unwrap_redirect::value>::result { inline unwrap(const T1& A) : unwrap_redirect::value>::result(A) { } }; template struct unwrap< Mat > { typedef Mat stored_type; inline unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; }; template struct unwrap< Row > { typedef Row stored_type; inline unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } const Row& M; }; template struct unwrap< Col > { typedef Col stored_type; inline unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } const Col& M; }; template struct unwrap< subview_col > { typedef Col stored_type; inline unwrap(const subview_col& A) : M(A.colmem, A.n_rows) { arma_extra_debug_sigprint(); } const Col M; }; template struct unwrap< subview_cols > { typedef Mat stored_type; inline unwrap(const subview_cols& A) : M(A.colptr(0), A.n_rows, A.n_cols) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap< mtGlue > { typedef Mat stored_type; inline unwrap(const mtGlue& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap< mtOp > { typedef Mat stored_type; inline unwrap(const mtOp& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; // // // template struct quasi_unwrap_default { typedef typename T1::elem_type eT; inline quasi_unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } // NOTE: DO NOT DIRECTLY CHECK FOR ALIASING BY TAKING THE ADDRESS OF THE "M" OBJECT IN ANY quasi_unwrap CLASS !!! Mat M; static constexpr bool is_const = false; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = false; template constexpr bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap_fixed { typedef typename T1::elem_type eT; inline explicit quasi_unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const T1& M; static constexpr bool is_const = true; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap_redirect {}; template struct quasi_unwrap_redirect { typedef quasi_unwrap_default result; }; template struct quasi_unwrap_redirect { typedef quasi_unwrap_fixed result; }; template struct quasi_unwrap : public quasi_unwrap_redirect::value>::result { typedef typename quasi_unwrap_redirect::value>::result quasi_unwrap_extra; inline quasi_unwrap(const T1& A) : quasi_unwrap_extra(A) { } static constexpr bool is_const = quasi_unwrap_extra::is_const; static constexpr bool has_subview = quasi_unwrap_extra::has_subview; static constexpr bool has_orig_mem = quasi_unwrap_extra::has_orig_mem; using quasi_unwrap_extra::M; using quasi_unwrap_extra::is_alias; }; template struct quasi_unwrap< Mat > { inline quasi_unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; static constexpr bool is_const = true; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< Row > { inline quasi_unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } const Row& M; static constexpr bool is_const = true; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< Col > { inline quasi_unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } const Col& M; static constexpr bool is_const = true; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< subview > { inline quasi_unwrap(const subview& A) : sv( A ) , M ( A, ((A.aux_row1 == 0) && (A.n_rows == A.m.n_rows)) ) // reuse memory if the subview is a contiguous chunk { arma_extra_debug_sigprint(); } const subview& sv; const Mat M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = false; // NOTE: set to false as this is the general case; original memory is only used when the subview is a contiguous chunk template arma_inline bool is_alias(const Mat& X) const { return ( ((sv.aux_row1 == 0) && (sv.n_rows == sv.m.n_rows)) ? (void_ptr(&(sv.m)) == void_ptr(&X)) : false ); } }; template struct quasi_unwrap< subview_row > { inline quasi_unwrap(const subview_row& A) : M(A) { arma_extra_debug_sigprint(); } Row M; static constexpr bool is_const = false; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = false; template constexpr bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< subview_col > { inline quasi_unwrap(const subview_col& A) : orig( A.m ) , M ( const_cast( A.colmem ), A.n_rows, false, false ) { arma_extra_debug_sigprint(); } const Mat& orig; const Col M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap< subview_cols > { inline quasi_unwrap(const subview_cols& A) : orig( A.m ) , M ( const_cast( A.colptr(0) ), A.n_rows, A.n_cols, false, false ) { arma_extra_debug_sigprint(); } const Mat& orig; const Mat M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap< mtGlue > { inline quasi_unwrap(const mtGlue& A) : M(A) { arma_extra_debug_sigprint(); } Mat M; static constexpr bool is_const = false; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = false; template constexpr bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< mtOp > { inline quasi_unwrap(const mtOp& A) : M(A) { arma_extra_debug_sigprint(); } Mat M; static constexpr bool is_const = false; static constexpr bool has_subview = false; static constexpr bool has_orig_mem = false; template constexpr bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< Op > { typedef typename T1::elem_type eT; inline quasi_unwrap(const Op& A) : U( A.m ) , M( const_cast(U.M.memptr()), U.M.n_elem, 1, false, false ) { arma_extra_debug_sigprint(); } const quasi_unwrap U; const Mat M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return U.is_alias(X); } }; template struct quasi_unwrap< Op, op_strans> > { inline quasi_unwrap(const Op, op_strans>& A) : orig(A.m) , M (const_cast(A.m.memptr()), A.m.n_elem, false, false) { arma_extra_debug_sigprint(); } const Col& orig; const Row M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap< Op, op_strans> > { inline quasi_unwrap(const Op, op_strans>& A) : orig(A.m) , M (const_cast(A.m.memptr()), A.m.n_elem, false, false) { arma_extra_debug_sigprint(); } const Row& orig; const Col M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap< Op, op_strans> > { inline quasi_unwrap(const Op, op_strans>& A) : orig( A.m.m ) , M ( const_cast( A.m.colmem ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } const Mat& orig; const Row M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } }; template struct quasi_unwrap_Col_htrans { inline quasi_unwrap_Col_htrans(const T1&) {} }; template struct quasi_unwrap_Col_htrans< Op, op_htrans> > { inline quasi_unwrap_Col_htrans(const Op, op_htrans>& A) : orig(A.m) , M (const_cast(A.m.memptr()), A.m.n_elem, false, false) { arma_extra_debug_sigprint(); } const Col& orig; const Row M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap_Col_htrans_redirect {}; template struct quasi_unwrap_Col_htrans_redirect { typedef quasi_unwrap_default result; }; template struct quasi_unwrap_Col_htrans_redirect { typedef quasi_unwrap_Col_htrans result; }; template struct quasi_unwrap< Op, op_htrans> > : public quasi_unwrap_Col_htrans_redirect< Op, op_htrans>, is_cx::value >::result { typedef typename quasi_unwrap_Col_htrans_redirect< Op, op_htrans>, is_cx::value >::result quasi_unwrap_Col_htrans_extra; inline quasi_unwrap(const Op, op_htrans>& A) : quasi_unwrap_Col_htrans_extra(A) { } static constexpr bool is_const = quasi_unwrap_Col_htrans_extra::is_const; static constexpr bool has_subview = quasi_unwrap_Col_htrans_extra::has_subview; static constexpr bool has_orig_mem = quasi_unwrap_Col_htrans_extra::has_orig_mem; using quasi_unwrap_Col_htrans_extra::M; using quasi_unwrap_Col_htrans_extra::is_alias; }; template struct quasi_unwrap_Row_htrans { inline quasi_unwrap_Row_htrans(const T1&) {} }; template struct quasi_unwrap_Row_htrans< Op, op_htrans> > { inline quasi_unwrap_Row_htrans(const Op, op_htrans>& A) : orig(A.m) , M (const_cast(A.m.memptr()), A.m.n_elem, false, false) { arma_extra_debug_sigprint(); } const Row& orig; const Col M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap_Row_htrans_redirect {}; template struct quasi_unwrap_Row_htrans_redirect { typedef quasi_unwrap_default result; }; template struct quasi_unwrap_Row_htrans_redirect { typedef quasi_unwrap_Row_htrans result; }; template struct quasi_unwrap< Op, op_htrans> > : public quasi_unwrap_Row_htrans_redirect< Op, op_htrans>, is_cx::value >::result { typedef typename quasi_unwrap_Row_htrans_redirect< Op, op_htrans>, is_cx::value >::result quasi_unwrap_Row_htrans_extra; inline quasi_unwrap(const Op, op_htrans>& A) : quasi_unwrap_Row_htrans_extra(A) { } static constexpr bool is_const = quasi_unwrap_Row_htrans_extra::is_const; static constexpr bool has_subview = quasi_unwrap_Row_htrans_extra::has_subview; static constexpr bool has_orig_mem = quasi_unwrap_Row_htrans_extra::has_orig_mem; using quasi_unwrap_Row_htrans_extra::M; using quasi_unwrap_Row_htrans_extra::is_alias; }; template struct quasi_unwrap_subview_col_htrans { inline quasi_unwrap_subview_col_htrans(const T1&) {} }; template struct quasi_unwrap_subview_col_htrans< Op, op_htrans> > { inline quasi_unwrap_subview_col_htrans(const Op, op_htrans>& A) : orig(A.m.m) , M (const_cast(A.m.colmem), A.m.n_rows, false, false) { arma_extra_debug_sigprint(); } const Mat& orig; const Row M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap_subview_col_htrans_redirect {}; template struct quasi_unwrap_subview_col_htrans_redirect { typedef quasi_unwrap_default result; }; template struct quasi_unwrap_subview_col_htrans_redirect { typedef quasi_unwrap_subview_col_htrans result; }; template struct quasi_unwrap< Op, op_htrans> > : public quasi_unwrap_subview_col_htrans_redirect< Op, op_htrans>, is_cx::value >::result { typedef typename quasi_unwrap_subview_col_htrans_redirect< Op, op_htrans>, is_cx::value >::result quasi_unwrap_subview_col_htrans_extra; inline quasi_unwrap(const Op, op_htrans>& A) : quasi_unwrap_subview_col_htrans_extra(A) { } static constexpr bool is_const = quasi_unwrap_subview_col_htrans_extra::is_const; static constexpr bool has_subview = quasi_unwrap_subview_col_htrans_extra::has_subview; static constexpr bool has_orig_mem = quasi_unwrap_subview_col_htrans_extra::has_orig_mem; using quasi_unwrap_subview_col_htrans_extra::M; using quasi_unwrap_subview_col_htrans_extra::is_alias; }; template struct quasi_unwrap< CubeToMatOp > { typedef typename T1::elem_type eT; inline quasi_unwrap(const CubeToMatOp& A) : U( A.m ) , M( const_cast(U.M.memptr()), U.M.n_elem, 1, false, true ) { arma_extra_debug_sigprint(); } const unwrap_cube U; const Mat M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template constexpr bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< SpToDOp > { typedef typename T1::elem_type eT; inline quasi_unwrap(const SpToDOp& A) : U( A.m ) , M( const_cast(U.M.values), U.M.n_nonzero, 1, false, true ) { arma_extra_debug_sigprint(); } const unwrap_spmat U; const Mat M; static constexpr bool is_const = true; static constexpr bool has_subview = true; static constexpr bool has_orig_mem = true; template constexpr bool is_alias(const Mat&) const { return false; } }; // // // template struct unwrap_check_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline unwrap_check_default(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } inline unwrap_check_default(const T1& A, const bool) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_check_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline unwrap_check_fixed(const T1& A, const Mat& B) : M_local( (&A == &B) ? new T1(A) : nullptr ) , M ( (&A == &B) ? *M_local : A ) { arma_extra_debug_sigprint(); } inline unwrap_check_fixed(const T1& A, const bool is_alias) : M_local( is_alias ? new T1(A) : nullptr ) , M ( is_alias ? *M_local : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const T1* M_local; const T1& M; }; template struct unwrap_check_redirect {}; template struct unwrap_check_redirect { typedef unwrap_check_default result; }; template struct unwrap_check_redirect { typedef unwrap_check_fixed result; }; template struct unwrap_check : public unwrap_check_redirect::value>::result { inline unwrap_check(const T1& A, const Mat& B) : unwrap_check_redirect::value>::result(A, B) { } inline unwrap_check(const T1& A, const bool is_alias) : unwrap_check_redirect::value>::result(A, is_alias) { } }; template struct unwrap_check< Mat > { typedef Mat stored_type; inline unwrap_check(const Mat& A, const Mat& B) : M_local( (&A == &B) ? new Mat(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline unwrap_check(const Mat& A, const bool is_alias) : M_local( is_alias ? new Mat(A) : nullptr ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Mat* M_local; const Mat& M; }; template struct unwrap_check< Row > { typedef Row stored_type; inline unwrap_check(const Row& A, const Mat& B) : M_local( (&A == &B) ? new Row(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline unwrap_check(const Row& A, const bool is_alias) : M_local( is_alias ? new Row(A) : nullptr ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Row* M_local; const Row& M; }; template struct unwrap_check< Col > { typedef Col stored_type; inline unwrap_check(const Col& A, const Mat& B) : M_local( (&A == &B) ? new Col(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline unwrap_check(const Col& A, const bool is_alias) : M_local( is_alias ? new Col(A) : nullptr ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Col* M_local; const Col& M; }; // // // template struct unwrap_check_mixed { typedef typename T1::elem_type eT1; template inline unwrap_check_mixed(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const T1& A, const bool) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_check_mixed< Mat > { template inline unwrap_check_mixed(const Mat& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Mat(A) : nullptr ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Mat& A, const bool is_alias) : M_local( is_alias ? new Mat(A) : nullptr ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Mat* M_local; const Mat& M; }; template struct unwrap_check_mixed< Row > { template inline unwrap_check_mixed(const Row& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Row(A) : nullptr ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Row& A, const bool is_alias) : M_local( is_alias ? new Row(A) : nullptr ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Row* M_local; const Row& M; }; template struct unwrap_check_mixed< Col > { template inline unwrap_check_mixed(const Col& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Col(A) : nullptr ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Col& A, const bool is_alias) : M_local( is_alias ? new Col(A) : nullptr ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Col* M_local; const Col& M; }; // // // template struct partial_unwrap_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Mat M; }; template struct partial_unwrap_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const T1& M; }; template struct partial_unwrap_redirect {}; template struct partial_unwrap_redirect { typedef partial_unwrap_default result; }; template struct partial_unwrap_redirect { typedef partial_unwrap_fixed result; }; template struct partial_unwrap : public partial_unwrap_redirect::value>::result { inline partial_unwrap(const T1& A) : partial_unwrap_redirect< T1, is_Mat_fixed::value>::result(A) { } }; template struct partial_unwrap< Mat > { typedef Mat stored_type; inline partial_unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Mat& M; }; template struct partial_unwrap< Row > { typedef Row stored_type; inline partial_unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Row& M; }; template struct partial_unwrap< Col > { typedef Col stored_type; inline partial_unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Col& M; }; template struct partial_unwrap< subview > { typedef Mat stored_type; inline partial_unwrap(const subview& A) : sv( A ) , M ( A, ((A.aux_row1 == 0) && (A.n_rows == A.m.n_rows)) ) // reuse memory if the subview is a contiguous chunk { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return ( ((sv.aux_row1 == 0) && (sv.n_rows == sv.m.n_rows)) ? (void_ptr(&(sv.m)) == void_ptr(&X)) : false ); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const subview& sv; const Mat M; }; template struct partial_unwrap< subview_col > { typedef Col stored_type; inline partial_unwrap(const subview_col& A) : orig( A.m ) , M ( const_cast( A.colmem ), A.n_rows, false, false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Mat& orig; const Col M; }; template struct partial_unwrap< subview_cols > { typedef Mat stored_type; inline partial_unwrap(const subview_cols& A) : orig( A.m ) , M ( const_cast( A.colptr(0) ), A.n_rows, A.n_cols, false, false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Mat& orig; const Mat M; }; template struct partial_unwrap< subview_row > { typedef Row stored_type; inline partial_unwrap(const subview_row& A) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Row M; }; template struct partial_unwrap_htrans_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_htrans_default(const Op& A) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Mat M; }; template struct partial_unwrap_htrans_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_htrans_fixed(const Op& A) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const T1& M; }; template struct partial_unwrap_htrans_redirect {}; template struct partial_unwrap_htrans_redirect { typedef partial_unwrap_htrans_default result; }; template struct partial_unwrap_htrans_redirect { typedef partial_unwrap_htrans_fixed result; }; template struct partial_unwrap< Op > : public partial_unwrap_htrans_redirect::value>::result { inline partial_unwrap(const Op& A) : partial_unwrap_htrans_redirect::value>::result(A) { } }; template struct partial_unwrap< Op< Mat, op_htrans> > { typedef Mat stored_type; inline partial_unwrap(const Op< Mat, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Mat& M; }; template struct partial_unwrap< Op< Row, op_htrans> > { typedef Row stored_type; inline partial_unwrap(const Op< Row, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Row& M; }; template struct partial_unwrap< Op< Col, op_htrans> > { typedef Col stored_type; inline partial_unwrap(const Op< Col, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Col& M; }; template struct partial_unwrap< Op< subview, op_htrans> > { typedef Mat stored_type; inline partial_unwrap(const Op< subview, op_htrans>& A) : sv( A.m ) , M ( A.m, ((A.m.aux_row1 == 0) && (A.m.n_rows == A.m.m.n_rows)) ) // reuse memory if the subview is a contiguous chunk { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return ( ((sv.aux_row1 == 0) && (sv.n_rows == sv.m.n_rows)) ? (void_ptr(&(sv.m)) == void_ptr(&X)) : false ); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const subview& sv; const Mat M; }; template struct partial_unwrap< Op< subview_cols, op_htrans> > { typedef Mat stored_type; inline partial_unwrap(const Op< subview_cols, op_htrans>& A) : orig( A.m.m ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, A.m.n_cols, false, false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Mat& orig; const Mat M; }; template struct partial_unwrap< Op< subview_col, op_htrans> > { typedef Col stored_type; inline partial_unwrap(const Op< subview_col, op_htrans>& A) : orig( A.m.m ) , M ( const_cast( A.m.colmem ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Mat& orig; const Col M; }; template struct partial_unwrap< Op< subview_row, op_htrans> > { typedef Row stored_type; inline partial_unwrap(const Op< subview_row, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Row M; }; template struct partial_unwrap_htrans2_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_htrans2_default(const Op& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_htrans2_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_htrans2_fixed(const Op& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const T1& M; }; template struct partial_unwrap_htrans2_redirect {}; template struct partial_unwrap_htrans2_redirect { typedef partial_unwrap_htrans2_default result; }; template struct partial_unwrap_htrans2_redirect { typedef partial_unwrap_htrans2_fixed result; }; template struct partial_unwrap< Op > : public partial_unwrap_htrans2_redirect::value>::result { inline partial_unwrap(const Op& A) : partial_unwrap_htrans2_redirect::value>::result(A) { } }; template struct partial_unwrap< Op< Mat, op_htrans2> > { typedef Mat stored_type; inline partial_unwrap(const Op< Mat, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Mat& M; }; template struct partial_unwrap< Op< Row, op_htrans2> > { typedef Row stored_type; inline partial_unwrap(const Op< Row, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Row& M; }; template struct partial_unwrap< Op< Col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap(const Op< Col, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Col& M; }; template struct partial_unwrap< Op< subview, op_htrans2> > { typedef Mat stored_type; inline partial_unwrap(const Op< subview, op_htrans2>& A) : sv ( A.m ) , val( A.aux ) , M ( A.m, ((A.m.aux_row1 == 0) && (A.m.n_rows == A.m.m.n_rows)) ) // reuse memory if the subview is a contiguous chunk { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return ( ((sv.aux_row1 == 0) && (sv.n_rows == sv.m.n_rows)) ? (void_ptr(&(sv.m)) == void_ptr(&X)) : false ); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const subview& sv; const eT val; const Mat M; }; template struct partial_unwrap< Op< subview_cols, op_htrans2> > { typedef Mat stored_type; inline partial_unwrap(const Op< subview_cols, op_htrans2>& A) : orig( A.m.m ) , val ( A.aux ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, A.m.n_cols, false, false ) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const Mat& orig; const eT val; const Mat M; }; template struct partial_unwrap< Op< subview_col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap(const Op< subview_col, op_htrans2>& A) : orig( A.m.m ) , val ( A.aux ) , M ( const_cast( A.m.colmem ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static constexpr bool do_trans = true; static constexpr bool do_times = true; const Mat& orig; const eT val; const Col M; }; template struct partial_unwrap< Op< subview_row, op_htrans2> > { typedef Row stored_type; inline partial_unwrap(const Op< subview_row, op_htrans2>& A) : val(A.aux) , M (A.m ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Row M; }; template struct partial_unwrap_scalar_times_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_scalar_times_default(const eOp& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_scalar_times_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_scalar_times_fixed(const eOp& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const T1& M; }; template struct partial_unwrap_scalar_times_redirect {}; template struct partial_unwrap_scalar_times_redirect { typedef partial_unwrap_scalar_times_default result; }; template struct partial_unwrap_scalar_times_redirect { typedef partial_unwrap_scalar_times_fixed result; }; template struct partial_unwrap< eOp > : public partial_unwrap_scalar_times_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap(const eOp& A) : partial_unwrap_scalar_times_redirect< T1, is_Mat_fixed::value>::result(A) { } }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Mat stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Mat& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Row& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Col& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : orig( A.P.Q.m ) , val ( A.aux ) , M ( const_cast( A.P.Q.colmem ), A.P.Q.n_rows, false, false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Mat& orig; const eT val; const Col M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Row M; }; template struct partial_unwrap_neg_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_neg_default(const eOp& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Mat M; }; template struct partial_unwrap_neg_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_neg_fixed(const eOp& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const T1& M; }; template struct partial_unwrap_neg_redirect {}; template struct partial_unwrap_neg_redirect { typedef partial_unwrap_neg_default result; }; template struct partial_unwrap_neg_redirect { typedef partial_unwrap_neg_fixed result; }; template struct partial_unwrap< eOp > : public partial_unwrap_neg_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap(const eOp& A) : partial_unwrap_neg_redirect< T1, is_Mat_fixed::value>::result(A) { } }; template struct partial_unwrap< eOp, eop_neg> > { typedef Mat stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Mat& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Row& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Col& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : orig( A.P.Q.m ) , M ( const_cast( A.P.Q.colmem ), A.P.Q.n_rows, false, false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Mat& orig; const Col M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } template constexpr bool is_alias(const Mat&) const { return false; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Row M; }; // template struct partial_unwrap_check_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_default(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Mat M; }; template struct partial_unwrap_check_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_fixed(const T1& A, const Mat& B) : M_local( (&A == &B) ? new T1(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_redirect {}; template struct partial_unwrap_check_redirect { typedef partial_unwrap_check_default result; }; template struct partial_unwrap_check_redirect { typedef partial_unwrap_check_fixed result; }; template struct partial_unwrap_check : public partial_unwrap_check_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const T1& A, const Mat& B) : partial_unwrap_check_redirect::value>::result(A, B) { } }; template struct partial_unwrap_check< Mat > { typedef Mat stored_type; inline partial_unwrap_check(const Mat& A, const Mat& B) : M_local ( (&A == &B) ? new Mat(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = false; static constexpr bool do_times = false; // the order below is important const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Row > { typedef Row stored_type; inline partial_unwrap_check(const Row& A, const Mat& B) : M_local ( (&A == &B) ? new Row(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = false; static constexpr bool do_times = false; // the order below is important const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Col > { typedef Col stored_type; inline partial_unwrap_check(const Col& A, const Mat& B) : M_local ( (&A == &B) ? new Col(A) : nullptr ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = false; static constexpr bool do_times = false; // the order below is important const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< subview_col > { typedef Col stored_type; inline partial_unwrap_check(const subview_col& A, const Mat& B) : M ( const_cast( A.colmem ), A.n_rows, (&(A.m) == &B), false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = false; static constexpr bool do_times = false; const Col M; }; template struct partial_unwrap_check_htrans_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_htrans_default(const Op& A, const Mat&) : M(A.m) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Mat M; }; template struct partial_unwrap_check_htrans_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_htrans_fixed(const Op& A, const Mat& B) : M_local( (&(A.m) == &B) ? new T1(A.m) : nullptr ) , M ( (&(A.m) == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_htrans_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_htrans_redirect {}; template struct partial_unwrap_check_htrans_redirect { typedef partial_unwrap_check_htrans_default result; }; template struct partial_unwrap_check_htrans_redirect { typedef partial_unwrap_check_htrans_fixed result; }; template struct partial_unwrap_check< Op > : public partial_unwrap_check_htrans_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const Op& A, const Mat& B) : partial_unwrap_check_htrans_redirect::value>::result(A, B) { } }; template struct partial_unwrap_check< Op< Mat, op_htrans> > { typedef Mat stored_type; inline partial_unwrap_check(const Op< Mat, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Mat(A.m) : nullptr ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = true; static constexpr bool do_times = false; // the order below is important const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Op< Row, op_htrans> > { typedef Row stored_type; inline partial_unwrap_check(const Op< Row, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Row(A.m) : nullptr ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = true; static constexpr bool do_times = false; // the order below is important const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Op< Col, op_htrans> > { typedef Col stored_type; inline partial_unwrap_check(const Op< Col, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Col(A.m) : nullptr ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = true; static constexpr bool do_times = false; // the order below is important const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< Op< subview_col, op_htrans> > { typedef Col stored_type; inline partial_unwrap_check(const Op< subview_col, op_htrans>& A, const Mat& B) : M ( const_cast( A.m.colmem ), A.m.n_rows, (&(A.m.m) == &B), false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(1); } static constexpr bool do_trans = true; static constexpr bool do_times = false; const Col M; }; template struct partial_unwrap_check_htrans2_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_htrans2_default(const Op& A, const Mat&) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_check_htrans2_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_htrans2_fixed(const Op& A, const Mat& B) : val (A.aux) , M_local( (&(A.m) == &B) ? new T1(A.m) : nullptr ) , M ( (&(A.m) == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_htrans2_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_htrans2_redirect {}; template struct partial_unwrap_check_htrans2_redirect { typedef partial_unwrap_check_htrans2_default result; }; template struct partial_unwrap_check_htrans2_redirect { typedef partial_unwrap_check_htrans2_fixed result; }; template struct partial_unwrap_check< Op > : public partial_unwrap_check_htrans2_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const Op& A, const Mat& B) : partial_unwrap_check_htrans2_redirect::value>::result(A, B) { } }; template struct partial_unwrap_check< Op< Mat, op_htrans2> > { typedef Mat stored_type; inline partial_unwrap_check(const Op< Mat, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Mat(A.m) : nullptr ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = true; static constexpr bool do_times = true; // the order below is important const eT val; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Op< Row, op_htrans2> > { typedef Row stored_type; inline partial_unwrap_check(const Op< Row, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Row(A.m) : nullptr ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = true; static constexpr bool do_times = true; // the order below is important const eT val; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Op< Col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap_check(const Op< Col, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Col(A.m) : nullptr ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = true; static constexpr bool do_times = true; // the order below is important const eT val; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< Op< subview_col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap_check(const Op< subview_col, op_htrans2>& A, const Mat& B) : val( A.aux ) , M ( const_cast( A.m.colmem ), A.m.n_rows, (&(A.m.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = true; static constexpr bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_check_scalar_times_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_scalar_times_default(const eOp& A, const Mat&) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_check_scalar_times_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_scalar_times_fixed(const eOp& A, const Mat& B) : val ( A.aux ) , M_local( (&(A.P.Q) == &B) ? new T1(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_scalar_times_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_scalar_times_redirect {}; template struct partial_unwrap_check_scalar_times_redirect { typedef partial_unwrap_check_scalar_times_default result; }; template struct partial_unwrap_check_scalar_times_redirect { typedef partial_unwrap_check_scalar_times_fixed result; }; template struct partial_unwrap_check< eOp > : public partial_unwrap_check_scalar_times_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const eOp& A, const Mat& B) : partial_unwrap_check_scalar_times_redirect::value>::result(A, B) { } }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Mat stored_type; inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val (A.aux) , M_local( (&(A.P.Q) == &B) ? new Mat(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Row stored_type; inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val(A.aux) , M_local( (&(A.P.Q) == &B) ? new Row(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Col stored_type; inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val ( A.aux ) , M_local( (&(A.P.Q) == &B) ? new Col(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Col stored_type; inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val( A.aux ) , M ( const_cast( A.P.Q.colmem ), A.P.Q.n_rows, (&(A.P.Q.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } static constexpr bool do_trans = false; static constexpr bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_check_neg_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_neg_default(const eOp& A, const Mat&) : M(A.P.Q) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Mat M; }; template struct partial_unwrap_check_neg_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_neg_fixed(const eOp& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new T1(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_neg_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(-1); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_neg_redirect {}; template struct partial_unwrap_check_neg_redirect { typedef partial_unwrap_check_neg_default result; }; template struct partial_unwrap_check_neg_redirect { typedef partial_unwrap_check_neg_fixed result; }; template struct partial_unwrap_check< eOp > : public partial_unwrap_check_neg_redirect::value>::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const eOp& A, const Mat& B) : partial_unwrap_check_neg_redirect::value>::result(A, B) { } }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Mat stored_type; inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Mat(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(-1); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Row stored_type; inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Row(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(-1); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Col(A.P.Q) : nullptr ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } constexpr eT get_val() const { return eT(-1); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M ( const_cast( A.P.Q.colmem ), A.P.Q.n_rows, (&(A.P.Q.m) == &B), false ) { arma_extra_debug_sigprint(); } constexpr eT get_val() const { return eT(-1); } static constexpr bool do_trans = false; static constexpr bool do_times = true; const Col M; }; //! @}