[Rcpp-commits] r2930 - in pkg/RcppArmadillo: . inst inst/include/armadillo_bits
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Mar 22 21:13:29 CET 2011
Author: edd
Date: 2011-03-22 21:13:27 +0100 (Tue, 22 Mar 2011)
New Revision: 2930
Modified:
pkg/RcppArmadillo/ChangeLog
pkg/RcppArmadillo/DESCRIPTION
pkg/RcppArmadillo/inst/NEWS
pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/fn_prod.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/fn_stddev.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/fn_var.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/glue_mixed_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_min_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_min_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_stddev_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_stddev_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_var_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/op_var_proto.hpp
Log:
RcppArmadillo 0.2.17 with Armadillo 1.1.90
Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/ChangeLog 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,3 +1,9 @@
+2011-03-22 Dirk Eddelbuettel <edd at debian.org>
+
+ * DESCRIPTION: Release 0.2.17
+
+ * inst/include/*: Updated to Armadillo 1.1.90 "Inside Job"
+
2011-03-10 Dirk Eddelbuettel <edd at debian.org>
* DESCRIPTION: Release 0.2.16
Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/DESCRIPTION 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,7 +1,7 @@
Package: RcppArmadillo
Type: Package
Title: Rcpp integration for Armadillo templated linear algebra library
-Version: 0.2.16
+Version: 0.2.17
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.1.8). Thus users do not need to
+ Armadillo library (currently version 1.1.90). 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-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/NEWS 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,3 +1,10 @@
+0.2.17 2011-03-22
+
+ o Upgraded to Armadillo Version 1.1.90 "Inside Job"
+
+ * Added .min() & .max(), which can provide the extremum's location
+ * More robust mean(), var(), stddev()
+
0.2.16 2011-03-10
o Upgraded to Armadillo Version 1.1.8 "Kangaroo Steak"
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2008-2010 Conrad Sanderson
+// Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2008-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -2410,6 +2410,114 @@
+template<typename eT>
+inline
+eT
+Cube<eT>::min() const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "min(): object has no elements" );
+
+ return op_min::direct_min(memptr(), n_elem);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Cube<eT>::max() const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "max(): object has no elements" );
+
+ return op_max::direct_max(memptr(), n_elem);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Cube<eT>::min(u32& index_of_min_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "min(): object has no elements" );
+
+ return op_min::direct_min(memptr(), n_elem, index_of_min_val);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Cube<eT>::max(u32& index_of_max_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "max(): object has no elements" );
+
+ return op_max::direct_max(memptr(), n_elem, index_of_max_val);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Cube<eT>::min(u32& row_of_min_val, u32& col_of_min_val, u32& slice_of_min_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "min(): object has no elements" );
+
+ u32 i;
+
+ eT val = op_min::direct_min(memptr(), n_elem, i);
+
+ const u32 in_slice = i / n_elem_slice;
+ const u32 offset = in_slice * n_elem_slice;
+ const u32 j = i - offset;
+
+ row_of_min_val = j % n_rows;
+ col_of_min_val = j / n_rows;
+ slice_of_min_val = in_slice;
+
+ return val;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Cube<eT>::max(u32& row_of_max_val, u32& col_of_max_val, u32& slice_of_max_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "max(): object has no elements" );
+
+ u32 i;
+
+ eT val = op_max::direct_max(memptr(), n_elem, i);
+
+ const u32 in_slice = i / n_elem_slice;
+ const u32 offset = in_slice * n_elem_slice;
+ const u32 j = i - offset;
+
+ row_of_max_val = j % n_rows;
+ col_of_max_val = j / n_rows;
+ slice_of_max_val = in_slice;
+
+ return val;
+ }
+
+
+
//! save the cube to a file
template<typename eT>
inline
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2008-2010 Conrad Sanderson
+// Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2008-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -228,6 +228,16 @@
template<typename T1> inline void set_imag(const BaseCube<pod_type,T1>& X);
+ inline eT min() const;
+ inline eT max() const;
+
+ inline eT min(u32& index_of_min_val) const;
+ inline eT max(u32& index_of_max_val) const;
+
+ inline eT min(u32& row_of_min_val, u32& col_of_min_val, u32& slice_of_min_val) const;
+ inline eT max(u32& row_of_max_val, u32& col_of_max_val, u32& slice_of_max_val) const;
+
+
inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -4144,6 +4144,104 @@
+template<typename eT>
+inline
+eT
+Mat<eT>::min() const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "min(): object has no elements" );
+
+ return op_min::direct_min(memptr(), n_elem);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Mat<eT>::max() const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "max(): object has no elements" );
+
+ return op_max::direct_max(memptr(), n_elem);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Mat<eT>::min(u32& index_of_min_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "min(): object has no elements" );
+
+ return op_min::direct_min(memptr(), n_elem, index_of_min_val);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Mat<eT>::max(u32& index_of_max_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "max(): object has no elements" );
+
+ return op_max::direct_max(memptr(), n_elem, index_of_max_val);
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Mat<eT>::min(u32& row_of_min_val, u32& col_of_min_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "min(): object has no elements" );
+
+ u32 i;
+
+ eT val = op_min::direct_min(memptr(), n_elem, i);
+
+ row_of_min_val = i % n_rows;
+ col_of_min_val = i / n_rows;
+
+ return val;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Mat<eT>::max(u32& row_of_max_val, u32& col_of_max_val) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (n_elem == 0), "max(): object has no elements" );
+
+ u32 i;
+
+ eT val = op_max::direct_max(memptr(), n_elem, i);
+
+ row_of_max_val = i % n_rows;
+ col_of_max_val = i / n_rows;
+
+ return val;
+ }
+
+
+
//! save the matrix to a file
template<typename eT>
inline
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -320,6 +320,16 @@
template<typename T1> inline void set_imag(const Base<pod_type,T1>& X);
+ inline eT min() const;
+ inline eT max() const;
+
+ inline eT min(u32& index_of_min_val) const;
+ inline eT max(u32& index_of_max_val) const;
+
+ inline eT min(u32& row_of_min_val, u32& col_of_min_val) const;
+ inline eT max(u32& row_of_max_val, u32& col_of_max_val) const;
+
+
inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -18,8 +18,8 @@
#define ARMA_VERSION_MAJOR 1
#define ARMA_VERSION_MINOR 1
-#define ARMA_VERSION_PATCH 8
-#define ARMA_VERSION_NAME "Kangaroo Steak"
+#define ARMA_VERSION_PATCH 90
+#define ARMA_VERSION_NAME "Inside Job"
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/fn_prod.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/fn_prod.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/fn_prod.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -86,17 +86,7 @@
arma_debug_check( (X.n_elem < 1), "prod(): given object has no elements" );
- const u32 n_elem = X.n_elem;
- const eT* X_mem = X.memptr();
-
- eT val = X_mem[0];
-
- for(u32 i=1; i<n_elem; ++i)
- {
- val *= X_mem[i];
- }
-
- return val;
+ return arrayops::product(X.memptr(), X.n_elem);
}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/fn_stddev.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/fn_stddev.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/fn_stddev.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2009-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2009-2010 Conrad Sanderson
+// Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2009-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -18,22 +18,12 @@
template<typename T1>
inline
-Mat<typename T1::pod_type>
+const mtOp<typename T1::pod_type, T1, op_stddev>
stddev(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, const u32 dim = 0)
{
arma_extra_debug_sigprint();
- typedef typename T1::elem_type in_eT;
- typedef typename T1::pod_type out_eT;
-
- const unwrap<T1> tmp(X.get_ref());
- const Mat<in_eT>& A = tmp.M;
-
- Mat<out_eT> out;
-
- op_stddev::apply(out, A, norm_type, dim);
-
- return out;
+ return mtOp<typename T1::pod_type, T1, op_stddev>(X.get_ref(), norm_type, dim);
}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/fn_var.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/fn_var.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/fn_var.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2009-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2009-2010 Conrad Sanderson
+// Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2009-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -18,22 +18,12 @@
template<typename T1>
inline
-Mat<typename T1::pod_type>
+const mtOp<typename T1::pod_type, T1, op_var>
var(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, const u32 dim = 0)
{
arma_extra_debug_sigprint();
- typedef typename T1::elem_type in_eT;
- typedef typename T1::pod_type out_eT;
-
- const unwrap<T1> tmp(X.get_ref());
- const Mat<in_eT>& A = tmp.M;
-
- Mat<out_eT> out;
-
- op_var::apply(out, A, norm_type, dim);
-
- return out;
+ return mtOp<typename T1::pod_type, T1, op_var>(X.get_ref(), norm_type, dim);
}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/glue_mixed_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/glue_mixed_meat.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/glue_mixed_meat.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2009-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2009-2010 Conrad Sanderson
+// Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2009-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -44,7 +44,7 @@
const Mat<eT1>& AA = A_is_alias ? *AA_ptr : A;
const Mat<eT2>& BB = B_is_alias ? *BB_ptr : B;
- arma_debug_assert_mul_size(AA, BB, "matrix multiplication");
+ arma_debug_assert_mul_size(AA, BB, "multiplication");
out.set_size(AA.n_rows, BB.n_cols);
@@ -81,7 +81,7 @@
const Proxy<T1> A(X.A);
const Proxy<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "matrix addition");
+ arma_debug_assert_same_size(A, B, "addition");
out.set_size(A.get_n_rows(), A.get_n_cols());
@@ -114,7 +114,7 @@
const Proxy<T1> A(X.A);
const Proxy<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "matrix subtraction");
+ arma_debug_assert_same_size(A, B, "subtraction");
out.set_size(A.get_n_rows(), A.get_n_cols());
@@ -147,7 +147,7 @@
const Proxy<T1> A(X.A);
const Proxy<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "element-wise matrix division");
+ arma_debug_assert_same_size(A, B, "element-wise division");
out.set_size(A.get_n_rows(), A.get_n_cols());
@@ -180,7 +180,7 @@
const Proxy<T1> A(X.A);
const Proxy<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "element-wise matrix multiplication");
+ arma_debug_assert_same_size(A, B, "element-wise multiplication");
out.set_size(A.get_n_rows(), A.get_n_cols());
@@ -219,7 +219,7 @@
const ProxyCube<T1> A(X.A);
const ProxyCube<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "cube addition");
+ arma_debug_assert_same_size(A, B, "addition");
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
@@ -252,7 +252,7 @@
const ProxyCube<T1> A(X.A);
const ProxyCube<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "cube subtraction");
+ arma_debug_assert_same_size(A, B, "subtraction");
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
@@ -285,7 +285,7 @@
const ProxyCube<T1> A(X.A);
const ProxyCube<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "element-wise cube division");
+ arma_debug_assert_same_size(A, B, "element-wise division");
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
@@ -318,7 +318,7 @@
const ProxyCube<T1> A(X.A);
const ProxyCube<T2> B(X.B);
- arma_debug_assert_same_size(A, B, "element-wise cube multiplication");
+ arma_debug_assert_same_size(A, B, "element-wise multiplication");
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_meat.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_meat.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -60,6 +60,82 @@
+template<typename eT>
+inline
+eT
+op_max::direct_max(const eT* const X, const u32 n_elem, u32& index_of_max_val)
+ {
+ arma_extra_debug_sigprint();
+
+ eT max_val = (n_elem != 1) ? priv::most_neg<eT>() : X[0];
+
+ u32 best_index = 0;
+
+ u32 i,j;
+
+ for(i=0, j=1; j<n_elem; i+=2, j+=2)
+ {
+ const eT X_i = X[i];
+ const eT X_j = X[j];
+
+ if(X_i > max_val)
+ {
+ max_val = X_i;
+ best_index = i;
+ }
+
+ if(X_j > max_val)
+ {
+ max_val = X_j;
+ best_index = j;
+ }
+ }
+
+
+ if(i < n_elem)
+ {
+ const eT X_i = X[i];
+
+ if(X_i > max_val)
+ {
+ max_val = X_i;
+ best_index = i;
+ }
+ }
+
+ index_of_max_val = best_index;
+
+ return max_val;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+op_max::direct_max(const Mat<eT>& X, const u32 row)
+ {
+ arma_extra_debug_sigprint();
+
+ const u32 X_n_cols = X.n_cols;
+
+ eT max_val = (X_n_cols != 1) ? priv::most_neg<eT>() : X.at(row,0);
+
+ for(u32 col=0; col<X_n_cols; ++col)
+ {
+ const eT tmp_val = X.at(row,col);
+
+ if(tmp_val > max_val)
+ {
+ max_val = tmp_val;
+ }
+ }
+
+ return max_val;
+ }
+
+
+
//! find the maximum value in a subview
template<typename eT>
inline
@@ -156,19 +232,7 @@
for(u32 row=0; row<X_n_rows; ++row)
{
- eT max_val = (X_n_cols != 1) ? priv::most_neg<eT>() : X.at(row,0);
-
- for(u32 col=0; col<X_n_cols; ++col)
- {
- const eT tmp_val = X.at(row,col);
-
- if(tmp_val > max_val)
- {
- max_val = tmp_val;
- }
- }
-
- out[row] = max_val;
+ out[row] = op_max::direct_max( X, row );
}
}
}
@@ -202,19 +266,17 @@
-//! Find the maximum value in a subview (version for complex numbers)
template<typename T>
-inline
+inline
std::complex<T>
-op_max::direct_max(const subview< std::complex<T> >& X)
+op_max::direct_max(const std::complex<T>* const X, const u32 n_elem, u32& index_of_max_val)
{
arma_extra_debug_sigprint();
- const u32 X_n_elem = X.n_elem;
- u32 index = 0;
- T max_val = (X_n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0]);
+ u32 index = 0;
+ T max_val = (n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0]);
- for(u32 i=0; i<X_n_elem; ++i)
+ for(u32 i=0; i<n_elem; ++i)
{
const T tmp_val = std::abs(X[i]);
@@ -225,19 +287,49 @@
}
}
+ index_of_max_val = index;
+
return X[index];
}
-//! Find the maximum value in a diagview (version for complex numbers)
template<typename T>
inline
std::complex<T>
-op_max::direct_max(const diagview< std::complex<T> >& X)
+op_max::direct_max(const Mat< std::complex<T> >& X, const u32 row)
{
arma_extra_debug_sigprint();
+ const u32 X_n_cols = X.n_cols;
+
+ u32 index = 0;
+ T max_val = (X_n_cols != 1) ? priv::most_neg<T>() : std::abs(X.at(row,0));
+
+ for(u32 col=0; col<X_n_cols; ++col)
+ {
+ const T tmp_val = std::abs(X.at(row,col));
+
+ if(tmp_val > max_val)
+ {
+ max_val = tmp_val;
+ index = col;
+ }
+ }
+
+ return X.at(row,index);
+ }
+
+
+
+//! Find the maximum value in a subview (version for complex numbers)
+template<typename T>
+inline
+std::complex<T>
+op_max::direct_max(const subview< std::complex<T> >& X)
+ {
+ arma_extra_debug_sigprint();
+
const u32 X_n_elem = X.n_elem;
u32 index = 0;
T max_val = (X_n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0]);
@@ -258,65 +350,30 @@
-//! Implementation for complex numbers
-template<typename T, typename T1>
-inline void op_max::apply(Mat< std::complex<T> >& out, const Op<T1,op_max>& in)
+//! Find the maximum value in a diagview (version for complex numbers)
+template<typename T>
+inline
+std::complex<T>
+op_max::direct_max(const diagview< std::complex<T> >& X)
{
arma_extra_debug_sigprint();
- typedef typename std::complex<T> eT;
- isnt_same_type<eT, typename T1::elem_type>::check();
+ const u32 X_n_elem = X.n_elem;
+ u32 index = 0;
+ T max_val = (X_n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0]);
- const unwrap_check<T1> tmp(in.m, out);
- const Mat<eT>& X = tmp.M;
-
- arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" );
-
- const u32 dim = in.aux_u32_a;
- arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1");
-
- const u32 X_n_rows = X.n_rows;
- const u32 X_n_cols = X.n_cols;
-
- if(dim == 0) // column-wise max
+ for(u32 i=0; i<X_n_elem; ++i)
{
- arma_extra_debug_print("op_max::apply(), dim = 0");
+ const T tmp_val = std::abs(X[i]);
- out.set_size(1, X_n_cols);
-
- for(u32 col=0; col<X_n_cols; ++col)
+ if(tmp_val > max_val)
{
- out[col] = op_max::direct_max( X.colptr(col), X_n_rows );
+ max_val = tmp_val;
+ index = i;
}
}
- else
- if(dim == 1) // row-wise max
- {
- arma_extra_debug_print("op_max::apply(), dim = 1");
-
- out.set_size(X_n_rows, 1);
-
- for(u32 row=0; row<X_n_rows; ++row)
- {
- u32 index = 0;
- T max_val = (X_n_cols != 1) ? priv::most_neg<T>() : std::abs(X.at(row,0));
-
- for(u32 col=0; col<X_n_cols; ++col)
- {
- const T tmp_val = std::abs(X.at(row,col));
-
- if(tmp_val > max_val)
- {
- max_val = tmp_val;
- index = col;
- }
- }
-
- out[row] = X.at(row,index);
- }
-
- }
+ return X[index];
}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_proto.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_max_proto.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2008-2010 Conrad Sanderson
+// Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2008-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -25,6 +25,12 @@
inline static eT direct_max(const eT* const X, const u32 N);
template<typename eT>
+ inline static eT direct_max(const eT* const X, const u32 N, u32& index_of_max_val);
+
+ template<typename eT>
+ inline static eT direct_max(const Mat<eT>& X, const u32 row);
+
+ template<typename eT>
inline static eT direct_max(const subview<eT>& X);
template<typename eT>
@@ -36,19 +42,22 @@
//
// for complex numbers
-
+
template<typename T>
inline static std::complex<T> direct_max(const std::complex<T>* const X, const u32 n_elem);
template<typename T>
+ inline static std::complex<T> direct_max(const std::complex<T>* const X, const u32 n_elem, u32& index_of_max_val);
+
+ template<typename T>
+ inline static std::complex<T> direct_max(const Mat< std::complex<T> >& X, const u32 row);
+
+ template<typename T>
inline static std::complex<T> direct_max(const subview< std::complex<T> >&X);
template<typename T>
inline static std::complex<T> direct_max(const diagview< std::complex<T> >&X);
- template<typename T, typename T1>
- inline static void apply(Mat< std::complex<T> >& out, const Op<T1,op_max>& in);
-
};
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_meat.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_meat.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -26,11 +26,38 @@
typedef typename get_pod_type<eT>::result T;
- return arrayops::accumulate(X, n_elem) / T(n_elem);
+ const eT result = arrayops::accumulate(X, n_elem) / T(n_elem);
+
+ return arma_isfinite(result) ? result : op_mean::direct_mean_robust(X, n_elem);
}
+template<typename eT>
+inline
+eT
+op_mean::direct_mean(const Mat<eT>& X, const u32 row)
+ {
+ arma_extra_debug_sigprint();
+
+ typedef typename get_pod_type<eT>::result T;
+
+ const u32 X_n_cols = X.n_cols;
+
+ eT val = eT(0);
+
+ for(u32 col=0; col<X_n_cols; ++col)
+ {
+ val += X.at(row,col);
+ }
+
+ const eT result = val / T(X_n_cols);
+
+ return arma_isfinite(result) ? result : direct_mean_robust(X, row);
+ }
+
+
+
//! find the mean value of a subview
template<typename eT>
inline
@@ -49,7 +76,9 @@
val += X[i];
}
- return val / T(X_n_elem);
+ const eT result = val / T(X_n_elem);
+
+ return arma_isfinite(result) ? result : direct_mean_robust(X);
}
@@ -72,7 +101,9 @@
val += X[i];
}
- return val / T(X_n_elem);
+ const eT result = val / T(X_n_elem);
+
+ return arma_isfinite(result) ? result : direct_mean_robust(X);
}
@@ -122,18 +153,119 @@
for(u32 row=0; row<X_n_rows; ++row)
{
- eT val = eT(0);
-
- for(u32 col=0; col<X_n_cols; ++col)
- {
- val += X.at(row,col);
- }
-
- out[row] = val / T(X_n_cols);
+ out[row] = op_mean::direct_mean( X, row );
}
}
}
+
+template<typename eT>
+arma_pure
+inline
+eT
+op_mean::direct_mean_robust(const eT* const X, const u32 n_elem)
+ {
+ arma_extra_debug_sigprint();
+
+ // use an adapted form of the mean finding algorithm from the running_stat class
+
+ typedef typename get_pod_type<eT>::result T;
+
+ u32 i,j;
+
+ eT r_mean = eT(0);
+
+ for(i=0, j=1; j<n_elem; i+=2, j+=2)
+ {
+ const eT Xi = X[i];
+ const eT Xj = X[j];
+
+ r_mean = r_mean + (Xi - r_mean)/T(j); // we need i+1, and j is equivalent to i+1 here
+ r_mean = r_mean + (Xj - r_mean)/T(j+1);
+ }
+
+
+ if(i < n_elem)
+ {
+ const eT Xi = X[i];
+
+ r_mean = r_mean + (Xi - r_mean)/T(i+1);
+ }
+
+ return r_mean;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+op_mean::direct_mean_robust(const Mat<eT>& X, const u32 row)
+ {
+ arma_extra_debug_sigprint();
+
+ typedef typename get_pod_type<eT>::result T;
+
+ const u32 X_n_cols = X.n_cols;
+
+ eT r_mean = eT(0);
+
+ for(u32 col=0; col<X_n_cols; ++col)
+ {
+ r_mean = r_mean + (X.at(row,col) - r_mean)/T(col+1);
+ }
+
+ return r_mean;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+op_mean::direct_mean_robust(const subview<eT>& X)
+ {
+ arma_extra_debug_sigprint();
+
+ typedef typename get_pod_type<eT>::result T;
+
+ const u32 X_n_elem = X.n_elem;
+
+ eT r_mean = eT(0);
+
+ for(u32 i=0; i<X_n_elem; ++i)
+ {
+ r_mean = r_mean + (X[i] - r_mean)/T(i+1);
+ }
+
+ return r_mean;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+op_mean::direct_mean_robust(const diagview<eT>& X)
+ {
+ arma_extra_debug_sigprint();
+
+ typedef typename get_pod_type<eT>::result T;
+
+ const u32 X_n_elem = X.n_elem;
+
+ eT r_mean = eT(0);
+
+ for(u32 i=0; i<X_n_elem; ++i)
+ {
+ r_mean = r_mean + (X[i] - r_mean)/T(i+1);
+ }
+
+ return r_mean;
+ }
+
+
+
//! @}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_proto.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_mean_proto.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -1,5 +1,5 @@
-// Copyright (C) 2009-2010 NICTA (www.nicta.com.au)
-// Copyright (C) 2009-2010 Conrad Sanderson
+// Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
+// Copyright (C) 2009-2011 Conrad Sanderson
//
// This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness
@@ -14,6 +14,7 @@
//! \addtogroup op_mean
//! @{
+
//! Class for finding mean values of a matrix
class op_mean
{
@@ -23,6 +24,9 @@
inline static eT direct_mean(const eT* const X, const u32 N);
template<typename eT>
+ inline static eT direct_mean(const Mat<eT>& X, const u32 row);
+
+ template<typename eT>
inline static eT direct_mean(const subview<eT>& X);
template<typename eT>
@@ -31,6 +35,20 @@
template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op_mean>& in);
+
+ template<typename eT>
+ inline static eT direct_mean_robust(const eT* const X, const u32 N);
+
+ template<typename eT>
+ inline static eT direct_mean_robust(const Mat<eT>& X, const u32 row);
+
+ template<typename eT>
+ inline static eT direct_mean_robust(const subview<eT>& X);
+
+ template<typename eT>
+ inline static eT direct_mean_robust(const diagview<eT>& X);
};
+
+
//! @}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/op_min_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/op_min_meat.hpp 2011-03-21 17:09:12 UTC (rev 2929)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/op_min_meat.hpp 2011-03-22 20:13:27 UTC (rev 2930)
@@ -60,6 +60,82 @@
+template<typename eT>
+inline
+eT
+op_min::direct_min(const eT* const X, const u32 n_elem, u32& index_of_min_val)
+ {
+ arma_extra_debug_sigprint();
+
+ eT min_val = (n_elem != 1) ? priv::most_pos<eT>() : X[0];
+
+ u32 best_index = 0;
+
+ u32 i,j;
+
+ for(i=0, j=1; j<n_elem; i+=2, j+=2)
+ {
+ const eT X_i = X[i];
+ const eT X_j = X[j];
+
+ if(X_i < min_val)
+ {
+ min_val = X_i;
+ best_index = i;
+ }
+
+ if(X_j < min_val)
+ {
+ min_val = X_j;
+ best_index = j;
+ }
+ }
+
+
+ if(i < n_elem)
+ {
+ const eT X_i = X[i];
+
+ if(X_i < min_val)
+ {
+ min_val = X_i;
+ best_index = i;
+ }
+ }
+
+ index_of_min_val = best_index;
+
+ return min_val;
+ }
+
+
+
+template<typename eT>
+inline
+eT
+op_min::direct_min(const Mat<eT>& X, const u32 row)
+ {
+ arma_extra_debug_sigprint();
+
+ const u32 X_n_cols = X.n_cols;
+
+ eT min_val = (X_n_cols != 1) ? priv::most_pos<eT>() : X.at(row,0);
+
+ for(u32 col=0; col<X_n_cols; ++col)
+ {
+ const eT tmp_val = X.at(row,col);
+
+ if(tmp_val < min_val)
+ {
+ min_val = tmp_val;
+ }
+ }
+
+ return min_val;
+ }
+
+
+
//! find the minimum value in a subview
template<typename eT>
inline
@@ -156,23 +232,9 @@
for(u32 row=0; row<X_n_rows; ++row)
{
- eT min_val = (X_n_cols != 1) ? priv::most_pos<eT>() : X.at(row,0);
-
- for(u32 col=0; col<X_n_cols; ++col)
- {
- const eT tmp_val = X.at(row,col);
-
- if(tmp_val < min_val)
- {
- min_val = tmp_val;
- }
- }
-
- out[row] = min_val;
+ out[row] = op_min::direct_min( X, row );
}
-
}
-
}
@@ -204,19 +266,17 @@
-//! Find the minimum value in a subview (version for complex numbers)
template<typename T>
inline
std::complex<T>
-op_min::direct_min(const subview< std::complex<T> >& X)
+op_min::direct_min(const std::complex<T>* const X, const u32 n_elem, u32& index_of_min_val)
{
arma_extra_debug_sigprint();
- const u32 X_n_elem = X.n_elem;
- u32 index = 0;
- T min_val = (X_n_elem != 1) ? priv::most_pos<T>() : std::abs(X[0]);
+ u32 index = 0;
+ T min_val = (n_elem != 1) ? priv::most_pos<T>() : std::abs(X[0]);
- for(u32 i=0; i<X_n_elem; ++i)
+ for(u32 i=0; i<n_elem; ++i)
{
const T tmp_val = std::abs(X[i]);
@@ -227,19 +287,49 @@
}
}
+ index_of_min_val = index;
+
return X[index];
}
-//! Find the minimum value in a diagview (version for complex numbers)
template<typename T>
inline
std::complex<T>
-op_min::direct_min(const diagview< std::complex<T> >& X)
+op_min::direct_min(const Mat< std::complex<T> >& X, const u32 row)
{
arma_extra_debug_sigprint();
+ const u32 X_n_cols = X.n_cols;
+
+ u32 index = 0;
+ T min_val = (X_n_cols != 1) ? priv::most_pos<T>() : std::abs(X.at(row,0));
+
+ for(u32 col=0; col<X_n_cols; ++col)
+ {
+ const T tmp_val = std::abs(X.at(row,col));
+
+ if(tmp_val < min_val)
+ {
+ min_val = tmp_val;
+ index = col;
+ }
+ }
+
+ return X.at(row,index);
+ }
+
+
+
+//! Find the minimum value in a subview (version for complex numbers)
+template<typename T>
+inline
+std::complex<T>
+op_min::direct_min(const subview< std::complex<T> >& X)
+ {
+ arma_extra_debug_sigprint();
+
const u32 X_n_elem = X.n_elem;
u32 index = 0;
T min_val = (X_n_elem != 1) ? priv::most_pos<T>() : std::abs(X[0]);
@@ -260,65 +350,30 @@
-//! Implementation for complex numbers
-template<typename T, typename T1>
-inline void op_min::apply(Mat< std::complex<T> >& out, const Op<T1,op_min>& in)
+//! Find the minimum value in a diagview (version for complex numbers)
+template<typename T>
+inline
+std::complex<T>
+op_min::direct_min(const diagview< std::complex<T> >& X)
{
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rcpp -r 2930
More information about the Rcpp-commits
mailing list