[Rcpp-commits] r1730 - in pkg/Rcpp: inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 25 16:44:39 CEST 2010
Author: romain
Date: 2010-06-25 16:44:39 +0200 (Fri, 25 Jun 2010)
New Revision: 1730
Added:
pkg/Rcpp/inst/include/RcppMatrix__backward.h
Modified:
pkg/Rcpp/inst/include/Rcpp.h
pkg/Rcpp/inst/include/RcppMatrix.h
pkg/Rcpp/inst/include/RcppResultSet.h
pkg/Rcpp/inst/include/RcppResultSet__backward.h
pkg/Rcpp/src/RcppResultSet.cpp
Log:
let the compiler do the copy and paste
Modified: pkg/Rcpp/inst/include/Rcpp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp.h 2010-06-25 14:07:41 UTC (rev 1729)
+++ pkg/Rcpp/inst/include/Rcpp.h 2010-06-25 14:44:39 UTC (rev 1730)
@@ -82,5 +82,6 @@
#include <RcppResultSet__backward.h>
#include <RcppList__backward.h>
+#include <RcppMatrix__backward.h>
#endif
Modified: pkg/Rcpp/inst/include/RcppMatrix.h
===================================================================
--- pkg/Rcpp/inst/include/RcppMatrix.h 2010-06-25 14:07:41 UTC (rev 1729)
+++ pkg/Rcpp/inst/include/RcppMatrix.h 2010-06-25 14:44:39 UTC (rev 1730)
@@ -139,4 +139,13 @@
return temp;
}
+namespace Rcpp{
+
+template <> SEXP wrap( const RcppMatrix<int>& );
+
+template <> SEXP wrap( const RcppMatrix<double>& );
+
+}
+
+
#endif
Added: pkg/Rcpp/inst/include/RcppMatrix__backward.h
===================================================================
--- pkg/Rcpp/inst/include/RcppMatrix__backward.h (rev 0)
+++ pkg/Rcpp/inst/include/RcppMatrix__backward.h 2010-06-25 14:44:39 UTC (rev 1730)
@@ -0,0 +1,54 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// RcppMatrix_backward.h: Rcpp R/C++ interface class library -- templated matrix support
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RcppMatrix__backward_h
+#define RcppMatrix__backward_h
+
+#include <RcppCommon.h>
+
+namespace Rcpp{
+namespace internal{
+
+ template <typename T>
+ SEXP wrap__old__rcppmatrix( const ::RcppMatrix<T>& x ){
+ int nx = x.rows() ;
+ int ny = x.cols() ;
+ Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat( nx, ny ) ;
+ for (int i = 0; i < nx; i++)
+ for (int j = 0; j < ny; j++)
+ mat[i + nx*j] = x(i,j);
+ return mat ;
+ }
+}
+
+template <>
+inline SEXP wrap( const RcppMatrix<int>& x){
+ return internal::wrap__old__rcppmatrix( x );
+}
+template <>
+inline SEXP wrap( const RcppMatrix<double>& x){
+ return internal::wrap__old__rcppmatrix( x );
+}
+
+
+}
+
+#endif
Modified: pkg/Rcpp/inst/include/RcppResultSet.h
===================================================================
--- pkg/Rcpp/inst/include/RcppResultSet.h 2010-06-25 14:07:41 UTC (rev 1729)
+++ pkg/Rcpp/inst/include/RcppResultSet.h 2010-06-25 14:44:39 UTC (rev 1730)
@@ -52,30 +52,20 @@
typedef std::list<PAIR> LIST ;
RcppResultSet();
- void add(std::string, double);
- void add(std::string, int);
- void add(std::string, std::string);
- void add(std::string, double *, int);
- void add(std::string, int *, int);
- void add(std::string, double **, int, int);
- void add(std::string, int **, int, int);
- void add(std::string, RcppDate&);
- void add(std::string, RcppDateVector&);
- void add(std::string, RcppDatetime&);
- void add(std::string, RcppDatetimeVector&);
- void add(std::string, RcppStringVector&);
- void add(std::string, std::vector<double>&);
- void add(std::string, std::vector<int>&);
- void add(std::string, std::vector<std::vector<double> >&);
- void add(std::string, std::vector<std::vector<int> >&);
- void add(std::string, std::vector<std::string>&);
- void add(std::string, RcppVector<int>&);
- void add(std::string, RcppVector<double>&);
- void add(std::string, RcppMatrix<int>&);
- void add(std::string, RcppMatrix<double>&);
- void add(std::string, RcppFrame&);
- void add(std::string, RcppList&);
- void add(std::string, SEXP, bool isProtected);
+
+ template <typename T>
+ void add(const std::string& name, const T& object){
+ return add__impl( name, object ) ;
+ }
+
+ void add(const std::string&, double *, int);
+ void add(const std::string&, int *, int);
+ void add(const std::string&, double **, int, int);
+ void add(const std::string&, int **, int, int);
+
+ void add(const std::string& name , const std::vector<std::vector<double> >& object) ;
+ void add(const std::string& name , const std::vector<std::vector<int> >& object) ;
+
SEXP getReturnList();
SEXP getSEXP();
@@ -90,15 +80,15 @@
numProtected++ ;
}
- // defined later because it needs wrap
template <typename T>
- void add__impl( const std::string& name, const T& t ) ;
-
+ void add__impl( const std::string&, const T& ) ;
+
template <typename T>
- void add__matrix( const std::string& name, T**, int nx, int ny ) ;
-
- template <typename T>
void add__matrix__std( const std::string& name, const std::vector<std::vector<T> >& mat ) throw(std::range_error) ;
+
+ template <typename T>
+ void add__matrix( const std::string& name, T**, int, int ) ;
+
};
#endif
Modified: pkg/Rcpp/inst/include/RcppResultSet__backward.h
===================================================================
--- pkg/Rcpp/inst/include/RcppResultSet__backward.h 2010-06-25 14:07:41 UTC (rev 1729)
+++ pkg/Rcpp/inst/include/RcppResultSet__backward.h 2010-06-25 14:44:39 UTC (rev 1730)
@@ -28,15 +28,6 @@
}
template <typename T>
-void RcppResultSet::add__matrix( const std::string& name, T** input, int nx, int ny ){
- Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat( nx, ny ) ;
- for (int i = 0; i < nx; i++)
- for (int j = 0; j < ny; j++)
- mat[i + nx*j] = input[i][j];
- push_back( name, mat );
-}
-
-template <typename T>
void RcppResultSet::add__matrix__std( const std::string& name, const std::vector<std::vector<T> >& mat ) throw(std::range_error) {
int nx = (int)mat.size();
if (nx == 0)
@@ -53,4 +44,14 @@
push_back( name, out );
}
+
+template <typename T>
+void RcppResultSet::add__matrix( const std::string& name, T** input, int nx, int ny) {
+ Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat( nx, ny ) ;
+ for (int i = 0; i < nx; i++)
+ for (int j = 0; j < ny; j++)
+ mat[i + nx*j] = input[i][j] ;
+ push_back( name, mat );
+}
+
#endif
Modified: pkg/Rcpp/src/RcppResultSet.cpp
===================================================================
--- pkg/Rcpp/src/RcppResultSet.cpp 2010-06-25 14:07:41 UTC (rev 1729)
+++ pkg/Rcpp/src/RcppResultSet.cpp 2010-06-25 14:44:39 UTC (rev 1730)
@@ -60,117 +60,38 @@
}
-void RcppResultSet::add(std::string name, RcppDate& date) {
- add__impl( name, date );
+void RcppResultSet::add(const std::string& name , const std::vector<std::vector<double> >& object){
+ return add__matrix__std( name, object ) ;
}
-void RcppResultSet::add(std::string name, RcppDatetime& datetime) {
- add__impl( name, datetime );
+void RcppResultSet::add(const std::string& name , const std::vector<std::vector<int> >& object){
+ return add__matrix__std( name, object ) ;
}
-
-void RcppResultSet::add(std::string name, double x) {
- add__impl( name, x );
-}
-
-void RcppResultSet::add(std::string name, int i) {
- add__impl( name, i );
-}
-
-void RcppResultSet::add(std::string name, std::string strvalue) {
- add__impl( name, strvalue );
-}
-
-void RcppResultSet::add(std::string name, double *vec, int len) {
+
+void RcppResultSet::add(const std::string& name, double *vec, int len) {
if (vec == 0)
throw std::range_error("RcppResultSet::add: NULL double vector");
add__impl( name, Rcpp::wrap( vec, vec + len) );
}
-void RcppResultSet::add(std::string name, RcppDateVector& datevec) {
- add__impl( name, datevec ) ;
-}
-
-void RcppResultSet::add(std::string name, RcppDatetimeVector &dtvec) {
- add__impl( name, dtvec ) ;
-}
-
-void RcppResultSet::add(std::string name, RcppStringVector& stringvec) {
- add__impl( name, stringvec ) ;
-}
-
-void RcppResultSet::add(std::string name, int *vec, int len) {
+void RcppResultSet::add(const std::string& name, int *vec, int len) {
if (vec == 0)
throw std::range_error("RcppResultSet::add: NULL int vector");
add__impl( name, Rcpp::wrap( vec, vec + len) );
}
-void RcppResultSet::add(std::string name, double **mat, int nx, int ny) {
+void RcppResultSet::add(const std::string& name, double **mat, int nx, int ny) {
if (mat == 0)
throw std::range_error("RcppResultSet::add: NULL double matrix");
add__matrix( name, mat, nx, ny ) ;
}
-void RcppResultSet::add(std::string name, int **mat, int nx, int ny) {
+void RcppResultSet::add(const std::string& name, int **mat, int nx, int ny) {
if (mat == 0)
throw std::range_error("RcppResultSet::add: NULL int matrix");
add__matrix( name, mat, nx, ny ) ;
}
-void RcppResultSet::add(std::string name, std::vector<std::string>& vec) {
- if (vec.size() == 0)
- throw std::range_error("RcppResultSet::add; zero length vector<string>");
- add__impl( name, vec ) ;
-}
-
-void RcppResultSet::add(std::string name, std::vector<int>& vec) {
- if (vec.size() == 0)
- throw std::range_error("RcppResultSet::add; zero length vector<int>");
- add__impl( name, vec ) ;
-}
-
-void RcppResultSet::add(std::string name, std::vector<double>& vec) {
- if (vec.size() == 0)
- throw std::range_error("RcppResultSet::add; zero length vector<double>");
- add__impl( name, vec ) ;
-}
-
-void RcppResultSet::add(std::string name, std::vector<std::vector<int> >& mat) {
- add__matrix__std( name, mat ) ;
-}
-
-void RcppResultSet::add(std::string name, std::vector<std::vector<double> >& mat) {
- add__matrix__std( name, mat ) ;
-}
-
-void RcppResultSet::add(std::string name, RcppVector<int>& vec) {
- add__impl( name, vec ) ;
-}
-
-void RcppResultSet::add(std::string name, RcppVector<double>& vec) {
- add__impl( name, vec ) ;
-}
-
-void RcppResultSet::add(std::string name, RcppMatrix<int>& mat) {
- add__matrix( name, mat.cMatrix(), mat.getDim1(), mat.getDim2() ) ;
-}
-
-void RcppResultSet::add(std::string name, RcppMatrix<double>& mat) {
- add__matrix( name, mat.cMatrix(), mat.getDim1(), mat.getDim2() ) ;
-}
-
-
-void RcppResultSet::add(std::string name, RcppList &list) {
- add__impl( name, list ) ;
-}
-
-void RcppResultSet::add(std::string name, SEXP sexp, bool isProtected) {
- push_back(name, sexp);
-}
-
-void RcppResultSet::add(std::string name, RcppFrame& frame) {
- add__impl( name, frame ) ;
-}
-
SEXP RcppResultSet::getReturnList() {
SEXP rl = PROTECT( Rcpp::wrap( values ) ) ;
UNPROTECT(numProtected+1);
More information about the Rcpp-commits
mailing list