[Rcpp-commits] r2352 - in pkg/Rcpp: . inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 21 20:54:10 CEST 2010
Author: romain
Date: 2010-10-21 20:54:10 +0200 (Thu, 21 Oct 2010)
New Revision: 2352
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
Log:
Column gains operator=( sugar expression )
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2010-10-21 18:09:07 UTC (rev 2351)
+++ pkg/Rcpp/ChangeLog 2010-10-21 18:54:10 UTC (rev 2352)
@@ -6,6 +6,9 @@
* inst/unitTests/runit.Matrix.R: test the fix above based on the
R-help/Rcpp-devel thread: http://article.gmane.org/gmane.comp.lang.r.rcpp/851
+ * inst/include/Rcpp/vector/MatrixColumn.h: Column gains a operator= taking a
+ sugar expression
+
2010-10-21 Dirk Eddelbuettel <edd at debian.org>
* inst/include/Rcpp/Module.h: Reorder instantiation for class_
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h 2010-10-21 18:09:07 UTC (rev 2351)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h 2010-10-21 18:54:10 UTC (rev 2352)
@@ -41,10 +41,32 @@
index = other.index ;
}
-// template <int RT, bool NA, typename T>
-// MatrixColumn& operator=( const Rcpp::VectorBase<RT,NA,T>& rhs ){
-// std::copy( rhs.begin(), rhs.end(), begin() ) ;
-// }
+ template <int RT, bool NA, typename T>
+ MatrixColumn& operator=( const Rcpp::VectorBase<RT,NA,T>& rhs ){
+ iterator start = begin() ;
+ int n = size() ;
+ const T& ref = rhs.get_ref() ;
+
+ int __trip_count = n >> 2 ;
+ int i = 0 ;
+ for ( ; __trip_count > 0 ; --__trip_count) {
+ start[i] = ref[i] ; i++ ;
+ start[i] = ref[i] ; i++ ;
+ start[i] = ref[i] ; i++ ;
+ start[i] = ref[i] ; i++ ;
+ }
+ switch (n - i){
+ case 3:
+ start[i] = ref[i] ; i++ ;
+ case 2:
+ start[i] = ref[i] ; i++ ;
+ case 1:
+ start[i] = ref[i] ; i++ ;
+ case 0:
+ default:
+ {}
+ }
+ }
Proxy operator[]( int i ){
/* TODO: should we cache nrow and ncol */
More information about the Rcpp-commits
mailing list