[Rcpp-commits] r3602 - pkg/RcppArmadillo/inst/include/armadillo_bits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 10 15:32:01 CEST 2012


Author: edd
Date: 2012-05-10 15:32:00 +0200 (Thu, 10 May 2012)
New Revision: 3602

Modified:
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_htrans_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_strans_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/unwrap.hpp
Log:
RcppArmadillo 0.3.1.92 with Armadillo 3.1.92: three additional files


Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_htrans_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_htrans_meat.hpp	2012-05-10 12:43:03 UTC (rev 3601)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_htrans_meat.hpp	2012-05-10 13:32:00 UTC (rev 3602)
@@ -389,10 +389,13 @@
   
   const Proxy<T1> P(X);
   
-  // allow detection of in-place transpose
-  if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) && (Proxy<T1>::fake_mat == false) )
+  if(
+    (is_Mat<typename Proxy<T1>::stored_type>::value || is_Mat_fixed<typename Proxy<T1>::stored_type>::value)
+    &&
+    (Proxy<T1>::fake_mat == false)  // can't rely on simple alias checking for matrices constructed out of auxiliary memory
+    )
     {
-    const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q);
+    const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q);  // need this unwrap to keep stupid compilers happy
     
     op_htrans2::apply(out, tmp.M, val);
     }

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_strans_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_strans_meat.hpp	2012-05-10 12:43:03 UTC (rev 3601)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_strans_meat.hpp	2012-05-10 13:32:00 UTC (rev 3602)
@@ -209,10 +209,13 @@
   
   const Proxy<T1> P(X);
   
-  // allow detection of in-place transpose
-  if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) && (Proxy<T1>::fake_mat == false) )
+  if(
+    (is_Mat<typename Proxy<T1>::stored_type>::value || is_Mat_fixed<typename Proxy<T1>::stored_type>::value)
+    &&
+    (Proxy<T1>::fake_mat == false)  // can't rely on simple alias checking for matrices constructed out of auxiliary memory
+    )
     {
-    const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q);
+    const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q);  // need this unwrap to keep stupid compilers happy
     
     op_strans::apply(out, tmp.M);
     }

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/unwrap.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/unwrap.hpp	2012-05-10 12:43:03 UTC (rev 3601)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/unwrap.hpp	2012-05-10 13:32:00 UTC (rev 3602)
@@ -21,7 +21,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline unwrap_default(const T1& A)   // TODO: change this to Base ?
+  inline
+  unwrap_default(const T1& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
@@ -33,11 +34,12 @@
 
 
 template<typename T1>
-struct unwrap_Mat_fixed
+struct unwrap_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit unwrap_Mat_fixed(const T1& A)
+  inline explicit
+  unwrap_fixed(const T1& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
@@ -52,18 +54,17 @@
 struct unwrap_redirect {};
 
 template<typename T1>
-struct unwrap_redirect<T1, false> { typedef unwrap_default<T1>   result; };
+struct unwrap_redirect<T1, false> { typedef unwrap_default<T1> result; };
 
 template<typename T1>
-struct unwrap_redirect<T1, true>  { typedef unwrap_Mat_fixed<T1> result; };
+struct unwrap_redirect<T1, true>  { typedef unwrap_fixed<T1>   result; };
 
 
 template<typename T1>
-class unwrap : public unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct unwrap : public unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
-  public:
-  
-  inline unwrap(const T1& A)
+  inline
+  unwrap(const T1& A)
     : unwrap_redirect< T1, is_Mat_fixed<T1>::value >::result(A)
     {
     }
@@ -72,80 +73,278 @@
 
 
 template<typename eT>
-class unwrap< Mat<eT> >
+struct unwrap< Mat<eT> >
   {
-  public:
+  inline
+  unwrap(const Mat<eT>& A)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
   
-  inline unwrap(const Mat<eT>& A)
+  const Mat<eT>& M;
+  };
+
+
+
+template<typename eT>
+struct unwrap< Row<eT> >
+  {
+  inline
+  unwrap(const Row<eT>& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
     }
+  
+  const Row<eT>& M;
+  };
 
+
+
+template<typename eT>
+struct unwrap< Col<eT> >
+  {
+  inline
+  unwrap(const Col<eT>& A)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
+  const Col<eT>& M;
+  };
+
+
+
+template<typename out_eT, typename T1, typename T2, typename glue_type>
+struct unwrap< mtGlue<out_eT, T1, T2, glue_type> >
+  {
+  inline
+  unwrap(const mtGlue<out_eT, T1, T2, glue_type>& A)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
+  const Mat<out_eT> M;
+  };
+
+
+
+template<typename out_eT, typename T1, typename op_type>
+struct unwrap< mtOp<out_eT, T1, op_type> >
+  {
+  inline
+  unwrap(const mtOp<out_eT, T1, op_type>& A)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
+  const Mat<out_eT> M;
+  };
+
+
+
+//
+//
+//
+
+
+
+template<typename T1>
+struct quasi_unwrap_default
+  {
+  typedef typename T1::elem_type eT;
+  
+  static const bool has_subview = false;
+  
+  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 !!!
+  const Mat<eT> M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
+  };
+
+
+
+template<typename T1>
+struct quasi_unwrap_fixed
+  {
+  typedef typename T1::elem_type eT;
+  
+  static const bool has_subview = false;
+  
+  inline explicit
+  quasi_unwrap_fixed(const T1& A)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
   const Mat<eT>& M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) == void_ptr(&X)); }
   };
 
 
 
