[Rcpp-commits] r3098 - in pkg/RcppArmadillo: . inst inst/include inst/include/armadillo_bits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 23 15:49:18 CEST 2011


Author: edd
Date: 2011-06-23 15:49:17 +0200 (Thu, 23 Jun 2011)
New Revision: 3098

Removed:
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_princomp_cov.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_princomp_cov_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_princomp_cov_meat.hpp
Modified:
   pkg/RcppArmadillo/ChangeLog
   pkg/RcppArmadillo/DESCRIPTION
   pkg/RcppArmadillo/inst/NEWS
   pkg/RcppArmadillo/inst/include/armadillo
   pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/config.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/debug.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/field_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_chol.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_eig.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_inv.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_log_det.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_lu.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_misc.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_pinv.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_princomp.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_qr.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_rank.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_solve.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_svd.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/fn_syl_lyap.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/forward_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/glue_join_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/glue_solve_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/lapack_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_chol_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_inv_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_inv_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_median_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_min_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_misc_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_misc_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_pinv_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_princomp_bones.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_princomp_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_prod_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_stddev_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_sum_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/op_var_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/running_stat_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/running_stat_vec_meat.hpp
Log:
Release 0.2.3 using RcppArmadillo 1.99.5

Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/ChangeLog	2011-06-23 13:49:17 UTC (rev 3098)
@@ -1,3 +1,9 @@
+2011-06-23  Dirk Eddelbuettel  <edd at debian.org>
+
+	* DESCRIPTION: Release 0.2.23
+
+	* inst/include/*: Updated to release 1.99.5 of Armadillo
+
 2011-06-14  Douglas Bates <bates at stat.wisc.edu>
 
 	* R/fastLm.R, inst/unitTests/runit.fastLm.R, man/fastLm.Rd,

Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/DESCRIPTION	2011-06-23 13:49:17 UTC (rev 3098)
@@ -1,7 +1,7 @@
 Package: RcppArmadillo
 Type: Package
 Title: Rcpp integration for Armadillo templated linear algebra library
-Version: 0.2.22.1
+Version: 0.2.23
 Date: $Date$
 Author: Romain Francois, Dirk Eddelbuettel and Doug Bates
 Maintainer: Romain Francois, Dirk Eddelbuettel and Doug Bates <RcppArmadillo-authors at r-enthusiasts.com>
@@ -21,7 +21,7 @@
  (due to speed and/or integration capabilities), rather than another language.
  .
  The RcppArmadillo package includes the header files from the templated
- Armadillo library (currently version 1.99.4). Thus users do not need to
+ Armadillo library (currently version 1.99.5). Thus users do not need to
  install Armadillo itself in order to use RcppArmadillo.
  .
  This Armadillo integration provides a nice illustration of the 

Modified: pkg/RcppArmadillo/inst/NEWS
===================================================================
--- pkg/RcppArmadillo/inst/NEWS	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/NEWS	2011-06-23 13:49:17 UTC (rev 3098)
@@ -1,5 +1,19 @@
-0.2.23  2011-xx-yy
+0.2.23  2011-05-23
 
+    o   Upgraded to Armadillo release 1.99.5 "v2.0 beta 5"
+
+          * Forms of chol(), eig_sym(), eig_gen(), inv(), lu(), pinv(),
+	    princomp(), qr(), solve(), svd(), syl() that do not return a bool
+	    indicating success now throw std::runtime_error exceptions when
+	    failures are detected 
+          * princomp_cov() has been removed; princomp() in conjunction with
+	    cov() can be used instead
+          * set_log_stream() & get_log_stream() have been replaced by
+	    set_stream_err1() & get_stream_err1()
+          * det(), inv() and solve() can be forced to use more precise
+	    algorithms for tiny matrices (≤ 4x4)
+          * Added loading & saving of matrices as CSV text files 
+
     o   fastLmPure() now uses same argument order as R's lm.fit()
 
     o   Export and document S3 methods in NAMESPACE and manual page as such

Modified: pkg/RcppArmadillo/inst/include/armadillo
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo	2011-06-23 13:49:17 UTC (rev 3098)
@@ -202,7 +202,6 @@
   #include "armadillo_bits/op_dotext_bones.hpp"
   #include "armadillo_bits/op_flip_bones.hpp"
   #include "armadillo_bits/op_princomp_bones.hpp"
-  #include "armadillo_bits/op_princomp_cov_bones.hpp"
   #include "armadillo_bits/op_misc_bones.hpp"
   #include "armadillo_bits/op_relational_bones.hpp"
   #include "armadillo_bits/op_find_bones.hpp"
@@ -349,7 +348,6 @@
   #include "armadillo_bits/fn_flip.hpp"
   #include "armadillo_bits/fn_as_scalar.hpp"
   #include "armadillo_bits/fn_princomp.hpp"
-  #include "armadillo_bits/fn_princomp_cov.hpp"
   #include "armadillo_bits/fn_cross.hpp"
   #include "armadillo_bits/fn_join.hpp"
   #include "armadillo_bits/fn_conv.hpp"
@@ -417,7 +415,6 @@
   #include "armadillo_bits/op_dotext_meat.hpp"
   #include "armadillo_bits/op_flip_meat.hpp"
   #include "armadillo_bits/op_princomp_meat.hpp"
-  #include "armadillo_bits/op_princomp_cov_meat.hpp"
   #include "armadillo_bits/op_misc_meat.hpp"
   #include "armadillo_bits/op_relational_meat.hpp"
   #include "armadillo_bits/op_find_meat.hpp"

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -170,7 +170,7 @@
         
         access::rw(mem) = new(std::nothrow) eT[new_n_elem];
       
-        arma_check( (mem == 0), "Cube::init(): out of memory" );
+        arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" );
         }
       
       if(new_n_elem > 0)
@@ -337,7 +337,7 @@
       {
       access::rw(mat_ptrs) = new(std::nothrow) const Mat<eT>*[n_slices];
       
-      arma_check( (mat_ptrs == 0), "Cube::create_mat(): out of memory" );
+      arma_check_bad_alloc( (mat_ptrs == 0), "Cube::create_mat(): out of memory" );
       }
     }
   
@@ -2668,11 +2668,11 @@
     {
     if(err_msg.length() > 0)
       {
-      arma_print("Cube::load(): ", err_msg, name);
+      arma_warn(true, "Cube::load(): ", err_msg, name);
       }
     else
       {
-      arma_print("Cube::load(): couldn't read ", name);
+      arma_warn(true, "Cube::load(): couldn't read ", name);
       }
     }
   
@@ -2733,11 +2733,11 @@
     {
     if(err_msg.length() > 0)
       {
-      arma_print("Cube::load(): ", err_msg, "the given stream");
+      arma_warn(true, "Cube::load(): ", err_msg, "the given stream");
       }
     else
       {
-      arma_print("Cube::load(): couldn't load from the given stream");
+      arma_warn(true, "Cube::load(): couldn't load from the given stream");
       }
     }
   

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -255,6 +255,8 @@
   
   arma_inline arma_warn_unused bool is_empty()  const;
   arma_inline arma_warn_unused bool is_vec()    const;
+  arma_inline arma_warn_unused bool is_rowvec() const;
+  arma_inline arma_warn_unused bool is_colvec() const;
   arma_inline arma_warn_unused bool is_square() const;
        inline arma_warn_unused bool is_finite() const;
   

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -182,7 +182,7 @@
         
         access::rw(mem) = new(std::nothrow) eT[new_n_elem];
         
-        arma_check( (mem == 0), "Mat::init(): out of memory" );
+        arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" );
         }
       
       access::rw(n_elem)    = new_n_elem;
@@ -2406,34 +2406,60 @@
   const unwrap<T1>   tmp(X.get_ref());
   const Mat<eT>& C = tmp.M;
   
-  const u32 N = C.n_rows;
+  const u32 C_n_rows = C.n_rows;
+  const u32 C_n_cols = C.n_cols;
   
   const u32 t_n_rows = n_rows;
   const u32 t_n_cols = n_cols;
   
   const u32 A_n_rows = row_num;
   const u32 B_n_rows = t_n_rows - row_num;
-
+  
+  bool  err_state = false;
+  char* err_msg   = 0;
+  
   // insertion at row_num == n_rows is in effect an append operation
-  arma_debug_check( (row_num  >  t_n_rows), "Mat::insert_rows(): out of bounds");
-  arma_debug_check( (C.n_cols != t_n_cols), "Mat::insert_rows(): given object has an incompatible number of columns");
   
-  if(N > 0)
+  arma_debug_set_error
+    (
+    err_state,
+    err_msg,
+    (row_num > t_n_rows),
+    "Mat::insert_rows(): out of bounds"
+    );
+  
+  arma_debug_set_error
+    (
+    err_state,
+    err_msg,
+    ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ),
+    "Mat::insert_rows(): given object has an incompatible number of columns"
+    );
+  
+  arma_debug_check(err_state, err_msg);
+  
+  if(C_n_rows > 0)
     {
-    Mat<eT> out(t_n_rows + N, t_n_cols);
+    Mat<eT> out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) );
     
-    if(A_n_rows > 0)
+    if(t_n_cols > 0)
       {
-      out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1);
+      if(A_n_rows > 0)
+        {
+        out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1);
+        }
+      
+      if( (t_n_cols > 0) && (B_n_rows > 0) )
+        {
+        out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1);
+        }
       }
     
-    if(B_n_rows > 0)
+    if(C_n_cols > 0)
       {
-      out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows - 1);
+      out.rows(row_num, row_num + C_n_rows - 1) = C;
       }
     
-    out.rows(row_num, row_num + N - 1) = C;
-    
     steal_mem(out);
     }
   }
@@ -2453,34 +2479,60 @@
   const unwrap<T1>   tmp(X.get_ref());
   const Mat<eT>& C = tmp.M;
   
-  const u32 N = C.n_cols;
+  const u32 C_n_rows = C.n_rows;
+  const u32 C_n_cols = C.n_cols;
   
   const u32 t_n_rows = n_rows;
   const u32 t_n_cols = n_cols;
   
   const u32 A_n_cols = col_num;
   const u32 B_n_cols = t_n_cols - col_num;
-
+  
+  bool  err_state = false;
+  char* err_msg   = 0;
+  
   // insertion at col_num == n_cols is in effect an append operation
-  arma_debug_check( (col_num  >  t_n_cols), "Mat::insert_cols(): out of bounds");
-  arma_debug_check( (C.n_rows != t_n_rows), "Mat::insert_cols(): given object has an incompatible number of rows");
   
-  if(N > 0)
+  arma_debug_set_error
+    (
+    err_state,
+    err_msg,
+    (col_num > t_n_cols),
+    "Mat::insert_cols(): out of bounds"
+    );
+  
+  arma_debug_set_error
+    (
+    err_state,
+    err_msg,
+    ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ),
+    "Mat::insert_cols(): given object has an incompatible number of rows"
+    );
+  
+  arma_debug_check(err_state, err_msg);
+  
+  if(C_n_cols > 0)
     {
-    Mat<eT> out(t_n_rows, t_n_cols + N);
+    Mat<eT> out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols );
     
-    if(A_n_cols > 0)
+    if(t_n_rows > 0)
       {
-      out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1);
+      if(A_n_cols > 0)
+        {
+        out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1);
+        }
+      
+      if(B_n_cols > 0)
+        {
+        out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1);
+        }
       }
     
-    if(B_n_cols > 0)
+    if(C_n_rows > 0)
       {
-      out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols - 1);
+      out.cols(col_num, col_num + C_n_cols - 1) = C;
       }
     
-    out.cols(col_num, col_num + N - 1) = C;
-    
     steal_mem(out);
     }
   }
@@ -3467,6 +3519,30 @@
 
 
 
+//! returns true if the object can be interpreted as a row vector
+template<typename eT>
+arma_inline
+arma_warn_unused
+bool
+Mat<eT>::is_rowvec() const
+  {
+  return (n_rows == 1);
+  }
+
+
+
+//! returns true if the object can be interpreted as a column vector
+template<typename eT>
+arma_inline
+arma_warn_unused
+bool
+Mat<eT>::is_colvec() const
+  {
+  return (n_cols == 1);
+  }
+
+
+
 //! returns true if the object has the same number of non-zero rows and columnns
 template<typename eT>
 arma_inline
@@ -4303,6 +4379,10 @@
       save_okay = diskio::save_arma_ascii(*this, name);
       break;
     
+    case csv_ascii:
+      save_okay = diskio::save_csv_ascii(*this, name);
+      break;
+    
     case raw_binary:
       save_okay = diskio::save_raw_binary(*this, name);
       break;
@@ -4347,6 +4427,10 @@
       save_okay = diskio::save_arma_ascii(*this, os);
       break;
     
+    case csv_ascii:
+      save_okay = diskio::save_csv_ascii(*this, os);
+      break;
+    
     case raw_binary:
       save_okay = diskio::save_raw_binary(*this, os);
       break;
@@ -4396,6 +4480,10 @@
       load_okay = diskio::load_arma_ascii(*this, name, err_msg);
       break;
     
+    case csv_ascii:
+      load_okay = diskio::load_csv_ascii(*this, name, err_msg);
+      break;
+    
     case raw_binary:
       load_okay = diskio::load_raw_binary(*this, name, err_msg);
       break;
@@ -4417,11 +4505,11 @@
     {
     if(err_msg.length() > 0)
       {
-      arma_print("Mat::load(): ", err_msg, name);
+      arma_warn(true, "Mat::load(): ", err_msg, name);
       }
     else
       {
-      arma_print("Mat::load(): couldn't read ", name);
+      arma_warn(true, "Mat::load(): couldn't read ", name);
       }
     }
   
@@ -4460,6 +4548,10 @@
       load_okay = diskio::load_arma_ascii(*this, is, err_msg);
       break;
     
+    case csv_ascii:
+      load_okay = diskio::load_csv_ascii(*this, is, err_msg);
+      break;
+    
     case raw_binary:
       load_okay = diskio::load_raw_binary(*this, is, err_msg);
       break;
@@ -4482,11 +4574,11 @@
     {
     if(err_msg.length() > 0)
       {
-      arma_print("Mat::load(): ", err_msg, "the given stream");
+      arma_warn(true, "Mat::load(): ", err_msg, "the given stream");
       }
     else
       {
-      arma_print("Mat::load(): couldn't load from the given stream");
+      arma_warn(true, "Mat::load(): couldn't load from the given stream");
       }
     }
   

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -18,8 +18,8 @@
 
 #define ARMA_VERSION_MAJOR 1
 #define ARMA_VERSION_MINOR 99
-#define ARMA_VERSION_PATCH 4
-#define ARMA_VERSION_NAME  "v2.0 beta 4"
+#define ARMA_VERSION_PATCH 5
+#define ARMA_VERSION_NAME  "v2.0 beta 5"
 
 
 

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_bones.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_bones.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_bones.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -66,6 +66,13 @@
   
   
   //
+  // inv_sympd
+  
+  template<typename eT, typename T1>
+  inline static bool inv_sympd(Mat<eT>& out, const Base<eT,T1>& X, const u32 layout);
+  
+  
+  //
   // det
   
   template<typename eT, typename T1>
@@ -82,20 +89,20 @@
   // log_det
   
   template<typename eT, typename T1>
-  inline static void log_det(eT& out_val, typename get_pod_type<eT>::result& out_sign, const Base<eT,T1>& X);
+  inline static bool log_det(eT& out_val, typename get_pod_type<eT>::result& out_sign, const Base<eT,T1>& X);
   
   
   //
   // lu
   
   template<typename eT, typename T1>
-  inline static void lu(Mat<eT>& L, Mat<eT>& U, podarray<blas_int>& ipiv, const Base<eT,T1>& X);
+  inline static bool lu(Mat<eT>& L, Mat<eT>& U, podarray<blas_int>& ipiv, const Base<eT,T1>& X);
   
   template<typename eT, typename T1>
-  inline static void lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Base<eT,T1>& X);
+  inline static bool lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Base<eT,T1>& X);
   
   template<typename eT, typename T1>
-  inline static void lu(Mat<eT>& L, Mat<eT>& U, const Base<eT,T1>& X);
+  inline static bool lu(Mat<eT>& L, Mat<eT>& U, const Base<eT,T1>& X);
   
   
   //

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_meat.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/auxlib_meat.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -1,7 +1,8 @@
 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
 // Copyright (C) 2008-2011 Conrad Sanderson
-// Copyright (C)      2009 Edmund Highcock
-// Copyright (C)      2011 James Sanders
+// Copyright (C) 2009 Edmund Highcock
+// Copyright (C) 2011 James Sanders
+// Copyright (C) 2011 Stanislav Funiak
 // 
 // This file is part of the Armadillo C++ library.
 // It is provided without any warranty of fitness
@@ -44,12 +45,6 @@
     status = auxlib::inv_inplace_lapack(out);
     }
   
-  if(status == false)
-    {
-    arma_print("inv(): matrix appears to be singular" );
-    out.reset();
-    }
-  
   return status;
   }
 
@@ -79,12 +74,6 @@
     status = auxlib::inv_inplace_lapack(out);
     }
   
-  if(status == false)
-    {
-    arma_print("inv(): matrix appears to be singular" );
-    out.reset();
-    }
-  
   return status;
   }
 
@@ -364,6 +353,11 @@
 auxlib::inv_inplace_lapack(Mat<eT>& out)
   {
   arma_extra_debug_sigprint();
+
+  if(out.is_empty())
+    {
+    return true;
+    }
   
   #if defined(ARMA_USE_ATLAS)
     {
@@ -470,13 +464,8 @@
   #endif
   
   
-  if(status == false)
+  if(status == true)
     {
-    arma_print("inv(): matrix appears to be singular" );
-    out.reset();
-    }
-  else
-    {
     if(layout == 0)
       {
       // upper triangular
@@ -514,16 +503,79 @@
   
   #if defined(ARMA_USE_LAPACK)
     {
+    char     uplo  = (layout == 0) ? 'U' : 'L';
+    blas_int n     = blas_int(out.n_rows);
+    blas_int lwork = n*n; // TODO: use lwork = -1 to determine optimal size
+    blas_int info  = 0;
+    
+    podarray<blas_int> ipiv;
+    ipiv.set_size(out.n_rows);
+    
+    podarray<eT> work;
+    work.set_size( u32(lwork) );
+    
+    lapack::sytrf(&uplo, &n, out.memptr(), &n, ipiv.memptr(), work.memptr(), &lwork, &info);
+    
+    status = (info == 0);
+    
+    if(status == true)
+      {
+      lapack::sytri(&uplo, &n, out.memptr(), &n, ipiv.memptr(), work.memptr(), &info);
+      
+      out = (layout == 0) ? symmatu(out) : symmatl(out);
+      
+      status = (info == 0);
+      }
+    }
+  #else
+    {
+    arma_ignore(layout);
+    arma_stop("inv(): use of LAPACK needs to be enabled");
+    status = false;
+    }
+  #endif
+  
+  return status;
+  }
+
+
+
+template<typename eT, typename T1>
+inline
+bool
+auxlib::inv_sympd(Mat<eT>& out, const Base<eT,T1>& X, const u32 layout)
+  {
+  arma_extra_debug_sigprint();
+  
+  out = X.get_ref();
+  
+  arma_debug_check( (out.is_square() == false), "inv(): given matrix is not square" );
+  
+  if(out.is_empty())
+    {
+    return true;
+    }
+  
+  bool status;
+  
+  #if defined(ARMA_USE_LAPACK)
+    {
     char     uplo = (layout == 0) ? 'U' : 'L';
     blas_int n    = blas_int(out.n_rows);
     blas_int info = 0;
     
     lapack::potrf(&uplo, &n, out.memptr(), &n, &info);
-    lapack::potri(&uplo, &n, out.memptr(), &n, &info);
     
-    out = (layout == 0) ? symmatu(out) : symmatl(out);
+    status = (info == 0);
     
-    status = (info == 0);
+    if(status == true)
+      {
+      lapack::potri(&uplo, &n, out.memptr(), &n, &info);
+    
+      out = (layout == 0) ? symmatu(out) : symmatl(out);
+    
+      status = (info == 0);
+      }
     }
   #else
     {
@@ -533,12 +585,6 @@
     }
   #endif
   
-  if(status == false)
-    {
-    arma_print("inv(): matrix appears to be singular" );
-    out.reset();
-    }
-  
   return status;
   }
 
@@ -712,6 +758,7 @@
     {
     podarray<int> ipiv(tmp.n_rows);
     
+    //const int info =
     atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr());
     
     // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero
@@ -776,7 +823,7 @@
 //! immediate log determinant of a matrix using ATLAS or LAPACK
 template<typename eT, typename T1>
 inline
-void
+bool
 auxlib::log_det(eT& out_val, typename get_pod_type<eT>::result& out_sign, const Base<eT,T1>& X)
   {
   arma_extra_debug_sigprint();
@@ -797,7 +844,7 @@
     
     podarray<int> ipiv(tmp.n_rows);
     
-    atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr());
+    const int info = atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr());
     
     // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero
     
@@ -822,6 +869,8 @@
     
     out_val  = val;
     out_sign = T(sign);
+    
+    return (info == 0);
     }
   #elif defined(ARMA_USE_LAPACK)
     {
@@ -866,13 +915,17 @@
     
     out_val  = val;
     out_sign = T(sign);
+    
+    return (info == 0);
     }
   #else
     {
+    out_val  = eT(0);
+    out_sign =  T(0);
+    
     arma_stop("log_det(): use of ATLAS or LAPACK needs to be enabled");
     
-    out_val  = eT(0);
-    out_sign =  T(0);
+    return false;
     }
   #endif
   }
@@ -882,32 +935,35 @@
 //! immediate LU decomposition of a matrix using ATLAS or LAPACK
 template<typename eT, typename T1>
 inline
-void
+bool
 auxlib::lu(Mat<eT>& L, Mat<eT>& U, podarray<blas_int>& ipiv, const Base<eT,T1>& X)
   {
   arma_extra_debug_sigprint();
   
   U = X.get_ref();
   
+  const u32 U_n_rows = U.n_rows;
+  const u32 U_n_cols = U.n_cols;
+  
   if(U.is_empty())
     {
-    L.reset();
-    U.reset();
+    L.set_size(U_n_rows, 0);
+    U.set_size(0, U_n_cols);
     ipiv.reset();
-    return;
+    return true;
     }
   
-  const u32 U_n_rows = U.n_rows;
-  const u32 U_n_cols = U.n_cols;
-  
   #if defined(ARMA_USE_ATLAS) || defined(ARMA_USE_LAPACK)
     {
+    bool status;
+    
     #if defined(ARMA_USE_ATLAS)
       {
       ipiv.set_size( (std::min)(U_n_rows, U_n_cols) );
       
-      //int info = 
-      atlas::clapack_getrf(atlas::CblasColMajor, U_n_rows, U_n_cols, U.memptr(), U_n_rows, ipiv.memptr());
+      int info = atlas::clapack_getrf(atlas::CblasColMajor, U_n_rows, U_n_cols, U.memptr(), U_n_rows, ipiv.memptr());
+      
+      status = (info == 0);
       }
     #elif defined(ARMA_USE_LAPACK)
       {
@@ -923,6 +979,8 @@
       
       // take into account that Fortran counts from 1
       arrayops::inplace_minus(ipiv.memptr(), blas_int(1), ipiv.n_elem);
+      
+      status = (info == 0);
       }
     #endif
     
@@ -946,12 +1004,14 @@
         U.at(row,col) = eT(0);
         }
       }
+    
+    return status;
     }
   #else
     {
-    arma_ignore(U_n_rows);
-    arma_ignore(U_n_cols);
     arma_stop("lu(): use of ATLAS or LAPACK needs to be enabled");
+    
+    return false;
     }
   #endif
   }
@@ -960,115 +1020,123 @@
 
 template<typename eT, typename T1>
 inline
-void
+bool
 auxlib::lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Base<eT,T1>& X)
   {
   arma_extra_debug_sigprint();
   
   podarray<blas_int> ipiv1;
-  auxlib::lu(L, U, ipiv1, X);
+  const bool status = auxlib::lu(L, U, ipiv1, X);
   
-  if(U.is_empty())
+  if(status == true)
     {
-    L.reset();
-    U.reset();
-    P.reset();
-    return;
-    }
-  
-  const u32 n      = ipiv1.n_elem;
-  const u32 P_rows = U.n_rows;
-  
-  podarray<blas_int> ipiv2(P_rows);
-  
-  const blas_int* ipiv1_mem = ipiv1.memptr();
-        blas_int* ipiv2_mem = ipiv2.memptr();
-  
-  for(u32 i=0; i<P_rows; ++i)
-    {
-    ipiv2_mem[i] = blas_int(i);
-    }
-  
-  for(u32 i=0; i<n; ++i)
-    {
-    const u32 k = static_cast<u32>(ipiv1_mem[i]);
+    if(U.is_empty())
+      {
+      // L and U have been already set to the correct empty matrices
+      P.eye(L.n_rows, L.n_rows);
+      return true;
+      }
     
-    if( ipiv2_mem[i] != ipiv2_mem[k] )
+    const u32 n      = ipiv1.n_elem;
+    const u32 P_rows = U.n_rows;
+    
+    podarray<blas_int> ipiv2(P_rows);
+    
+    const blas_int* ipiv1_mem = ipiv1.memptr();
+          blas_int* ipiv2_mem = ipiv2.memptr();
+    
+    for(u32 i=0; i<P_rows; ++i)
       {
-      std::swap( ipiv2_mem[i], ipiv2_mem[k] );
+      ipiv2_mem[i] = blas_int(i);
       }
+    
+    for(u32 i=0; i<n; ++i)
+      {
+      const u32 k = static_cast<u32>(ipiv1_mem[i]);
+      
+      if( ipiv2_mem[i] != ipiv2_mem[k] )
+        {
+        std::swap( ipiv2_mem[i], ipiv2_mem[k] );
+        }
+      }
+    
+    P.zeros(P_rows, P_rows);
+    
+    for(u32 row=0; row<P_rows; ++row)
+      {
+      P.at(row, static_cast<u32>(ipiv2_mem[row])) = eT(1);
+      }
+    
+    if(L.n_cols > U.n_rows)
+      {
+      L.shed_cols(U.n_rows, L.n_cols-1);
+      }
+      
+    if(U.n_rows > L.n_cols)
+      {
+      U.shed_rows(L.n_cols, U.n_rows-1);
+      }
     }
   
-  P.zeros(P_rows, P_rows);
-  
-  for(u32 row=0; row<P_rows; ++row)
-    {
-    P.at(row, static_cast<u32>(ipiv2_mem[row])) = eT(1);
-    }
-  
-  if(L.n_cols > U.n_rows)
-    {
-    L.shed_cols(U.n_rows, L.n_cols-1);
-    }
-    
-  if(U.n_rows > L.n_cols)
-    {
-    U.shed_rows(L.n_cols, U.n_rows-1);
-    }
+  return status;
   }
 
 
 
 template<typename eT, typename T1>
 inline
-void
+bool
 auxlib::lu(Mat<eT>& L, Mat<eT>& U, const Base<eT,T1>& X)
   {
   arma_extra_debug_sigprint();
   
   podarray<blas_int> ipiv1;
-  auxlib::lu(L, U, ipiv1, X);
+  const bool status = auxlib::lu(L, U, ipiv1, X);
   
-  if(U.is_empty())
+  if(status == true)
     {
-    L.reset();
-    U.reset();
-    return;
-    }
-  
-  const u32 n      = ipiv1.n_elem;
-  const u32 P_rows = U.n_rows;
-  
-  podarray<blas_int> ipiv2(P_rows);
-  
-  const blas_int* ipiv1_mem = ipiv1.memptr();
-        blas_int* ipiv2_mem = ipiv2.memptr();
-  
-  for(u32 i=0; i<P_rows; ++i)
-    {
-    ipiv2_mem[i] = blas_int(i);
-    }
-  
-  for(u32 i=0; i<n; ++i)
-    {
-    const u32 k = static_cast<u32>(ipiv1_mem[i]);
+    if(U.is_empty())
+      {
+      // L and U have been already set to the correct empty matrices
+      return true;
+      }
     
-    if( ipiv2_mem[i] != ipiv2_mem[k] )
+    const u32 n      = ipiv1.n_elem;
+    const u32 P_rows = U.n_rows;
+    
+    podarray<blas_int> ipiv2(P_rows);
+    
+    const blas_int* ipiv1_mem = ipiv1.memptr();
+          blas_int* ipiv2_mem = ipiv2.memptr();
+    
+    for(u32 i=0; i<P_rows; ++i)
       {
-      std::swap( ipiv2_mem[i], ipiv2_mem[k] );
-      L.swap_rows( static_cast<u32>(ipiv2_mem[i]), static_cast<u32>(ipiv2_mem[k]) );
+      ipiv2_mem[i] = blas_int(i);
       }
+    
+    for(u32 i=0; i<n; ++i)
+      {
+      const u32 k = static_cast<u32>(ipiv1_mem[i]);
+      
+      if( ipiv2_mem[i] != ipiv2_mem[k] )
+        {
+        std::swap( ipiv2_mem[i], ipiv2_mem[k] );
+        L.swap_rows( static_cast<u32>(ipiv2_mem[i]), static_cast<u32>(ipiv2_mem[k]) );
+        }
+      }
+    
+    if(L.n_cols > U.n_rows)
+      {
+      L.shed_cols(U.n_rows, L.n_cols-1);
+      }
+      
+    if(U.n_rows > L.n_cols)
+      {
+      U.shed_rows(L.n_cols, U.n_rows-1);
+      }
     }
   
-  if(L.n_cols > U.n_rows)
-    {
-    L.shed_cols(U.n_rows, L.n_cols-1);
-    }
-    
-  if(U.n_rows > L.n_cols)
-    {
-    U.shed_rows(L.n_cols, U.n_rows-1);
-    }
+  return status;
   }
 
 
@@ -1549,16 +1617,15 @@
     {
     R = X.get_ref();
     
+    const u32 R_n_rows = R.n_rows;
+    const u32 R_n_cols = R.n_cols;
+    
     if(R.is_empty())
       {
-      Q.reset();
-      R.reset();
+      Q.eye(R_n_rows, R_n_rows);
       return true;
       }
     
-    const u32 R_n_rows = R.n_rows;
-    const u32 R_n_cols = R.n_cols;
-    
     blas_int m            = static_cast<blas_int>(R_n_rows);
     blas_int n            = static_cast<blas_int>(R_n_cols);
     blas_int work_len     = (std::max)(blas_int(1),n);
@@ -1659,8 +1726,6 @@
     if(A.is_empty())
       {
       S.reset();
-      X_n_rows = 0;
-      X_n_cols = 0;
       return true;
       }
     
@@ -1756,8 +1821,6 @@
     if(A.is_empty())
       {
       S.reset();
-      X_n_rows = 0;
-      X_n_cols = 0;
       return true;
       }
     
@@ -1875,9 +1938,9 @@
     
     if(A.is_empty())
       {
-      U.reset();
+      U.eye(A.n_rows, A.n_rows);
       S.reset();
-      V.reset();
+      V.eye(A.n_cols, A.n_cols);
       return true;
       }
     
@@ -1969,9 +2032,9 @@
     
     if(A.is_empty())
       {
-      U.reset();
+      U.eye(A.n_rows, A.n_rows);
       S.reset();
-      V.reset();
+      V.eye(A.n_cols, A.n_cols);
       return true;
       }
     
@@ -2062,8 +2125,7 @@
   
   if(A.is_empty() || B.is_empty())
     {
-    out.reset();
-    A.reset();
+    out.zeros(A.n_cols, B.n_cols);
     return true;
     }
   else
@@ -2133,8 +2195,7 @@
     {
     if(A.is_empty() || B.is_empty())
       {
-      out.reset();
-      A.reset();
+      out.zeros(A.n_cols, B.n_cols);
       return true;
       }
     
@@ -2202,8 +2263,7 @@
     {
     if(A.is_empty() || B.is_empty())
       {
-      out.reset();
-      A.reset();
+      out.zeros(A.n_cols, B.n_cols);
       return true;
       }
     
@@ -2286,7 +2346,7 @@
     {
     if(A.is_empty() || B.is_empty())
       {
-      out.reset();
+      out.zeros(A.n_cols, B.n_cols);
       return true;
       }
     
@@ -2499,12 +2559,6 @@
   #endif
   
   
-  if(status == false)
-    {
-    arma_print("syl(): equation appears to be singular" );
-    X.reset();
-    }
-  
   return status;
   }
   

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/config.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/config.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/config.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -57,6 +57,9 @@
 // #define ARMA_USE_BOOST
 // #define ARMA_USE_BOOST_DATE
 
+#define ARMA_PRINT_LOGIC_ERRORS
+#define ARMA_PRINT_RUNTIME_ERRORS
+
 // #define ARMA_HAVE_STD_ISFINITE
 // #define ARMA_HAVE_STD_ISINF
 // #define ARMA_HAVE_STD_ISNAN
@@ -67,3 +70,8 @@
 
 // #define ARMA_EXTRA_DEBUG
 // #define ARMA_NO_DEBUG
+
+#if defined(ARMA_DONT_USE_ATLAS)
+  #undef ARMA_USE_ATLAS
+  #undef ARMA_ATLAS_INCLUDE_DIR
+#endif

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/debug.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/debug.hpp	2011-06-21 22:17:36 UTC (rev 3097)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/debug.hpp	2011-06-23 13:49:17 UTC (rev 3098)
@@ -1,5 +1,6 @@
 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
 // Copyright (C) 2008-2011 Conrad Sanderson
+// Copyright (C) 2011 Stanislav Funiak
 // 
 // This file is part of the Armadillo C++ library.
 // It is provided without any warranty of fitness
@@ -19,63 +20,161 @@
 template<typename T>
 inline
 std::ostream&
-arma_log_stream(std::ostream* user_stream)
+arma_stream_err1(std::ostream* user_stream)
   {
-  static std::ostream* log_stream = &(std::cout);
+  static std::ostream* stream_err1 = &(std::cout);
   
   if(user_stream != NULL)
     {
-    log_stream = user_stream;
+    stream_err1 = user_stream;
     }
   
-  return *log_stream;
+  return *stream_err1;
   }
 
 
 
+template<typename T>
 inline
+std::ostream&
+arma_stream_err2(std::ostream* user_stream)
+  {
+  static std::ostream* stream_err2 = &(std::cout);
+  
+  if(user_stream != NULL)
+    {
+    stream_err2 = user_stream;
+    }
+  
+  return *stream_err2;
+  }
+
+
+
+inline
 void
-set_log_stream(std::ostream& user_stream)
+set_stream_err1(std::ostream& user_stream)
   {
-  arma_log_stream<char>(&user_stream);
+  arma_stream_err1<char>(&user_stream);
   }
 
 
 
 inline
+void
+set_stream_err2(std::ostream& user_stream)
+  {
+  arma_stream_err2<char>(&user_stream);
+  }
+
+
+
+inline
 std::ostream&
-get_log_stream()
+get_stream_err1()
   {
-  return arma_log_stream<char>(NULL);
+  return arma_stream_err1<char>(NULL);
   }
 
 
 
+inline
+std::ostream&
+get_stream_err2()
+  {
+  return arma_stream_err2<char>(NULL);
+  }
+
+
+
 //
 // arma_stop
 
-//! print a message to get_log_stream() and/or throw a run-time error exception
+//! print a message to get_stream_err1() and/or throw a logic_error exception
 template<typename T1>
 inline
 void
 arma_cold
 arma_stop(const T1& x)
   {
-  std::ostream& log_stream = get_log_stream();
+  #if defined(ARMA_PRINT_LOGIC_ERRORS)
+    {
+    std::ostream& out = get_stream_err1();
+    
+    out.flush();
+    
+    out << '\n';
+    out << "error: " << x << '\n';
+    out << '\n';
+    out.flush();
+    }
+  #else
+    {
+    arma_ignore(x);
+    }
+  #endif
   
-  log_stream.flush();
+  throw std::logic_error("");
+  }
+
+
+
+template<typename T1>
+inline
+void
+arma_cold
+arma_stop_bad_alloc(const T1& x)
+  {
+  std::ostream& out = get_stream_err1();
   
-  log_stream << '\n';
-  log_stream << "run-time error: " << x << '\n';
-  log_stream << '\n';
-  log_stream.flush();
+  out.flush();
   
-  throw std::runtime_error("");
+  out << '\n';
+  out << "error: " << x << '\n';
+  out << '\n';
+  out.flush();
+  
+  throw std::bad_alloc();
   }
 
 
 
 //
+// arma_bad
+
+//! print a message to get_stream_err2() and/or throw a run-time error exception
+template<typename T1>
+inline
+void
+arma_cold
+arma_bad(const T1& x, const bool hurl = true)
+  {
+  #if defined(ARMA_PRINT_RUNTIME_ERRORS)
+    {
+    std::ostream& out = get_stream_err2();
+    
+    out.flush();
+    
+    out << '\n';
+    out << "error: " << x << '\n';
+    out << '\n';
+    out.flush();
+    }
+  #else
+    {
+    arma_ignore(x);
+    }
+  #endif
+  
+  if(hurl == true)
+    {
+    throw std::runtime_error("");
+    }
+  }
+
+
+
+//
 // arma_print
 
 
@@ -84,7 +183,7 @@
 arma_cold
 arma_print()
   {
-  get_log_stream() << std::endl;
+  get_stream_err1() << std::endl;
   }
 
 
@@ -94,7 +193,7 @@
 arma_cold
 arma_print(const T1& x)
   {
-  get_log_stream() << x << std::endl;
+  get_stream_err1() << x << std::endl;
   }
 
 
@@ -105,7 +204,7 @@
 arma_cold
 arma_print(const T1& x, const T2& y)
   {
-  get_log_stream() << x << y << std::endl;
+  get_stream_err1() << x << y << std::endl;
   }
 
 
@@ -116,7 +215,7 @@
 arma_cold
 arma_print(const T1& x, const T2& y, const T3& z)
   {
-  get_log_stream() << x << y << z << std::endl;
+  get_stream_err1() << x << y << z << std::endl;
   }
 
 
@@ -135,7 +234,7 @@
 void
 arma_sigprint(const char* x)
   {
-  get_log_stream() << "@ " << x;
+  get_stream_err1() << "@ " << x;
   }
 
 
[TRUNCATED]

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


More information about the Rcpp-commits mailing list