[Rcpp-commits] r2540 - pkg/Rcpp/inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 26 16:11:12 CET 2010
Author: romain
Date: 2010-11-26 16:11:12 +0100 (Fri, 26 Nov 2010)
New Revision: 2540
Modified:
pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
Log:
use Rf_allocMatrix from the R API
Modified: pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h 2010-11-26 15:03:58 UTC (rev 2539)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h 2010-11-26 15:11:12 UTC (rev 2540)
@@ -47,9 +47,8 @@
Matrix( const Dimension& dims) throw(not_compatible) : VECTOR(), nrows(dims[0]) {
if( dims.size() != 2 ) throw not_compatible("not a matrix") ;
- VECTOR::setSEXP( Rf_allocVector( RTYPE, dims.prod() ) ) ;
+ VECTOR::setSEXP( Rf_allocMatrix( RTYPE, dims[0], dims[1] ) ) ;
VECTOR::init() ;
- VECTOR::attr( "dim" ) = dims ;
}
Matrix( const int& nrows_, const int& ncols) :
@@ -84,13 +83,7 @@
template <bool NA, typename MAT>
Matrix( const MatrixBase<RTYPE,NA,MAT>& other ) : VECTOR(), nrows(other.nrow()) {
int nc = other.ncol() ;
- SEXP x = PROTECT( Rf_allocVector( RTYPE, nrows * nc ) ) ;
- SEXP d = PROTECT( Rf_allocVector( INTSXP, 2) ) ;
- INTEGER(d)[0] = nrows ;
- INTEGER(d)[1] = nc ;
- Rf_setAttrib( x, R_DimSymbol, d ) ;
- RObject::setSEXP( x ) ;
- UNPROTECT( 2 ) ;
+ RObject::setSEXP( Rf_allocMatrix( RTYPE, nrows, nc ) ) ;
import_matrix_expression<NA,MAT>( other, nrows, nc ) ;
}
More information about the Rcpp-commits
mailing list