+template<typename T1, bool condition>
+struct quasi_unwrap_redirect {};
+
+template<typename T1>
+struct quasi_unwrap_redirect<T1, false> { typedef quasi_unwrap_default<T1> result; };
+
+template<typename T1>
+struct quasi_unwrap_redirect<T1, true>  { typedef quasi_unwrap_fixed<T1>   result; };
+
+
+template<typename T1>
+struct quasi_unwrap : public quasi_unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result
+  {
+  typedef typename quasi_unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result quasi_unwrap_extra;
+  
+  static const bool has_subview = quasi_unwrap_extra::has_subview;
+  
+  inline
+  quasi_unwrap(const T1& A)
+    : quasi_unwrap_extra(A)
+    {
+    }
+  
+  using quasi_unwrap_extra::M;
+  using quasi_unwrap_extra::is_alias;
+  };
+
+
+
 template<typename eT>
-class unwrap< Row<eT> >
+struct quasi_unwrap< Mat<eT> >
   {
-  public:
+  static const bool has_subview = false;
   
-  inline unwrap(const Row<eT>& A)
+  inline
+  quasi_unwrap(const Mat<eT>& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
     }
+  
+  const Mat<eT>& M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) == void_ptr(&X)); }
+  };
 
+
+
+template<typename eT>
+struct quasi_unwrap< Row<eT> >
+  {
+  static const bool has_subview = false;
+  
+  inline
+  quasi_unwrap(const Row<eT>& A)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
   const Row<eT>& M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) == void_ptr(&X)); }
   };
 
 
 
 template<typename eT>
-class unwrap< Col<eT> >
+struct quasi_unwrap< Col<eT> >
   {
-  public:
+  static const bool has_subview = false;
   
-  inline unwrap(const Col<eT>& A)
+  inline
+  quasi_unwrap(const Col<eT>& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
     }
-
+  
   const Col<eT>& M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) == void_ptr(&X)); }
   };
 
 
 
+template<typename eT>
+struct quasi_unwrap< subview_col<eT> >
+  {
+  static const bool has_subview = true;
+  
+  inline
+  quasi_unwrap(const subview_col<eT>& A)
+    : M  ( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, false, false )
+    , src( A.m )
+    {
+    arma_extra_debug_sigprint();
+    }
+  
+  const Mat<eT>  M;
+  const Mat<eT>& src;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&src) == void_ptr(&X)); }
+  };
+
+
+
 template<typename out_eT, typename T1, typename T2, typename glue_type>
-class unwrap< mtGlue<out_eT, T1, T2, glue_type> >
+struct quasi_unwrap< mtGlue<out_eT, T1, T2, glue_type> >
   {
-  public:
+  static const bool has_subview = false;
   
-  inline unwrap(const mtGlue<out_eT, T1, T2, glue_type>& A)
+  inline
+  quasi_unwrap(const mtGlue<out_eT, T1, T2, glue_type>& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
     }
   
   const Mat<out_eT> M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
   };
 
 
+
 template<typename out_eT, typename T1, typename op_type>
-class unwrap< mtOp<out_eT, T1, op_type> >
+struct quasi_unwrap< mtOp<out_eT, T1, op_type> >
   {
-  public:
+  static const bool has_subview = false;
   
-  inline unwrap(const mtOp<out_eT, T1, op_type>& A)
+  inline
+  quasi_unwrap(const mtOp<out_eT, T1, op_type>& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
     }
   
   const Mat<out_eT> M;
+  
+  template<typename eT2>
+  arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
   };
 
 
@@ -155,30 +354,97 @@
 //
 
 
+
 template<typename T1>
