[Rcpp-commits] r1218 - in pkg/RcppGSL: inst inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu May 13 09:51:50 CEST 2010
Author: romain
Date: 2010-05-13 09:51:50 +0200 (Thu, 13 May 2010)
New Revision: 1218
Added:
pkg/RcppGSL/src/fastLm.cpp
Removed:
pkg/RcppGSL/inst/include/RcppGSL_caster.h
Modified:
pkg/RcppGSL/inst/ChangeLog
pkg/RcppGSL/inst/include/RcppGSL.h
pkg/RcppGSL/inst/include/RcppGSLForward.h
pkg/RcppGSL/inst/include/RcppGSL_matrix.h
pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h
pkg/RcppGSL/inst/include/RcppGSL_vector.h
pkg/RcppGSL/inst/include/RcppGSL_vector_view.h
Log:
resolve duplicate symbols issue
Modified: pkg/RcppGSL/inst/ChangeLog
===================================================================
--- pkg/RcppGSL/inst/ChangeLog 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/ChangeLog 2010-05-13 07:51:50 UTC (rev 1218)
@@ -1,3 +1,11 @@
+2010-05-13 Romain Francois <romain at r-enthusiasts.com>
+
+ * inst/include/*.h: wrap specializations are now inline
+
+2010-05-12 Dirk Eddelbuettel <edd at debian.org>
+
+ * src/fastLm.cpp : added fastLm from Rcpp examples
+
2010-05-12 Romain Francois <romain at r-enthusiasts.com>
* inst/include/*.h: added classes RcppGSL::vector<T> that act as smart pointers
Modified: pkg/RcppGSL/inst/include/RcppGSL.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSL.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -21,9 +21,9 @@
#define RCPPGSL__RCPPGSL_H
#include <RcppGSLForward.h>
+
#include <Rcpp.h>
-#include <RcppGSL_caster.h>
#include <RcppGSL_vector.h>
#include <RcppGSL_matrix.h>
#include <RcppGSL_vector_view.h>
Modified: pkg/RcppGSL/inst/include/RcppGSLForward.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSLForward.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSLForward.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -50,15 +50,46 @@
}
namespace internal{
- template<> gsl_complex caster<Rcomplex,gsl_complex>( Rcomplex from) ;
- template<> Rcomplex caster<gsl_complex,Rcomplex>( gsl_complex from) ;
+
+ template<> inline gsl_complex caster<Rcomplex,gsl_complex>( Rcomplex from){
+ gsl_complex x ;
+ GSL_REAL(x) = from.r ;
+ GSL_IMAG(x) = from.i ;
+ return x ;
+ }
+ template<> inline Rcomplex caster<gsl_complex,Rcomplex>( gsl_complex from){
+ Rcomplex x ;
+ x.r = GSL_REAL(from) ;
+ x.i = GSL_IMAG(from) ;
+ return x ;
+ }
- template<> gsl_complex_float caster<Rcomplex,gsl_complex_float>( Rcomplex from) ;
- template<> Rcomplex caster<gsl_complex_float,Rcomplex>( gsl_complex_float from) ;
-
- template<> gsl_complex_long_double caster<Rcomplex,gsl_complex_long_double>( Rcomplex from) ;
- template<> Rcomplex caster<gsl_complex_long_double,Rcomplex>( gsl_complex_long_double from) ;
- }
+ template<> inline gsl_complex_float caster<Rcomplex,gsl_complex_float>( Rcomplex from){
+ gsl_complex_float x ;
+ GSL_REAL(x) = static_cast<float>( from.r ) ;
+ GSL_IMAG(x) = static_cast<float>( from.i ) ;
+ return x ;
+ }
+ template<> inline Rcomplex caster<gsl_complex_float,Rcomplex>( gsl_complex_float from){
+ Rcomplex x ;
+ x.r = static_cast<double>( GSL_REAL(from) ) ;
+ x.i = static_cast<double>( GSL_IMAG(from) ) ;
+ return x ;
+ }
+
+ template<> inline gsl_complex_long_double caster<Rcomplex,gsl_complex_long_double>( Rcomplex from){
+ gsl_complex_long_double x ;
+ GSL_REAL(x) = static_cast<float>( from.r ) ;
+ GSL_IMAG(x) = static_cast<float>( from.i ) ;
+ return x ;
+ }
+ template<> inline Rcomplex caster<gsl_complex_long_double,Rcomplex>( gsl_complex_long_double from){
+ Rcomplex x ;
+ x.r = static_cast<double>( GSL_REAL(from) ) ;
+ x.i = static_cast<double>( GSL_IMAG(from) ) ;
+ return x ;
+ }
+ }
}
@@ -116,39 +147,6 @@
} \
} ; \
-// template <> class matrix<__T__> { \
-// public: \
-// typedef __T__ type ; \
-// typedef __T__* pointer ; \
-// typedef gsl_matrix##__SUFFIX__ gsltype ; \
-// gsltype* data ; \
-// const static int RTYPE = ::Rcpp::traits::r_sexptype_traits<type>::rtype ; \
-// matrix( SEXP x) throw(::Rcpp::not_compatible) : data(0) { \
-// if( !Rf_isMatrix(x) ) throw not_compatible("not a matrix") ; \
-// SEXP y = ::Rcpp::internal::rowmajor_wrap( ) ; \
-// data = gsl_matrix##__SUFFIX__##_calloc( size ) ; \
-// ::Rcpp::internal::export_range<__CAST__*>( y, \
-// reinterpret_cast<__CAST__*>( data->data ) ) ; \
-// } \
-// matrix( gsltype* x) : data(x) {} \
-// matrix( int nrow, int ncol) : \
-// data( gsl_matrix##__SUFFIX__##_alloc( nrow, ncol ) ){} \
-// ~matrix(){ } \
-// operator gsltype*(){ return data ; } \
-// gsltype* operator->() const { return data; } \
-// gsltype& operator*() const { return *data; } \
-// matrix( const matrix& x) : data(x.data) {} \
-// matrix& operator=(const matrix& other) { \
-// data = other.data ; \
-// return *this ; \
-// } \
-// void free(){ \
-// gsl_matrix##__SUFFIX__##_free(data) ; \
-// } \
-// } ; \
-//
-
-
_RCPPGSL_SPEC(double , , double )
_RCPPGSL_SPEC(float , _float , float )
_RCPPGSL_SPEC(int , _int , int )
@@ -172,96 +170,29 @@
/* forward declarations */
namespace Rcpp{
- template <> SEXP wrap( const gsl_vector& ) ;
- template <> SEXP wrap( const gsl_vector_int& ) ;
- template <> SEXP wrap( const gsl_vector_float& ) ;
- template <> SEXP wrap( const gsl_vector_long& ) ;
- template <> SEXP wrap( const gsl_vector_char& ) ;
- template <> SEXP wrap( const gsl_vector_complex& ) ;
- template <> SEXP wrap( const gsl_vector_complex_float& ) ;
- template <> SEXP wrap( const gsl_vector_complex_long_double& ) ;
- template <> SEXP wrap( const gsl_vector_long_double& ) ;
- template <> SEXP wrap( const gsl_vector_short& ) ;
- template <> SEXP wrap( const gsl_vector_uchar& ) ;
- template <> SEXP wrap( const gsl_vector_uint& ) ;
- template <> SEXP wrap( const gsl_vector_ushort& ) ;
- template <> SEXP wrap( const gsl_vector_ulong& ) ;
-
- template <> SEXP wrap( const gsl_vector_view& ) ;
- template <> SEXP wrap( const gsl_vector_int_view& ) ;
- template <> SEXP wrap( const gsl_vector_float_view& ) ;
- template <> SEXP wrap( const gsl_vector_long_view& ) ;
- template <> SEXP wrap( const gsl_vector_char_view& ) ;
- template <> SEXP wrap( const gsl_vector_complex_view& ) ;
- template <> SEXP wrap( const gsl_vector_complex_float_view& ) ;
- template <> SEXP wrap( const gsl_vector_complex_long_double_view& ) ;
- template <> SEXP wrap( const gsl_vector_long_double_view& ) ;
- template <> SEXP wrap( const gsl_vector_short_view& ) ;
- template <> SEXP wrap( const gsl_vector_uchar_view& ) ;
- template <> SEXP wrap( const gsl_vector_uint_view& ) ;
- template <> SEXP wrap( const gsl_vector_ushort_view& ) ;
- template <> SEXP wrap( const gsl_vector_ulong_view& ) ;
-
- template <> SEXP wrap( const gsl_vector_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_int_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_float_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_long_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_char_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_complex_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_complex_float_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_complex_long_double_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_long_double_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_short_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_uchar_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_uint_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_ushort_const_view& ) ;
- template <> SEXP wrap( const gsl_vector_ulong_const_view& ) ;
+#undef _RCPPGSL_WRAPDEF
+#define _RCPPGSL_WRAPDEF(__SUFFIX__) \
+template<> inline SEXP wrap( const gsl_vector##__SUFFIX__& ) ; \
+template<> inline SEXP wrap( const gsl_vector##__SUFFIX__##_view& ) ; \
+template<> inline SEXP wrap( const gsl_vector##__SUFFIX__##_const_view& ) ; \
+template<> inline SEXP wrap( const gsl_matrix##__SUFFIX__& ) ; \
+template<> inline SEXP wrap( const gsl_matrix##__SUFFIX__##_view& ) ; \
+template<> inline SEXP wrap( const gsl_matrix##__SUFFIX__##_const_view& ) ;
-
- template <> SEXP wrap( const gsl_matrix& ) ;
- template <> SEXP wrap( const gsl_matrix_int& ) ;
- template <> SEXP wrap( const gsl_matrix_float& ) ;
- template <> SEXP wrap( const gsl_matrix_long& ) ;
- template <> SEXP wrap( const gsl_matrix_char& ) ;
- template <> SEXP wrap( const gsl_matrix_complex& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_float& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_long_double& ) ;
- template <> SEXP wrap( const gsl_matrix_long_double& ) ;
- template <> SEXP wrap( const gsl_matrix_short& ) ;
- template <> SEXP wrap( const gsl_matrix_uchar& ) ;
- template <> SEXP wrap( const gsl_matrix_uint& ) ;
- template <> SEXP wrap( const gsl_matrix_ushort& ) ;
- template <> SEXP wrap( const gsl_matrix_ulong& ) ;
-
- template <> SEXP wrap( const gsl_matrix_view& ) ;
- template <> SEXP wrap( const gsl_matrix_int_view& ) ;
- template <> SEXP wrap( const gsl_matrix_float_view& ) ;
- template <> SEXP wrap( const gsl_matrix_long_view& ) ;
- template <> SEXP wrap( const gsl_matrix_char_view& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_view& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_float_view& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_long_double_view& ) ;
- template <> SEXP wrap( const gsl_matrix_long_double_view& ) ;
- template <> SEXP wrap( const gsl_matrix_short_view& ) ;
- template <> SEXP wrap( const gsl_matrix_uchar_view& ) ;
- template <> SEXP wrap( const gsl_matrix_uint_view& ) ;
- template <> SEXP wrap( const gsl_matrix_ushort_view& ) ;
- template <> SEXP wrap( const gsl_matrix_ulong_view& ) ;
-
- template <> SEXP wrap( const gsl_matrix_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_int_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_float_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_long_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_char_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_float_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_complex_long_double_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_long_double_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_short_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_uchar_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_uint_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_ushort_const_view& ) ;
- template <> SEXP wrap( const gsl_matrix_ulong_const_view& ) ;
+_RCPPGSL_WRAPDEF()
+_RCPPGSL_WRAPDEF(_int )
+_RCPPGSL_WRAPDEF(_float )
+_RCPPGSL_WRAPDEF(_long )
+_RCPPGSL_WRAPDEF(_char )
+_RCPPGSL_WRAPDEF(_complex )
+_RCPPGSL_WRAPDEF(_complex_float )
+_RCPPGSL_WRAPDEF(_complex_long_double )
+_RCPPGSL_WRAPDEF(_long_double )
+_RCPPGSL_WRAPDEF(_short )
+_RCPPGSL_WRAPDEF(_uchar )
+_RCPPGSL_WRAPDEF(_uint )
+_RCPPGSL_WRAPDEF(_ushort )
+_RCPPGSL_WRAPDEF(_ulong )
template <typename T> SEXP wrap( const ::RcppGSL::vector<T>& ) ;
template <typename T> SEXP wrap( const ::RcppGSL::vector_view<T>& ) ;
Deleted: pkg/RcppGSL/inst/include/RcppGSL_caster.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL_caster.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSL_caster.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -1,73 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
-//
-// RcppGSL.h: Rcpp/GSL glue
-//
-// Copyright (C) 2010 Romain Francois and Dirk Eddelbuettel
-//
-// This file is part of RcppGSL.
-//
-// RcppGSL 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.
-//
-// RcppGSL 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 RcppGSL. If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef RCPPGSL__RCPPGSL_CASTER_H
-#define RCPPGSL__RCPPGSL_CASTER_H
-
-#include <RcppGSLForward.h>
-#include <Rcpp.h>
-
-namespace Rcpp{
-
- namespace internal{
- template<> gsl_complex caster<Rcomplex,gsl_complex>( Rcomplex from){
- gsl_complex x ;
- GSL_REAL(x) = from.r ;
- GSL_IMAG(x) = from.i ;
- return x ;
- }
- template<> Rcomplex caster<gsl_complex,Rcomplex>( gsl_complex from){
- Rcomplex x ;
- x.r = GSL_REAL(from) ;
- x.i = GSL_IMAG(from) ;
- return x ;
- }
-
- template<> gsl_complex_float caster<Rcomplex,gsl_complex_float>( Rcomplex from){
- gsl_complex_float x ;
- GSL_REAL(x) = static_cast<float>( from.r ) ;
- GSL_IMAG(x) = static_cast<float>( from.i ) ;
- return x ;
- }
- template<> Rcomplex caster<gsl_complex_float,Rcomplex>( gsl_complex_float from){
- Rcomplex x ;
- x.r = static_cast<double>( GSL_REAL(from) ) ;
- x.i = static_cast<double>( GSL_IMAG(from) ) ;
- return x ;
- }
-
- template<> gsl_complex_long_double caster<Rcomplex,gsl_complex_long_double>( Rcomplex from){
- gsl_complex_long_double x ;
- GSL_REAL(x) = static_cast<float>( from.r ) ;
- GSL_IMAG(x) = static_cast<float>( from.i ) ;
- return x ;
- }
- template<> Rcomplex caster<gsl_complex_long_double,Rcomplex>( gsl_complex_long_double from){
- Rcomplex x ;
- x.r = static_cast<double>( GSL_REAL(from) ) ;
- x.i = static_cast<double>( GSL_IMAG(from) ) ;
- return x ;
- }
- }
-
-}
-
-#endif
Modified: pkg/RcppGSL/inst/include/RcppGSL_matrix.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL_matrix.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSL_matrix.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -24,7 +24,6 @@
#include <RcppGSLForward.h>
#include <Rcpp.h>
-#include <RcppGSL_caster.h>
namespace RcppGSL {
Modified: pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -24,7 +24,6 @@
#include <RcppGSLForward.h>
#include <Rcpp.h>
-#include <RcppGSL_caster.h>
namespace Rcpp{
Modified: pkg/RcppGSL/inst/include/RcppGSL_vector.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL_vector.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSL_vector.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -24,7 +24,6 @@
#include <RcppGSLForward.h>
#include <Rcpp.h>
-#include <RcppGSL_caster.h>
namespace RcppGSL{
@@ -56,7 +55,7 @@
}
#define RCPPGSL_WRAP_CAST(__TYPE__,__DATA__,__CAST__) \
-template <> SEXP wrap( const __TYPE__& x){ \
+template <> SEXP wrap( const __TYPE__& x){ \
return wrap( RcppGSL::gslvector_importer<__DATA__>( \
reinterpret_cast<__CAST__>(x.data), x.stride, x.size ) ) ; \
}
Modified: pkg/RcppGSL/inst/include/RcppGSL_vector_view.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL_vector_view.h 2010-05-13 00:37:26 UTC (rev 1217)
+++ pkg/RcppGSL/inst/include/RcppGSL_vector_view.h 2010-05-13 07:51:50 UTC (rev 1218)
@@ -24,7 +24,6 @@
#include <RcppGSLForward.h>
#include <Rcpp.h>
-#include <RcppGSL_caster.h>
namespace Rcpp{
Added: pkg/RcppGSL/src/fastLm.cpp
===================================================================
--- pkg/RcppGSL/src/fastLm.cpp (rev 0)
+++ pkg/RcppGSL/src/fastLm.cpp 2010-05-13 07:51:50 UTC (rev 1218)
@@ -0,0 +1,36 @@
+#include <RcppGSL.h>
+
+#include <gsl/gsl_multifit.h>
+
+
+extern "C" SEXP fastLm(SEXP ys, SEXP Xs) {
+
+ Rcpp::NumericVector Yr(ys); // creates Rcpp vector from SEXP
+ Rcpp::NumericMatrix Xr(Xs); // creates Rcpp matrix from SEXP
+
+ int i,j,n = Xr.nrow(), k = Xr.ncol();
+ double chisq;
+
+ gsl_matrix *X = gsl_matrix_alloc (n, k);
+ gsl_vector *y = gsl_vector_alloc (n);
+ gsl_vector *c = gsl_vector_alloc (k);
+ gsl_matrix *cov = gsl_matrix_alloc (k, k);
+ for (i = 0; i < n; i++) {
+ for (j = 0; j < k; j++)
+ gsl_matrix_set (X, i, j, Xr(i,j));
+ gsl_vector_set (y, i, Yr(i));
+ }
+
+ gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k);
+ gsl_multifit_linear (X, y, c, cov, &chisq, work);
+ gsl_multifit_linear_free (work);
+
+
+ //Rcpp::NumericVector coefr = Rcpp::wrap(c);
+ RcppGSL::vector<double> coefr(5);
+ RcppGSL::vector<double> vec(ys);
+ //return Rcpp::List::create( Rcpp::Named( "coef", coefr),
+ // Rcpp::Named( "stderr", coefr));
+ return Xs;
+}
+
More information about the Rcpp-commits
mailing list