[Rcpp-commits] r1152 - in pkg/RcppArmadillo: . inst/include inst/include/armadillo_bits
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue May 4 04:53:42 CEST 2010
Author: edd
Date: 2010-05-04 04:53:42 +0200 (Tue, 04 May 2010)
New Revision: 1152
Added:
pkg/RcppArmadillo/inst/include/armadillo_bits/fn_find.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/fn_join.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/glue_join_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/glue_join_proto.hpp
Modified:
pkg/RcppArmadillo/DESCRIPTION
pkg/RcppArmadillo/NEWS
pkg/RcppArmadillo/inst/include/armadillo
pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp
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/Row_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/eop_aux.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/field_meat.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/field_proto.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/fn_norm.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/format_wrap.hpp
pkg/RcppArmadillo/inst/include/armadillo_bits/version.hpp
Log:
updated to Armadillo 0.9.6, retaining the previous config.hpp
Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/DESCRIPTION 2010-05-04 02:53:42 UTC (rev 1152)
@@ -1,7 +1,7 @@
Package: RcppArmadillo
Type: Package
Title: Rcpp/Armadillo translation layer
-Version: 0.1.0.3
+Version: 0.1.0.4
Date: $Date$
Author: Romain Francois, Dirk Eddelbuettel and Doug Bates
Maintainer: Romain, Dirk and Doug <RcppArmadillo-authors at r-enthusiasts.com>
@@ -20,6 +20,9 @@
This library is useful if C++ has been decided as the language of choice
(due to speed and/or integration capabilities), rather than another language.
.
+ The RcppArmadillo package includes the header from the templated Armadillo
+ library.
+ .
This Armadillo / C integration provides a nice illustration of the
capabilities of the Rcpp package for seamless R and C++ integration/
License: GPL (>= 2)
Modified: pkg/RcppArmadillo/NEWS
===================================================================
--- pkg/RcppArmadillo/NEWS 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/NEWS 2010-05-04 02:53:42 UTC (rev 1152)
@@ -1,15 +1,15 @@
0.2.0 (under development)
- o Armadillo sources (using release 0.9.4) are now included in the package
- using a standardized build suitable for our purposes (not assuming
- Boost or Atlas) -- see the new README for details
+ o Armadillo sources (using release 0.9.6) are now included in the package
+ using a standardized build suitable for our purposes (not assuming
+ Boost or Atlas) -- see the new README for details
0.1.0 2010-03-11
o the fastLm() implementation of a bare-bones lm() fit
- (using Armadillo's solve() function) provides an example
- of how efficient code can be written compactly using
- the combination of Rcpp, RcppAramadillo and Armadillo
+ (using Armadillo's solve() function) provides an example
+ of how efficient code can be written compactly using
+ the combination of Rcpp, RcppAramadillo and Armadillo
o support for Rcpp implicit wrap of these types :
Mat<T>, Col<T>, Row<T>, Cube<T> where T is one of :
Modified: pkg/RcppArmadillo/inst/include/armadillo
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo 2010-05-04 02:53:42 UTC (rev 1152)
@@ -183,6 +183,7 @@
#include "armadillo_bits/glue_cor_proto.hpp"
#include "armadillo_bits/glue_kron_proto.hpp"
#include "armadillo_bits/glue_cross_proto.hpp"
+ #include "armadillo_bits/glue_join_proto.hpp"
//
@@ -303,6 +304,8 @@
#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_find.hpp"
//
// class meat
@@ -366,6 +369,7 @@
#include "armadillo_bits/glue_cor_meat.hpp"
#include "armadillo_bits/glue_kron_meat.hpp"
#include "armadillo_bits/glue_cross_meat.hpp"
+ #include "armadillo_bits/glue_join_meat.hpp"
}
#endif
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -796,4 +796,61 @@
}
+
+template<typename eT>
+inline
+typename Col<eT>::row_iterator
+Col<eT>::begin_row(const u32 row_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out of bounds");
+
+ return Mat<eT>::memptr() + row_num;
+ }
+
+
+
+template<typename eT>
+inline
+typename Col<eT>::const_row_iterator
+Col<eT>::begin_row(const u32 row_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out of bounds");
+
+ return Mat<eT>::memptr() + row_num;
+ }
+
+
+
+template<typename eT>
+inline
+typename Col<eT>::row_iterator
+Col<eT>::end_row(const u32 row_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of bounds");
+
+ return Mat<eT>::memptr() + row_num + 1;
+ }
+
+
+
+template<typename eT>
+inline
+typename Col<eT>::const_row_iterator
+Col<eT>::end_row(const u32 row_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of bounds");
+
+ return Mat<eT>::memptr() + row_num + 1;
+ }
+
+
+
//! @}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -104,7 +104,18 @@
inline void load(const std::string name, const file_type type = auto_detect);
inline void load( std::istream& is, const file_type type = auto_detect);
+
+
+ typedef eT* row_iterator;
+ typedef const eT* const_row_iterator;
+
+ inline row_iterator begin_row(const u32 row_num);
+ inline const_row_iterator begin_row(const u32 row_num) const;
+
+ inline row_iterator end_row (const u32 row_num);
+ inline const_row_iterator end_row (const u32 row_num) const;
};
+
//! @}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -1864,6 +1864,110 @@
+template<typename eT>
+inline
+typename Cube<eT>::iterator
+Cube<eT>::begin()
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr();
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::const_iterator
+Cube<eT>::begin() const
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr();
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::iterator
+Cube<eT>::end()
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr() + n_elem;
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::const_iterator
+Cube<eT>::end() const
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr() + n_elem;
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::slice_iterator
+Cube<eT>::begin_slice(const u32 slice_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
+
+ return slice_memptr(slice_num);
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::const_slice_iterator
+Cube<eT>::begin_slice(const u32 slice_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
+
+ return slice_memptr(slice_num);
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::slice_iterator
+Cube<eT>::end_slice(const u32 slice_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
+
+ return slice_memptr(slice_num) + n_elem_slice;
+ }
+
+
+
+template<typename eT>
+inline
+typename Cube<eT>::const_slice_iterator
+Cube<eT>::end_slice(const u32 slice_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
+
+ return slice_memptr(slice_num) + n_elem_slice;
+ }
+
+
+
//! prefix ++
template<typename eT>
arma_inline
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_proto.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -167,6 +167,27 @@
inline void load( std::istream& is, const file_type type = auto_detect);
+ // iterators
+
+ typedef eT* iterator;
+ typedef const eT* const_iterator;
+
+ typedef eT* slice_iterator;
+ typedef const eT* const_slice_iterator;
+
+ inline iterator begin();
+ inline const_iterator begin() const;
+
+ inline iterator end();
+ inline const_iterator end() const;
+
+ inline slice_iterator begin_slice(const u32 slice_num);
+ inline const_slice_iterator begin_slice(const u32 slice_num) const;
+
+ inline slice_iterator end_slice(const u32 slice_num);
+ inline const_slice_iterator end_slice(const u32 slice_num) const;
+
+
protected:
inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slices);
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -2521,6 +2521,384 @@
+template<typename eT>
+inline
+Mat<eT>::row_iterator::row_iterator(Mat<eT>& in_M, const u32 in_row)
+ : M (in_M )
+ , row(in_row)
+ , col(0 )
+ {
+ arma_extra_debug_sigprint();
+ }
+
+
+
+template<typename eT>
+inline
+eT&
+Mat<eT>::row_iterator::operator*()
+ {
+ return M.at(row,col);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::row_iterator&
+Mat<eT>::row_iterator::operator++()
+ {
+ ++col;
+
+ if(col >= M.n_cols)
+ {
+ col = 0;
+ ++row;
+ }
+
+ return *this;
+ }
+
+
+
+template<typename eT>
+inline
+void
+Mat<eT>::row_iterator::operator++(int)
+ {
+ operator++();
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::row_iterator&
+Mat<eT>::row_iterator::operator--()
+ {
+ if(col > 0)
+ {
+ --col;
+ }
+ else
+ {
+ if(row > 0)
+ {
+ col = M.n_cols - 1;
+ --row;
+ }
+ }
+
+ return *this;
+ }
+
+
+
+template<typename eT>
+inline
+void
+Mat<eT>::row_iterator::operator--(int)
+ {
+ operator--();
+ }
+
+
+
+template<typename eT>
+inline
+bool
+Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) const
+ {
+ return ( (row != X.row) || (col != X.col) ) ? true : false;
+ }
+
+
+
+template<typename eT>
+inline
+bool
+Mat<eT>::row_iterator::operator==(const typename Mat<eT>::row_iterator& X) const
+ {
+ return ( (row == X.row) && (col == X.col) ) ? true : false;
+ }
+
+
+
+template<typename eT>
+inline
+Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>& in_M, const u32 in_row)
+ : M (in_M )
+ , row(in_row)
+ , col(0 )
+ {
+ arma_extra_debug_sigprint();
+ }
+
+
+
+template<typename eT>
+inline
+Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>::row_iterator& X)
+ : M (X.M)
+ , row(X.row)
+ , col(X.col)
+ {
+ arma_extra_debug_sigprint();
+ }
+
+
+
+template<typename eT>
+inline
+eT
+Mat<eT>::const_row_iterator::operator*() const
+ {
+ return M.at(row,col);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_row_iterator&
+Mat<eT>::const_row_iterator::operator++()
+ {
+ ++col;
+
+ if(col >= M.n_cols)
+ {
+ col = 0;
+ ++row;
+ }
+
+ return *this;
+ }
+
+
+
+template<typename eT>
+inline
+void
+Mat<eT>::const_row_iterator::operator++(int)
+ {
+ operator++();
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_row_iterator&
+Mat<eT>::const_row_iterator::operator--()
+ {
+ if(col > 0)
+ {
+ --col;
+ }
+ else
+ {
+ if(row > 0)
+ {
+ col = M.n_cols - 1;
+ --row;
+ }
+ }
+
+ return *this;
+ }
+
+
+
+template<typename eT>
+inline
+void
+Mat<eT>::const_row_iterator::operator--(int)
+ {
+ operator--();
+ }
+
+
+
+template<typename eT>
+inline
+bool
+Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::const_row_iterator& X) const
+ {
+ return ( (row != X.row) || (col != X.col) ) ? true : false;
+ }
+
+
+
+template<typename eT>
+inline
+bool
+Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::const_row_iterator& X) const
+ {
+ return ( (row == X.row) && (col == X.col) ) ? true : false;
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::iterator
+Mat<eT>::begin()
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr();
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_iterator
+Mat<eT>::begin() const
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr();
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::iterator
+Mat<eT>::end()
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr() + n_elem;
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_iterator
+Mat<eT>::end() const
+ {
+ arma_extra_debug_sigprint();
+
+ return memptr() + n_elem;
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::col_iterator
+Mat<eT>::begin_col(const u32 col_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds");
+
+ return colptr(col_num);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_col_iterator
+Mat<eT>::begin_col(const u32 col_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds");
+
+ return colptr(col_num);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::col_iterator
+Mat<eT>::end_col(const u32 col_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds");
+
+ return colptr(col_num) + n_rows;
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_col_iterator
+Mat<eT>::end_col(const u32 col_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds");
+
+ return colptr(col_num) + n_rows;
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::row_iterator
+Mat<eT>::begin_row(const u32 row_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
+
+ return typename Mat<eT>::row_iterator(*this, row_num);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_row_iterator
+Mat<eT>::begin_row(const u32 row_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
+
+ return typename Mat<eT>::const_row_iterator(*this, row_num);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::row_iterator
+Mat<eT>::end_row(const u32 row_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
+
+ return typename Mat<eT>::row_iterator(*this, row_num + 1);
+ }
+
+
+
+template<typename eT>
+inline
+typename Mat<eT>::const_row_iterator
+Mat<eT>::end_row(const u32 row_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
+
+ return typename Mat<eT>::const_row_iterator(*this, row_num + 1);
+ }
+
+
+
//! prefix ++
template<typename eT>
arma_inline
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -24,8 +24,8 @@
{
public:
- typedef eT elem_type; //!< the type of elements stored in the matrix
- typedef typename get_pod_type<elem_type>::result pod_type; //!< if eT is non-complex, pod_type is same as eT. otherwise, pod_type is the underlying type used by std::complex
+ typedef eT elem_type; //!< the type of elements stored in the matrix
+ typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-complex, pod_type is same as eT. otherwise, pod_type is the underlying type used by std::complex
const u32 n_rows; //!< number of rows in the matrix (read-only)
const u32 n_cols; //!< number of columns in the matrix (read-only)
@@ -214,8 +214,81 @@
inline void load( std::istream& is, const file_type type = auto_detect);
- protected:
+ // iterators
+ typedef eT* iterator;
+ typedef const eT* const_iterator;
+
+ typedef eT* col_iterator;
+ typedef const eT* const_col_iterator;
+
+ class row_iterator
+ {
+ public:
+
+ inline row_iterator(Mat<eT>& in_M, const u32 in_row);
+
+ inline eT& operator* ();
+
+ inline row_iterator& operator++();
+ inline void operator++(int);
+
+ inline row_iterator& operator--();
+ inline void operator--(int);
+
+ inline bool operator!=(const row_iterator& X) const;
+ inline bool operator==(const row_iterator& X) const;
+
+ arma_aligned Mat<eT>& M;
+ arma_aligned u32 row;
+ arma_aligned u32 col;
+ };
+
+
+ class const_row_iterator
+ {
+ public:
+
+ const_row_iterator(const Mat<eT>& in_M, const u32 in_row);
+ const_row_iterator(const row_iterator& X);
+
+ inline eT operator*() const;
+
+ inline const_row_iterator& operator++();
+ inline void operator++(int);
+
+ inline const_row_iterator& operator--();
+ inline void operator--(int);
+
+ inline bool operator!=(const const_row_iterator& X) const;
+ inline bool operator==(const const_row_iterator& X) const;
+
+ arma_aligned const Mat<eT>& M;
+ arma_aligned u32 row;
+ arma_aligned u32 col;
+ };
+
+ inline iterator begin();
+ inline const_iterator begin() const;
+
+ inline iterator end();
+ inline const_iterator end() const;
+
+ inline col_iterator begin_col(const u32 col_num);
+ inline const_col_iterator begin_col(const u32 col_num) const;
+
+ inline col_iterator end_col (const u32 col_num);
+ inline const_col_iterator end_col (const u32 col_num) const;
+
+ inline row_iterator begin_row(const u32 row_num);
+ inline const_row_iterator begin_row(const u32 row_num) const;
+
+ inline row_iterator end_row (const u32 row_num);
+ inline const_row_iterator end_row (const u32 row_num) const;
+
+
+ protected:
+
inline void init(const u32 in_rows, const u32 in_cols);
inline void init(const std::string& text);
inline void init(const Mat& x);
@@ -223,6 +296,7 @@
inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols);
friend class Cube<eT>;
+ friend class glue_join;
};
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -767,4 +767,60 @@
+template<typename eT>
+inline
+typename Row<eT>::row_iterator
+Row<eT>::begin_row(const u32 row_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out of bounds");
+
+ return Mat<eT>::memptr();
+ }
+
+
+
+template<typename eT>
+inline
+typename Row<eT>::const_row_iterator
+Row<eT>::begin_row(const u32 row_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out of bounds");
+
+ return Mat<eT>::memptr();
+ }
+
+
+
+template<typename eT>
+inline
+typename Row<eT>::row_iterator
+Row<eT>::end_row(const u32 row_num)
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of bounds");
+
+ return Mat<eT>::memptr() + Mat<eT>::n_cols;
+ }
+
+
+
+template<typename eT>
+inline
+typename Row<eT>::const_row_iterator
+Row<eT>::end_row(const u32 row_num) const
+ {
+ arma_extra_debug_sigprint();
+
+ arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of bounds");
+
+ return Mat<eT>::memptr() + Mat<eT>::n_cols;
+ }
+
+
+
//! @}
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -105,6 +105,16 @@
inline void load(const std::string name, const file_type type = auto_detect);
inline void load( std::istream& is, const file_type type = auto_detect);
+
+
+ typedef eT* row_iterator;
+ typedef const eT* const_row_iterator;
+
+ inline row_iterator begin_row(const u32 row_num);
+ inline const_row_iterator begin_row(const u32 row_num) const;
+
+ inline row_iterator end_row (const u32 row_num);
+ inline const_row_iterator end_row (const u32 row_num) const;
};
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -1225,7 +1225,7 @@
static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN";
static const std::string P5 = "P5";
-
+
podarray<char> raw_header(ARMA_MAT_TXT.length() + 1);
std::streampos pos = f.tellg();
@@ -1233,6 +1233,7 @@
f.read(raw_header.memptr(), ARMA_MAT_TXT.length());
raw_header[ARMA_MAT_TXT.length()] = '\0';
+ f.clear();
f.seekg(pos);
const std::string header = raw_header.mem;
@@ -1721,6 +1722,7 @@
f.read(raw_header.memptr(), ARMA_CUB_TXT.length());
raw_header[ARMA_CUB_TXT.length()] = '\0';
+ f.clear();
f.seekg(pos);
const std::string header = raw_header.mem;
@@ -2081,9 +2083,12 @@
podarray<char> raw_header(ARMA_FLD_BIN.length() + 1);
std::streampos pos = f.tellg();
+
f.read(raw_header.memptr(), ARMA_FLD_BIN.length());
+
+ f.clear();
f.seekg(pos);
-
+
raw_header[ARMA_FLD_BIN.length()] = '\0';
const std::string header = raw_header.mem;
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/eop_aux.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/eop_aux.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/eop_aux.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -46,33 +46,60 @@
template<typename eT>
struct eop_aux_randn
{
- // TODO: implement a more efficient method for randn()
- //
- // possible option:
- // Marsaglia and Tsang Ziggurat technique to transform from a uniform to a normal distribution.
- // G. Marsaglia, W.W. Tsang.
- // "Ziggurat method for generating random variables",
- // J. Statistical Software, vol 5, 2000.
- // http://www.jstatsoft.org/v05/i08/
+ // // rudimentary method, based on the central limit theorem
+ // // http://en.wikipedia.org/wiki/Central_limit_theorem
+ // inline
+ // operator eT () const
+ // {
+ // const u32 N = 12; // N must be >= 12 and an even number
+ // const u32 N2 = N/2;
+ //
+ // eT acc = eT(0);
+ //
+ // for(u32 i=0; i<N2; ++i)
+ // {
+ // const eT tmp1 = eT(std::rand()) / eT(RAND_MAX);
+ // const eT tmp2 = eT(std::rand()) / eT(RAND_MAX);
+ // acc += tmp1+tmp2;
+ // }
+ //
+ // return acc - eT(N2);
+ // }
+
+ // polar form of the Box-Muller transformation
+ // http://en.wikipedia.org/wiki/Box-Muller_transformation
+ // http://en.wikipedia.org/wiki/Marsaglia_polar_method
inline
operator eT () const
{
- const u32 N = 12; // N must be >= 12 and an even number
- const u32 N2 = N/2;
+ // make sure we are internally using at least floats
+ typedef typename promote_type<eT,float>::result eTp;
- eT acc = eT(0);
+ eTp tmp1;
+ eTp tmp2;
+ eTp w;
- for(u32 i=0; i<N2; ++i)
+ do
{
- const eT tmp1 = eT(std::rand()) / eT(RAND_MAX);
- const eT tmp2 = eT(std::rand()) / eT(RAND_MAX);
- acc += tmp1+tmp2;
+ tmp1 = eTp(2) * eTp(std::rand()) / eTp(RAND_MAX) - eTp(1);
+ tmp2 = eTp(2) * eTp(std::rand()) / eTp(RAND_MAX) - eTp(1);
+ w = tmp1*tmp1 + tmp2*tmp2;
}
+ while ( w >= eTp(1) );
- return acc - eT(N2);
+ return eT( tmp1 * std::sqrt( (eTp(-2) * std::log(w)) / w) );
}
+
+ // other methods:
+ // http://en.wikipedia.org/wiki/Ziggurat_algorithm
+ //
+ // Marsaglia and Tsang Ziggurat technique to transform from a uniform to a normal distribution.
+ // G. Marsaglia, W.W. Tsang.
+ // "Ziggurat method for generating random variables",
+ // J. Statistical Software, vol 5, 2000.
+ // http://www.jstatsoft.org/v05/i08/
};
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/field_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/field_meat.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/field_meat.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -720,6 +720,241 @@
+template<typename oT>
+inline
+field<oT>::iterator::iterator(field<oT>& in_M, const bool at_end)
+ : M(in_M)
+ , i( (at_end == false) ? 0 : in_M.n_elem )
+ {
+ arma_extra_debug_sigprint();
+ }
+
+
+
+template<typename oT>
+inline
+oT&
+field<oT>::iterator::operator*()
+ {
+ return M[i];
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::iterator&
+field<oT>::iterator::operator++()
+ {
+ ++i;
+
+ return *this;
+ }
+
+
+
+template<typename oT>
+inline
+void
+field<oT>::iterator::operator++(int)
+ {
+ operator++();
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::iterator&
+field<oT>::iterator::operator--()
+ {
+ if(i > 0)
+ {
+ --i;
+ }
+
+ return *this;
+ }
+
+
+
+template<typename oT>
+inline
+void
+field<oT>::iterator::operator--(int)
+ {
+ operator--();
+ }
+
+
+
+template<typename oT>
+inline
+bool
+field<oT>::iterator::operator!=(const typename field<oT>::iterator& X) const
+ {
+ return (i != X.i);
+ }
+
+
+
+template<typename oT>
+inline
+bool
+field<oT>::iterator::operator==(const typename field<oT>::iterator& X) const
+ {
+ return (i == X.i);
+ }
+
+
+
+template<typename oT>
+inline
+field<oT>::const_iterator::const_iterator(const field<oT>& in_M, const bool at_end)
+ : M(in_M)
+ , i( (at_end == false) ? 0 : in_M.n_elem )
+ {
+ arma_extra_debug_sigprint();
+ }
+
+
+
+template<typename oT>
+inline
+field<oT>::const_iterator::const_iterator(const field<oT>::iterator& X)
+ : M(X.M)
+ , i(X.i)
+ {
+ arma_extra_debug_sigprint();
+ }
+
+
+
+template<typename oT>
+inline
+const oT&
+field<oT>::const_iterator::operator*() const
+ {
+ return M[i];
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::const_iterator&
+field<oT>::const_iterator::operator++()
+ {
+ ++i;
+
+ return *this;
+ }
+
+
+
+template<typename oT>
+inline
+void
+field<oT>::const_iterator::operator++(int)
+ {
+ operator++();
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::const_iterator&
+field<oT>::const_iterator::operator--()
+ {
+ if(i > 0)
+ {
+ --i;
+ }
+
+ return *this;
+ }
+
+
+
+template<typename oT>
+inline
+void
+field<oT>::const_iterator::operator--(int)
+ {
+ operator--();
+ }
+
+
+
+template<typename oT>
+inline
+bool
+field<oT>::const_iterator::operator!=(const typename field<oT>::const_iterator& X) const
+ {
+ return (i != X.i);
+ }
+
+
+
+template<typename oT>
+inline
+bool
+field<oT>::const_iterator::operator==(const typename field<oT>::const_iterator& X) const
+ {
+ return (i == X.i);
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::iterator
+field<oT>::begin()
+ {
+ arma_extra_debug_sigprint();
+
+ return field<oT>::iterator(*this);
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::const_iterator
+field<oT>::begin() const
+ {
+ arma_extra_debug_sigprint();
+
+ return field<oT>::const_iterator(*this);
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::iterator
+field<oT>::end()
+ {
+ arma_extra_debug_sigprint();
+
+ return field<oT>::iterator(*this, true);
+ }
+
+
+
+template<typename oT>
+inline
+typename field<oT>::const_iterator
+field<oT>::end() const
+ {
+ arma_extra_debug_sigprint();
+
+ return field<oT>::const_iterator(*this, true);
+ }
+
+
+
//
//
//
Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/field_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/field_proto.hpp 2010-05-04 02:31:58 UTC (rev 1151)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/field_proto.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -104,6 +104,59 @@
inline void load( std::istream& is, const file_type type = auto_detect);
+ // iterators
+
+ class iterator
+ {
+ public:
+
+ inline iterator(field<oT>& in_M, const bool at_end = false);
+
+ inline oT& operator* ();
+
+ inline iterator& operator++();
+ inline void operator++(int);
+
+ inline iterator& operator--();
+ inline void operator--(int);
+
+ inline bool operator!=(const iterator& X) const;
+ inline bool operator==(const iterator& X) const;
+
+ arma_aligned field<oT>& M;
+ arma_aligned u32 i;
+ };
+
+
+ class const_iterator
+ {
+ public:
+
+ const_iterator(const field<oT>& in_M, const bool at_end = false);
+ const_iterator(const iterator& X);
+
+ inline const oT& operator*() const;
+
+ inline const_iterator& operator++();
+ inline void operator++(int);
+
+ inline const_iterator& operator--();
+ inline void operator--(int);
+
+ inline bool operator!=(const const_iterator& X) const;
+ inline bool operator==(const const_iterator& X) const;
+
+ arma_aligned const field<oT>& M;
+ arma_aligned u32 i;
+ };
+
+ inline iterator begin();
+ inline const_iterator begin() const;
+
+ inline iterator end();
+ inline const_iterator end() const;
+
+
private:
inline void init(const field<oT>& x);
Added: pkg/RcppArmadillo/inst/include/armadillo_bits/fn_find.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/fn_find.hpp (rev 0)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/fn_find.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -0,0 +1,96 @@
+// Copyright (C) 2010 NICTA and the authors listed below
+// http://nicta.com.au
+//
+// Authors:
+// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
+// - Conrad Sanderson (conradsand at ieee dot org)
+//
+// This file is part of the Armadillo C++ library.
+// It is provided without any warranty of fitness
+// for any purpose. You can redistribute this file
+// and/or modify it under the terms of the GNU
+// Lesser General Public License (LGPL) as published
+// by the Free Software Foundation, either version 3
+// of the License or (at your option) any later version.
+// (see http://www.opensource.org/licenses for more info)
+
+
+//! \addtogroup fn_find
+//! @{
+
+
+
+template<typename eT>
+arma_hot
+inline
+u32
+find_helper(u32* out_mem, const eT* in_mem, const u32 n_elem)
+ {
+ arma_extra_debug_sigprint();
+
+ u32 n_nz = 0;
+
+ for(u32 i=0; i<n_elem; ++i)
+ {
+ if(in_mem[i] != eT(0))
+ {
+ out_mem[n_nz] = i;
+ ++n_nz;
+ }
+ }
+
+ return n_nz;
+ }
+
+
+// TODO:
+// once the relational operators are changed into delayed operations,
+// find() will need special handling of relational operators to gain speed
+template<typename T1>
+inline
+Mat<u32>
+find(const Base<typename T1::elem_type,T1>& X, const u32 k = 0, const char* direction = "first")
+ {
+ arma_extra_debug_sigprint();
+
+ typedef typename T1::elem_type eT;
+
+ const unwrap<T1> tmp(X.get_ref());
+ const Mat<eT>& A = tmp.M;
+
+ const u32 n_elem = A.n_elem;
+
+ Mat<u32> indices(n_elem, 1);
+
+ const u32 n_nz = find_helper(indices.memptr(), A.memptr(), n_elem);
+
+ const char sig = direction[0];
+
+ // return the indices of all n_nz elements, otherwise return an empty matrix
+ if(n_nz > 0)
+ {
+ if(sig == 'f' || sig == 'F') // "first"
+ {
+ return ( (k > 0 && k <= n_nz) ? indices.rows(0, k-1 ) : indices.rows(0, n_nz-1) );
+ }
+ else
+ if(sig == 'l' || sig == 'L') // "last"
+ {
+ return ( (k > 0 && k <= n_nz) ? indices.rows(n_nz-k, n_nz-1) : indices.rows(0, n_nz-1) );
+ }
+ else
+ {
+ arma_stop("find(): 3rd input argument must be \"first\" or \"last\"");
+
+ return Mat<u32>();
+ }
+ }
+ else
+ {
+ return Mat<u32>();
+ }
+ }
+
+
+
+//! @}
Added: pkg/RcppArmadillo/inst/include/armadillo_bits/fn_join.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/fn_join.hpp (rev 0)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/fn_join.hpp 2010-05-04 02:53:42 UTC (rev 1152)
@@ -0,0 +1,46 @@
+// Copyright (C) 2010 NICTA and the authors listed below
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rcpp -r 1152
More information about the Rcpp-commits
mailing list