-class unwrap_check
+struct unwrap_check_default
   {
-  public:
-  
   typedef typename T1::elem_type eT;
   
   inline
-  unwrap_check(const T1& A, const Mat<eT>&)
+  unwrap_check_default(const T1& A, const Mat<eT>&)
     : M(A)
     {
     arma_extra_debug_sigprint();
     }
   
+  inline
+  unwrap_check_default(const T1& A, const bool)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
   const Mat<eT> M;
   };
 
 
 
+template<typename T1>
+struct unwrap_check_fixed
+  {
+  typedef typename T1::elem_type eT;
+  
+  inline
+  unwrap_check_fixed(const T1& A, const Mat<eT>& B)
+    : M_local( (&A == &B) ? new Mat<eT>(A) : 0 )
+    , 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 Mat<eT>(A) : 0 )
+    , 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 Mat<eT>* M_local;
+  const Mat<eT>& M;
+  };
+
+
+
+template<typename T1, bool condition>
+struct unwrap_check_redirect {};
+
+template<typename T1>
+struct unwrap_check_redirect<T1, false> { typedef unwrap_check_default<T1> result; };
+
+template<typename T1>
+struct unwrap_check_redirect<T1, true>  { typedef unwrap_check_fixed<T1>   result; };
+
+
+template<typename T1>
+struct unwrap_check : public unwrap_check_redirect<T1, is_Mat_fixed<T1>::value >::result
+  {
+  inline unwrap_check(const T1& A, const Mat<typename T1::elem_type>& B)
+    : unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(A, B)
+    {
+    }
+  
+  inline unwrap_check(const T1& A, const bool is_alias)
+    : unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(A, is_alias)
+    {
+    }
+  };
+
+
+
 template<typename eT>
-class unwrap_check< Mat<eT> >
+struct unwrap_check< Mat<eT> >
   {
-  public:
-
   inline
   unwrap_check(const Mat<eT>& A, const Mat<eT>& B)
     : M_local( (&A == &B) ? new Mat<eT>(A) : 0 )
@@ -187,6 +453,12 @@
     arma_extra_debug_sigprint();
     }
   
+  unwrap_check(const Mat<eT>& A, const bool is_alias)
+    : M_local( is_alias ? new Mat<eT>(A) : 0 )
+    , M      ( is_alias ? (*M_local)     : A )
+    {
+    arma_extra_debug_sigprint();
+    }
   
   inline
   ~unwrap_check()
@@ -205,18 +477,22 @@
 
 
 template<typename eT>
-class unwrap_check< Row<eT> >
+struct unwrap_check< Row<eT> >
   {
-  public:
-  
   inline
   unwrap_check(const Row<eT>& A, const Mat<eT>& B)
-    : M_local( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? new Row<eT>(A) : 0 )
-    , M      ( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? (*M_local)     : A )
+    : M_local( (&A == &B) ? new Row<eT>(A) : 0 )
+    , M      ( (&A == &B) ? (*M_local)     : A )
     {
     arma_extra_debug_sigprint();
     }
   
+  unwrap_check(const Row<eT>& A, const bool is_alias)
+    : M_local( is_alias ? new Row<eT>(A) : 0 )
+    , M      ( is_alias ? (*M_local)     : A )
+    {
+    arma_extra_debug_sigprint();
+    }
   
   inline
   ~unwrap_check()
@@ -235,18 +511,22 @@
 
 
 template<typename eT>
-class unwrap_check< Col<eT> >
+struct unwrap_check< Col<eT> >
   {
-  public:
-
   inline
   unwrap_check(const Col<eT>& A, const Mat<eT>& B)
-    : M_local( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? new Col<eT>(A) : 0 )
-    , M      ( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? (*M_local)     : A )
+    : M_local( (&A == &B) ? new Col<eT>(A) : 0 )
+    , M      ( (&A == &B) ? (*M_local)     : A )
     {
     arma_extra_debug_sigprint();
     }
   
+  unwrap_check(const Col<eT>& A, const bool is_alias)
+    : M_local( is_alias ? new Col<eT>(A) : 0 )
+    , M      ( is_alias ? (*M_local)     : A )
+    {
+    arma_extra_debug_sigprint();
+    }
   
   inline
   ~unwrap_check()
@@ -260,7 +540,6 @@
   // the order below is important
   const Col<eT>* M_local;
   const Col<eT>& M;
-  
   };
 
 
@@ -272,10 +551,8 @@
 
 
 template<typename T1>
-class unwrap_check_mixed
+struct unwrap_check_mixed
   {
-  public:
-  
   typedef typename T1::elem_type eT1;
   
   template<typename eT2>
@@ -286,16 +563,22 @@
     arma_extra_debug_sigprint();
     }
   
+  template<typename eT2>
+  inline
+  unwrap_check_mixed(const T1& A, const bool)
+    : M(A)
+    {
+    arma_extra_debug_sigprint();
+    }
+  
   const Mat<eT1> M;
   };
 
 
 
 template<typename eT1>
