[Rcpp-commits] r1023 - in pkg/RcppGSL: inst/include inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 7 10:12:04 CEST 2010
Author: romain
Date: 2010-04-07 10:12:04 +0200 (Wed, 07 Apr 2010)
New Revision: 1023
Added:
pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h
Modified:
pkg/RcppGSL/inst/include/RcppGSL.h
pkg/RcppGSL/inst/include/RcppGSLForward.h
pkg/RcppGSL/inst/unitTests/runit.gsl.R
pkg/RcppGSL/src/RcppGSL.cpp
Log:
matrix views
Modified: pkg/RcppGSL/inst/include/RcppGSL.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL.h 2010-04-07 07:39:52 UTC (rev 1022)
+++ pkg/RcppGSL/inst/include/RcppGSL.h 2010-04-07 08:12:04 UTC (rev 1023)
@@ -27,5 +27,6 @@
#include <RcppGSL_vector.h>
#include <RcppGSL_matrix.h>
#include <RcppGSL_vector_view.h>
+#include <RcppGSL_matrix_view.h>
#endif
Modified: pkg/RcppGSL/inst/include/RcppGSLForward.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSLForward.h 2010-04-07 07:39:52 UTC (rev 1022)
+++ pkg/RcppGSL/inst/include/RcppGSLForward.h 2010-04-07 08:12:04 UTC (rev 1023)
@@ -103,6 +103,7 @@
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& ) ;
+
template <> SEXP wrap( const gsl_matrix& ) ;
template <> SEXP wrap( const gsl_matrix_int& ) ;
@@ -119,6 +120,36 @@
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& ) ;
+
}
#endif
Added: pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h (rev 0)
+++ pkg/RcppGSL/inst/include/RcppGSL_matrix_view.h 2010-04-07 08:12:04 UTC (rev 1023)
@@ -0,0 +1,55 @@
+// RcppGSL_matrix_view.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_MATRIX_VIEW_H
+#define RCPPGSL__RCPPGSL_MATRIX_VIEW_H
+
+#include <RcppGSLForward.h>
+#include <Rcpp.h>
+#include <RcppGSL_caster.h>
+
+namespace Rcpp{
+
+#define RCPPGSL_VIEW(SUFFIX) \
+template <> SEXP wrap( const gsl_matrix##SUFFIX##_view& x){ \
+ return wrap(x.matrix) ; \
+} ; \
+template <> SEXP wrap( const gsl_matrix##SUFFIX##_const_view& x ){ \
+ return wrap(x.matrix) ; \
+}
+
+RCPPGSL_VIEW()
+RCPPGSL_VIEW(_int) ;
+RCPPGSL_VIEW(_float) ;
+RCPPGSL_VIEW(_long) ;
+RCPPGSL_VIEW(_char) ;
+RCPPGSL_VIEW(_complex) ;
+RCPPGSL_VIEW(_complex_float) ;
+RCPPGSL_VIEW(_complex_long_double) ;
+RCPPGSL_VIEW(_long_double) ;
+RCPPGSL_VIEW(_short) ;
+RCPPGSL_VIEW(_uchar) ;
+RCPPGSL_VIEW(_uint) ;
+RCPPGSL_VIEW(_ushort) ;
+RCPPGSL_VIEW(_ulong) ;
+#undef RCPPGSL_VIEW
+
+}
+
+#endif
Modified: pkg/RcppGSL/inst/unitTests/runit.gsl.R
===================================================================
--- pkg/RcppGSL/inst/unitTests/runit.gsl.R 2010-04-07 07:39:52 UTC (rev 1022)
+++ pkg/RcppGSL/inst/unitTests/runit.gsl.R 2010-04-07 08:12:04 UTC (rev 1023)
@@ -75,6 +75,10 @@
checkEquals( res,
list( even = 2.0 * 0:4, odd = 2.0 * 0:4 + 1.0 ),
msg = "wrap( gsl.vector.view )" )
-
}
+test.gsl.matrix.view <- function(){
+ res <- .Call( "test_gsl_matrix_view", PACKAGE = "RcppGSL" )
+ checkEquals( res$full[3:4, 3:4], res$view, msg = "wrap(gsl.matrix.view)" )
+}
+
Modified: pkg/RcppGSL/src/RcppGSL.cpp
===================================================================
--- pkg/RcppGSL/src/RcppGSL.cpp 2010-04-07 07:39:52 UTC (rev 1022)
+++ pkg/RcppGSL/src/RcppGSL.cpp 2010-04-07 08:12:04 UTC (rev 1023)
@@ -123,3 +123,25 @@
return res ;
}
+
+extern "C" SEXP test_gsl_matrix_view(){
+ int nrow = 4 ;
+ int ncol = 6 ;
+ gsl_matrix *m = gsl_matrix_alloc(nrow, ncol);
+ int k =0 ;
+ for( int i=0 ; i<nrow; i++){
+ for( int j=0; j<ncol; j++, k++){
+ gsl_matrix_set( m, i, j, k ) ;
+ }
+ }
+ gsl_matrix_view x = gsl_matrix_submatrix(m, 2, 2, 2, 2 ) ;
+
+ List res = List::create(
+ _["full"] = *m,
+ _["view"] = x
+ ) ;
+ gsl_matrix_free(m);
+
+ return res ;
+}
+
More information about the Rcpp-commits
mailing list