diff --git a/include/armadillo_bits/unwrap.hpp b/include/armadillo_bits/unwrap.hpp index b6be60bc..77ead018 100644 --- a/include/armadillo_bits/unwrap.hpp +++ b/include/armadillo_bits/unwrap.hpp @@ -21,7 +21,7 @@ // TODO: document the conditions and restrictions for the use of each unwrap variant: -// TODO: unwrap, unwrap_check, quasi_unwrap, partial_unwrap, partial_unwrap_check +// TODO: unwrap, unwrap_check, quasi_unwrap, partial_unwrap template @@ -2425,1038 +2425,6 @@ struct partial_unwrap< eOp, eop_neg> > -// - - - -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_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check_fixed() - { - arma_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_debug_sigprint(); - } - - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - - inline - ~partial_unwrap_check() - { - arma_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_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_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check_htrans_fixed() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_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_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check_htrans2_fixed() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_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_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check_scalar_times_fixed() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_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_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check_neg_fixed() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_debug_sigprint(); - } - - inline - ~partial_unwrap_check() - { - arma_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_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; - }; - - - // // //