-class unwrap_check_mixed< Mat<eT1> >
+struct unwrap_check_mixed< Mat<eT1> >
   {
-  public:
-  
   template<typename eT2>
   inline
   unwrap_check_mixed(const Mat<eT1>& A, const Mat<eT2>& B)
@@ -305,6 +588,14 @@
     arma_extra_debug_sigprint();
     }
   
+  template<typename eT2>
+  inline
+  unwrap_check_mixed(const Mat<eT1>& A, const bool is_alias)
+    : M_local( is_alias ? new Mat<eT1>(A) : 0 )
+    , M      ( is_alias ? (*M_local)      : A )
+    {
+    arma_extra_debug_sigprint();
+    }
   
   inline
   ~unwrap_check_mixed()
@@ -323,10 +614,8 @@
 
 
 template<typename eT1>
-class unwrap_check_mixed< Row<eT1> >
+struct unwrap_check_mixed< Row<eT1> >
   {
-  public:
-  
   template<typename eT2>
   inline
   unwrap_check_mixed(const Row<eT1>& A, const Mat<eT2>& B)
@@ -337,7 +626,16 @@
     }
   
   
+  template<typename eT2>
   inline
+  unwrap_check_mixed(const Row<eT1>& A, const bool is_alias)
+    : M_local( is_alias ? new Row<eT1>(A) : 0 )
+    , M      ( is_alias ? (*M_local)      : A )
+    {
+    arma_extra_debug_sigprint();
+    }
+  
+  inline
   ~unwrap_check_mixed()
     {
     arma_extra_debug_sigprint();
@@ -354,10 +652,8 @@
 
 
 template<typename eT1>
-class unwrap_check_mixed< Col<eT1> >
+struct unwrap_check_mixed< Col<eT1> >
   {
-  public:
-  
   template<typename eT2>
   inline
   unwrap_check_mixed(const Col<eT1>& A, const Mat<eT2>& B)
@@ -367,6 +663,14 @@
     arma_extra_debug_sigprint();
     }
   
+  template<typename eT2>
+  inline
+  unwrap_check_mixed(const Col<eT1>& A, const bool is_alias)
+    : M_local( is_alias ? new Col<eT1>(A) : 0 )
+    , M      ( is_alias ? (*M_local)      : A )
+    {
+    arma_extra_debug_sigprint();
+    }
   
   inline
   ~unwrap_check_mixed()
@@ -385,6 +689,8 @@
 
 
 //
+//
+//
 
 
 
@@ -393,7 +699,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline partial_unwrap_default(const T1& A)
+  inline
+  partial_unwrap_default(const T1& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
@@ -409,11 +716,12 @@
 
 
 template<typename T1>
-struct partial_unwrap_Mat_fixed
+struct partial_unwrap_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit partial_unwrap_Mat_fixed(const T1& A)
+  inline explicit
+  partial_unwrap_fixed(const T1& A)
     : M(A)
     {
     arma_extra_debug_sigprint();
@@ -433,17 +741,16 @@
 struct partial_unwrap_redirect {};
 
 template<typename T1>
-struct partial_unwrap_redirect<T1, false> { typedef partial_unwrap_default<T1>   result; };
+struct partial_unwrap_redirect<T1, false> { typedef partial_unwrap_default<T1> result; };
 
 template<typename T1>
-struct partial_unwrap_redirect<T1, true>  { typedef partial_unwrap_Mat_fixed<T1> result; };
+struct partial_unwrap_redirect<T1, true>  { typedef partial_unwrap_fixed<T1>   result; };
 
 template<typename T1>
-class partial_unwrap : public partial_unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct partial_unwrap : public partial_unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
-  public:
-  
-  inline partial_unwrap(const T1& A)
+  inline
+  partial_unwrap(const T1& A)
     : partial_unwrap_redirect< T1, is_Mat_fixed<T1>::value >::result(A)
     {
     }
@@ -452,10 +759,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Mat<eT> >
+struct partial_unwrap< Mat<eT> >
   {
-  public:
-  
   inline
   partial_unwrap(const Mat<eT>& A)
     : M(A)
@@ -474,10 +779,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Row<eT> >
+struct partial_unwrap< Row<eT> >
   {
-  public:
-  
   inline
   partial_unwrap(const Row<eT>& A)
     : M(A)
@@ -496,10 +799,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Col<eT> >
+struct partial_unwrap< Col<eT> >
   {
-  public:
-  
   inline
   partial_unwrap(const Col<eT>& A)
     : M(A)
@@ -517,14 +818,15 @@
 
 
 
+// NOTE: we can get away with this shortcut as the partial_unwrap class is only used by as_scalar(),
+// NOTE: which doesn't need to check for aliasing (ie. it doesn't need to compare the address of M with another matrix)
 template<typename eT>
-class partial_unwrap< subview_col<eT> >
+struct partial_unwrap< subview_col<eT> >
   {
-  public:
-  
   inline
   partial_unwrap(const subview_col<eT>& A)
-    : M( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, false, false )
+    : M  ( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, false, false )
+    //, ref( A )
     {
     arma_extra_debug_sigprint();
     }
@@ -535,6 +837,9 @@
   static const bool do_times = false;
   
   const Mat<eT> M;
+  
+  //// prevents the compiler from potentially deleting the subview object before we're done with it
+  //const subview_col<eT>& ref;
   };
 
 
@@ -544,7 +849,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline partial_unwrap_htrans_default(const Op<T1, op_htrans>& A)
+  inline
+  partial_unwrap_htrans_default(const Op<T1, op_htrans>& A)
     : M(A.m)
     {
     arma_extra_debug_sigprint();
@@ -560,11 +866,12 @@
 
 
 template<typename T1>
-struct partial_unwrap_htrans_Mat_fixed
+struct partial_unwrap_htrans_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit partial_unwrap_htrans_Mat_fixed(const Op<T1, op_htrans>& A)
+  inline explicit
+  partial_unwrap_htrans_fixed(const Op<T1, op_htrans>& A)
     : M(A.m)
     {
     arma_extra_debug_sigprint();
@@ -584,16 +891,14 @@
 struct partial_unwrap_htrans_redirect {};
 
 template<typename T1>
-struct partial_unwrap_htrans_redirect<T1, false> { typedef partial_unwrap_htrans_default<T1>   result; };
+struct partial_unwrap_htrans_redirect<T1, false> { typedef partial_unwrap_htrans_default<T1> result; };
 
 template<typename T1>
-struct partial_unwrap_htrans_redirect<T1, true>  { typedef partial_unwrap_htrans_Mat_fixed<T1> result; };
+struct partial_unwrap_htrans_redirect<T1, true>  { typedef partial_unwrap_htrans_fixed<T1>   result; };
 
 template<typename T1>
-class partial_unwrap< Op<T1, op_htrans> > : public partial_unwrap_htrans_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct partial_unwrap< Op<T1, op_htrans> > : public partial_unwrap_htrans_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
-  public:
-  
   inline partial_unwrap(const Op<T1, op_htrans>& A)
     : partial_unwrap_htrans_redirect< T1, is_Mat_fixed<T1>::value >::result(A)
     {
@@ -603,10 +908,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Op< Mat<eT>, op_htrans> >
+struct partial_unwrap< Op< Mat<eT>, op_htrans> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< Mat<eT>, op_htrans>& A)
     : M(A.m)
@@ -625,10 +928,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Op< Row<eT>, op_htrans> >
+struct partial_unwrap< Op< Row<eT>, op_htrans> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< Row<eT>, op_htrans>& A)
     : M(A.m)
@@ -647,10 +948,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Op< Col<eT>, op_htrans> >
+struct partial_unwrap< Op< Col<eT>, op_htrans> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< Col<eT>, op_htrans>& A)
     : M(A.m)
@@ -668,14 +967,15 @@
 
 
 
+// NOTE: we can get away with this shortcut as the partial_unwrap class is only used by as_scalar(),
+// NOTE: which doesn't need to check for aliasing (ie. it doesn't need to compare the address of M with another matrix)
 template<typename eT>
-class partial_unwrap< Op< subview_col<eT>, op_htrans> >
+struct partial_unwrap< Op< subview_col<eT>, op_htrans> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< subview_col<eT>, op_htrans>& A)
-    : M( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false )
+    : M  ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false )
+    //, ref( A )
     {
     arma_extra_debug_sigprint();
     }
@@ -686,6 +986,9 @@
   static const bool do_times = false;
   
   const Mat<eT> M;
+  
+  //// prevents the compiler from potentially deleting the subview object before we're done with it
+  //const Op< subview_col<eT>, op_htrans>& ref;
   };
 
 
@@ -695,7 +998,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline partial_unwrap_htrans2_default(const Op<T1, op_htrans2>& A)
+  inline
+  partial_unwrap_htrans2_default(const Op<T1, op_htrans2>& A)
     : val(A.aux)
     , M  (A.m)
     {
@@ -713,11 +1017,12 @@
 
 
 template<typename T1>
-struct partial_unwrap_htrans2_Mat_fixed
+struct partial_unwrap_htrans2_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit partial_unwrap_htrans2_Mat_fixed(const Op<T1, op_htrans2>& A)
+  inline explicit
+  partial_unwrap_htrans2_fixed(const Op<T1, op_htrans2>& A)
     : val(A.aux)
     , M  (A.m)
     {
@@ -739,16 +1044,14 @@
 struct partial_unwrap_htrans2_redirect {};
 
 template<typename T1>
-struct partial_unwrap_htrans2_redirect<T1, false> { typedef partial_unwrap_htrans2_default<T1>   result; };
+struct partial_unwrap_htrans2_redirect<T1, false> { typedef partial_unwrap_htrans2_default<T1> result; };
 
 template<typename T1>
-struct partial_unwrap_htrans2_redirect<T1, true>  { typedef partial_unwrap_htrans2_Mat_fixed<T1> result; };
+struct partial_unwrap_htrans2_redirect<T1, true>  { typedef partial_unwrap_htrans2_fixed<T1>   result; };
 
 template<typename T1>
-class partial_unwrap< Op<T1, op_htrans2> > : public partial_unwrap_htrans2_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct partial_unwrap< Op<T1, op_htrans2> > : public partial_unwrap_htrans2_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
-  public:
-  
   inline partial_unwrap(const Op<T1, op_htrans2>& A)
     : partial_unwrap_htrans2_redirect< T1, is_Mat_fixed<T1>::value >::result(A)
     {
@@ -758,10 +1061,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Op< Mat<eT>, op_htrans2> >
+struct partial_unwrap< Op< Mat<eT>, op_htrans2> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< Mat<eT>, op_htrans2>& A)
     : val(A.aux)
@@ -782,10 +1083,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Op< Row<eT>, op_htrans2> >
+struct partial_unwrap< Op< Row<eT>, op_htrans2> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< Row<eT>, op_htrans2>& A)
     : val(A.aux)
@@ -806,10 +1105,8 @@
 
 
 template<typename eT>
-class partial_unwrap< Op< Col<eT>, op_htrans2> >
+struct partial_unwrap< Op< Col<eT>, op_htrans2> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< Col<eT>, op_htrans2>& A)
     : val(A.aux)
@@ -829,15 +1126,16 @@
 
 
 
+// NOTE: we can get away with this shortcut as the partial_unwrap class is only used by as_scalar(),
+// NOTE: which doesn't need to check for aliasing (ie. it doesn't need to compare the address of M with another matrix)
 template<typename eT>
-class partial_unwrap< Op< subview_col<eT>, op_htrans2> >
+struct partial_unwrap< Op< subview_col<eT>, op_htrans2> >
   {
-  public:
-  
   inline
   partial_unwrap(const Op< subview_col<eT>, op_htrans2>& A)
     : val( A.aux )
     , M  ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false )
+    //, ref( A )
     {
     arma_extra_debug_sigprint();
     }
@@ -849,6 +1147,9 @@
   
   const eT      val;
   const Mat<eT> M;
+
+  //// prevents the compiler from potentially deleting the subview object before we're done with it
+  //const Op< subview_col<eT>, op_htrans2>& ref;
   };
 
 
@@ -858,7 +1159,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline partial_unwrap_scalar_times_default(const eOp<T1, eop_scalar_times>& A)
+  inline
+  partial_unwrap_scalar_times_default(const eOp<T1, eop_scalar_times>& A)
     : val(A.aux)
     , M  (A.P.Q)
     {
@@ -877,11 +1179,12 @@
 
 
 template<typename T1>
-struct partial_unwrap_scalar_times_Mat_fixed
+struct partial_unwrap_scalar_times_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit partial_unwrap_scalar_times_Mat_fixed(const eOp<T1, eop_scalar_times>& A)
+  inline explicit
+  partial_unwrap_scalar_times_fixed(const eOp<T1, eop_scalar_times>& A)
     : val(A.aux)
     , M  (A.P.Q)
     {
@@ -903,19 +1206,19 @@
 struct partial_unwrap_scalar_times_redirect {};
 
 template<typename T1>
-struct partial_unwrap_scalar_times_redirect<T1, false> { typedef partial_unwrap_scalar_times_default<T1>   result; };
+struct partial_unwrap_scalar_times_redirect<T1, false> { typedef partial_unwrap_scalar_times_default<T1> result; };
 
 template<typename T1>
-struct partial_unwrap_scalar_times_redirect<T1, true>  { typedef partial_unwrap_scalar_times_Mat_fixed<T1> result; };
+struct partial_unwrap_scalar_times_redirect<T1, true>  { typedef partial_unwrap_scalar_times_fixed<T1>   result; };
 
 
 template<typename T1>
-class partial_unwrap< eOp<T1, eop_scalar_times> > : public partial_unwrap_scalar_times_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct partial_unwrap< eOp<T1, eop_scalar_times> > : public partial_unwrap_scalar_times_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
   typedef typename T1::elem_type eT;
   
-  public:
-  inline partial_unwrap(const eOp<T1, eop_scalar_times>& A)
+  inline
+  partial_unwrap(const eOp<T1, eop_scalar_times>& A)
     : partial_unwrap_scalar_times_redirect< T1, is_Mat_fixed<T1>::value >::result(A)
     {
     }
@@ -924,10 +1227,8 @@
 
 
 template<typename eT>
-class partial_unwrap< eOp<Mat<eT>, eop_scalar_times> >
+struct partial_unwrap< eOp<Mat<eT>, eop_scalar_times> >
   {
-  public:
-  
   inline
   partial_unwrap(const eOp<Mat<eT>,eop_scalar_times>& A)
     : val(A.aux)
@@ -948,10 +1249,8 @@
 
 
 template<typename eT>
-class partial_unwrap< eOp<Row<eT>, eop_scalar_times> >
+struct partial_unwrap< eOp<Row<eT>, eop_scalar_times> >
   {
-  public:
-  
   inline
   partial_unwrap(const eOp<Row<eT>,eop_scalar_times>& A)
     : val(A.aux)
@@ -972,10 +1271,8 @@
 
 
 template<typename eT>
-class partial_unwrap< eOp<Col<eT>, eop_scalar_times> >
+struct partial_unwrap< eOp<Col<eT>, eop_scalar_times> >
   {
-  public:
-  
   inline
   partial_unwrap(const eOp<Col<eT>,eop_scalar_times>& A)
     : val(A.aux)
@@ -1004,7 +1301,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline partial_unwrap_check_default(const T1& A, const Mat<eT>&)
+  inline
+  partial_unwrap_check_default(const T1& A, const Mat<eT>&)
     : M(A)
     {
     arma_extra_debug_sigprint();
@@ -1020,11 +1318,12 @@
 
 
 template<typename T1>
-struct partial_unwrap_check_Mat_fixed
+struct partial_unwrap_check_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit partial_unwrap_check_Mat_fixed(const T1& A, const Mat<eT>& B)
+  inline explicit
+  partial_unwrap_check_fixed(const T1& A, const Mat<eT>& B)
     : M_local( (&A == &B) ? new Mat<eT>(A) : 0 )
     , M      ( (&A == &B) ? (*M_local)     : A )
     {
@@ -1032,7 +1331,7 @@
     }
   
   inline
-  ~partial_unwrap_check_Mat_fixed()
+  ~partial_unwrap_check_fixed()
     {
     arma_extra_debug_sigprint();
     
@@ -1054,17 +1353,16 @@
 struct partial_unwrap_check_redirect {};
 
 template<typename T1>
-struct partial_unwrap_check_redirect<T1, false> { typedef partial_unwrap_check_default<T1>   result; };
+struct partial_unwrap_check_redirect<T1, false> { typedef partial_unwrap_check_default<T1> result; };
 
 template<typename T1>
-struct partial_unwrap_check_redirect<T1, true>  { typedef partial_unwrap_check_Mat_fixed<T1> result; };
+struct partial_unwrap_check_redirect<T1, true>  { typedef partial_unwrap_check_fixed<T1>   result; };
 
 template<typename T1>
-class partial_unwrap_check : public partial_unwrap_check_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct partial_unwrap_check : public partial_unwrap_check_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
   typedef typename T1::elem_type eT;
   
-  public:
   inline partial_unwrap_check(const T1& A, const Mat<eT>& B)
     : partial_unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(A, B)
     {
@@ -1074,10 +1372,8 @@
 
 
 template<typename eT>
-class partial_unwrap_check< Mat<eT> >
+struct partial_unwrap_check< Mat<eT> >
   {
-  public:
-  
   arma_hot inline
   partial_unwrap_check(const Mat<eT>& A, const Mat<eT>& B)
     : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 )
@@ -1108,10 +1404,8 @@
 
 
 template<typename eT>
-class partial_unwrap_check< Row<eT> >
+struct partial_unwrap_check< Row<eT> >
   {
-  public:
-  
   arma_hot inline
   partial_unwrap_check(const Row<eT>& A, const Mat<eT>& B)
     : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 )
@@ -1142,10 +1436,8 @@
 
 
 template<typename eT>
-class partial_unwrap_check< Col<eT> >
+struct partial_unwrap_check< Col<eT> >
   {
-  public:
-  
   arma_hot inline
   partial_unwrap_check(const Col<eT>& A, const Mat<eT>& B)
     : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 )
@@ -1175,14 +1467,15 @@
 
 
 
+// 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<typename eT>
-class partial_unwrap_check< subview_col<eT> >
+struct partial_unwrap_check< subview_col<eT> >
   {
-  public:
-  
   arma_hot inline
   partial_unwrap_check(const subview_col<eT>& A, const Mat<eT>& B)
-    : M( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, (&(A.m) == &B), false )
+    : M  ( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, (&(A.m) == &B), false )
+    //, ref( A )
     {
     arma_extra_debug_sigprint();
     }
@@ -1193,6 +1486,9 @@
   static const bool do_times = false;
   
   const Mat<eT> M;
+
+  //// prevents the compiler from potentially deleting the subview object before we're done with it
+  //const subview_col<eT>& ref;
   };
 
 
@@ -1202,7 +1498,8 @@
   {
   typedef typename T1::elem_type eT;
   
-  inline partial_unwrap_check_htrans_default(const Op<T1, op_htrans>& A, const Mat<eT>&)
+  inline
+  partial_unwrap_check_htrans_default(const Op<T1, op_htrans>& A, const Mat<eT>&)
     : M(A.m)
     {
     arma_extra_debug_sigprint();
@@ -1218,11 +1515,12 @@
 
 
 template<typename T1>
-struct partial_unwrap_check_htrans_Mat_fixed
+struct partial_unwrap_check_htrans_fixed
   {
   typedef typename T1::elem_type eT;
   
-  inline explicit partial_unwrap_check_htrans_Mat_fixed(const Op<T1, op_htrans>& A, const Mat<eT>& B)
+  inline explicit
+  partial_unwrap_check_htrans_fixed(const Op<T1, op_htrans>& A, const Mat<eT>& B)
     : M_local( (&(A.m) == &B) ? new Mat<eT>(A.m) : 0   )
     , M      ( (&(A.m) == &B) ? (*M_local)       : A.m )
     {
@@ -1230,7 +1528,7 @@
     }
   
   inline
-  ~partial_unwrap_check_htrans_Mat_fixed()
+  ~partial_unwrap_check_htrans_fixed()
     {
     arma_extra_debug_sigprint();
     
@@ -1252,18 +1550,17 @@
 struct partial_unwrap_check_htrans_redirect {};
 
 template<typename T1>
-struct partial_unwrap_check_htrans_redirect<T1, false> { typedef partial_unwrap_check_htrans_default<T1>   result; };
+struct partial_unwrap_check_htrans_redirect<T1, false> { typedef partial_unwrap_check_htrans_default<T1> result; };
 
 template<typename T1>
-struct partial_unwrap_check_htrans_redirect<T1, true>  { typedef partial_unwrap_check_htrans_Mat_fixed<T1> result; };
+struct partial_unwrap_check_htrans_redirect<T1, true>  { typedef partial_unwrap_check_htrans_fixed<T1>   result; };
 
 
 template<typename T1>
-class partial_unwrap_check< Op<T1, op_htrans> > : public partial_unwrap_check_htrans_redirect<T1, is_Mat_fixed<T1>::value >::result
+struct partial_unwrap_check< Op<T1, op_htrans> > : public partial_unwrap_check_htrans_redirect<T1, is_Mat_fixed<T1>::value >::result
   {
   typedef typename T1::elem_type eT;
   
-  public:
   inline partial_unwrap_check(const Op<T1, op_htrans>& A, const Mat<eT>& B)
     : partial_unwrap_check_htrans_redirect< T1, is_Mat_fixed<T1>::value >::result(A, B)
     {
@@ -1273,10 +1570,8 @@
 
 
 template<typename eT>
-class partial_unwrap_check< Op< Mat<eT>, op_htrans> >
+struct partial_unwrap_check< Op< Mat<eT>, op_htrans> >
   {
-  public:
-  
   arma_hot inline
   partial_unwrap_check(const Op< Mat<eT>, op_htrans>& A, const Mat<eT>& B)
     : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0   )
@@ -1306,10 +1601,8 @@
 
 
 template<typename eT>
-class partial_unwrap_check< Op< Row<eT>, op_htrans> >
+struct partial_unwrap_check< Op< Row<eT>, op_htrans> >
   {
-  public:
-  
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rcpp -r 3602


More information about the Rcpp-commits mailing list