Skip to content

Commit 604b1d3

Browse files
committed
Merging pull request #94 from Kevin
2 parents 2676e02 + e3d76a5 commit 604b1d3

File tree

4 files changed

+56
-38
lines changed

4 files changed

+56
-38
lines changed

ChangeLog

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
2014-01-18 JJ Allaiare <jj@rstudio.org>
22

3-
* R/Attributes.R: More restrictive matching of c++ file extensions
3+
* R/Attributes.R: More restrictive matching of C++ file extensions
44
for compileAttributes.
55

6+
2014-01-18 Kevin Ushey <kevinushey@gmail.com>
7+
8+
* inst/unitTests/cpp/Matrix.cpp: Add unit test
9+
* inst/unitTests/runit.Matrix.R: Add unit test
10+
* inst/include/Rcpp/api/meat/Matrix.h: Bug fix in operator=
11+
612
2014-01-17 Dirk Eddelbuettel <edd@debian.org>
713

814
* R/RcppLdpath.R (RcppCxxFlags): Restore function to supply values
915
for include files for packages not yet converted to LinkingTo:
1016

1117
2014-01-16 JJ Allaiare <jj@rstudio.org>
1218

13-
* inst/include/Rcpp/macros/macros.h: Use Rf_onintr rather than
19+
* inst/include/Rcpp/macros/macros.h: Use Rf_onintr rather than
1420
non-public Rf_jump_to_toplevel
1521
* inst/include/Rcpp/DateVector.h: Fix GreedyVector compilation error
1622
* inst/include/Rcpp/DatetimeVector.h: Fix GreedyVector compilation error
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
3-
// Matrix.h: Rcpp R/C++ interface class library -- Matrix meat
3+
// Matrix.h: Rcpp R/C++ interface class library -- Matrix meat
44
//
55
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
66
//
@@ -22,102 +22,102 @@
2222
#ifndef Rcpp_api_meat_Matrix_h
2323
#define Rcpp_api_meat_Matrix_h
2424

25-
namespace Rcpp{
25+
namespace Rcpp{
2626

2727
template <int RTYPE, template <class> class StoragePolicy >
2828
Matrix<RTYPE, StoragePolicy>::Matrix(SEXP x) : VECTOR( r_cast<RTYPE>( x ) ), nrows( VECTOR::dims()[0] ) {}
29-
29+
3030
template <int RTYPE, template <class> class StoragePolicy >
3131
Matrix<RTYPE,StoragePolicy>::Matrix( const Dimension& dims) : VECTOR( Rf_allocMatrix( RTYPE, dims[0], dims[1] ) ), nrows(dims[0]) {
3232
if( dims.size() != 2 ) throw not_compatible("not a matrix") ;
3333
VECTOR::init() ;
3434
}
35-
35+
3636
template <int RTYPE, template <class> class StoragePolicy >
37-
Matrix<RTYPE,StoragePolicy>::Matrix( const int& nrows_, const int& ncols) :
38-
VECTOR( Dimension( nrows_, ncols ) ),
37+
Matrix<RTYPE,StoragePolicy>::Matrix( const int& nrows_, const int& ncols) :
38+
VECTOR( Dimension( nrows_, ncols ) ),
3939
nrows(nrows_)
4040
{}
41-
41+
4242
template <int RTYPE, template <class> class StoragePolicy >
4343
template <typename Iterator>
44-
Matrix<RTYPE,StoragePolicy>::Matrix( const int& nrows_, const int& ncols, Iterator start ) :
44+
Matrix<RTYPE,StoragePolicy>::Matrix( const int& nrows_, const int& ncols, Iterator start ) :
4545
VECTOR( start, start + (nrows_*ncols) ),
4646
nrows(nrows_)
4747
{
48-
VECTOR::attr( "dim" ) = Dimension( nrows, ncols ) ;
48+
VECTOR::attr( "dim" ) = Dimension( nrows, ncols ) ;
4949
}
50-
50+
5151
template <int RTYPE, template <class> class StoragePolicy >
5252
Matrix<RTYPE,StoragePolicy>::Matrix( const int& n) : VECTOR( Dimension( n, n ) ), nrows(n) {}
53-
53+
5454
template <int RTYPE, template <class> class StoragePolicy >
5555
Matrix<RTYPE,StoragePolicy>::Matrix( const Matrix& other) : VECTOR( other.get__() ), nrows(other.nrows) {}
56-
56+
5757
template <int RTYPE, template <class> class StoragePolicy >
5858
template <bool NA, typename MAT>
5959
Matrix<RTYPE,StoragePolicy>::Matrix( const MatrixBase<RTYPE,NA,MAT>& other ) : VECTOR( Rf_allocMatrix( RTYPE, other.nrow(), other.ncol() ) ), nrows(other.nrow()) {
6060
import_matrix_expression<NA,MAT>( other, nrows, ncol() ) ;
6161
}
62-
62+
6363
template <int RTYPE, template <class> class StoragePolicy >
6464
Matrix<RTYPE, StoragePolicy>& Matrix<RTYPE,StoragePolicy>::operator=(const Matrix& other) {
65-
SEXP x = VECTOR::get__() ;
65+
SEXP x = other.get__() ;
6666
if( ! ::Rf_isMatrix(x) ) not_compatible("not a matrix") ;
6767
VECTOR::set__( x ) ;
6868
nrows = other.nrows ;
6969
return *this ;
7070
}
71-
71+
7272
template <int RTYPE, template <class> class StoragePolicy >
7373
template <typename U>
7474
void Matrix<RTYPE,StoragePolicy>::fill_diag( const U& u){
75-
fill_diag__dispatch( typename traits::is_trivial<RTYPE>::type(), u ) ;
75+
fill_diag__dispatch( typename traits::is_trivial<RTYPE>::type(), u ) ;
7676
}
77-
77+
7878
template <int RTYPE, template <class> class StoragePolicy >
7979
template <typename U>
8080
Matrix<RTYPE,StoragePolicy> Matrix<RTYPE,StoragePolicy>::diag( int size, const U& diag_value ){
8181
Matrix res(size,size) ;
8282
res.fill_diag( diag_value ) ;
8383
return res ;
8484
}
85-
85+
8686
template <int RTYPE, template <class> class StoragePolicy >
8787
inline typename Matrix<RTYPE,StoragePolicy>::Proxy Matrix<RTYPE,StoragePolicy>::operator[]( int i ){
8888
return static_cast< Vector<RTYPE>* >( this )->operator[]( i ) ;
8989
}
90-
90+
9191
template <int RTYPE, template <class> class StoragePolicy >
9292
inline typename Matrix<RTYPE,StoragePolicy>::const_Proxy Matrix<RTYPE,StoragePolicy>::operator[]( int i ) const {
9393
return static_cast< const Vector<RTYPE>* >( this )->operator[]( i ) ;
9494
}
95-
95+
9696
template <int RTYPE, template <class> class StoragePolicy >
9797
inline typename Matrix<RTYPE,StoragePolicy>::Proxy Matrix<RTYPE,StoragePolicy>::operator()( const size_t& i, const size_t& j) {
9898
return static_cast< Vector<RTYPE>* >( this )->operator[]( offset( i, j ) ) ;
9999
}
100-
100+
101101
template <int RTYPE, template <class> class StoragePolicy >
102102
inline typename Matrix<RTYPE,StoragePolicy>::const_Proxy Matrix<RTYPE,StoragePolicy>::operator()( const size_t& i, const size_t& j) const {
103103
return static_cast< const Vector<RTYPE>* >( this )->operator[]( offset( i, j ) ) ;
104104
}
105-
105+
106106
template <int RTYPE, template <class> class StoragePolicy >
107107
inline typename Matrix<RTYPE,StoragePolicy>::Row Matrix<RTYPE,StoragePolicy>::operator()( int i, internal::NamedPlaceHolder ){
108108
return Row( *this, i ) ;
109109
}
110-
110+
111111
template <int RTYPE, template <class> class StoragePolicy >
112112
inline typename Matrix<RTYPE,StoragePolicy>::Column Matrix<RTYPE,StoragePolicy>::operator()( internal::NamedPlaceHolder, int i ){
113113
return Column( *this, i ) ;
114114
}
115-
115+
116116
template <int RTYPE, template <class> class StoragePolicy >
117117
inline typename Matrix<RTYPE,StoragePolicy>::Column Matrix<RTYPE,StoragePolicy>::operator()( internal::NamedPlaceHolder, int i ) const {
118118
return Column( *this, i ) ;
119119
}
120-
120+
121121
template <int RTYPE, template <class> class StoragePolicy >
122122
inline typename Matrix<RTYPE,StoragePolicy>::Sub Matrix<RTYPE,StoragePolicy>::operator()( const Range& row_range, const Range& col_range){
123123
return Sub( const_cast<Matrix&>(*this), row_range, col_range ) ;
@@ -126,12 +126,12 @@ namespace Rcpp{
126126
inline typename Matrix<RTYPE,StoragePolicy>::Sub Matrix<RTYPE,StoragePolicy>::operator()( internal::NamedPlaceHolder, const Range& col_range){
127127
return Sub( const_cast<Matrix&>(*this), Range(0,nrow()-1) , col_range ) ;
128128
}
129-
129+
130130
template <int RTYPE, template <class> class StoragePolicy >
131131
inline typename Matrix<RTYPE,StoragePolicy>::Sub Matrix<RTYPE,StoragePolicy>::operator()( const Range& row_range, internal::NamedPlaceHolder ){
132132
return Sub( const_cast<Matrix&>(*this), row_range, Range(0,ncol()-1) ) ;
133133
}
134-
134+
135135
template <int RTYPE, template <class> class StoragePolicy >
136136
template <typename U>
137137
void Matrix<RTYPE,StoragePolicy>::fill_diag__dispatch( traits::false_type, const U& u){
@@ -141,10 +141,10 @@ namespace Rcpp{
141141
iterator it( VECTOR::begin()) ;
142142
for( int i=0; i<n; i++){
143143
*it = ::Rf_duplicate( elem );
144-
it += offset;
144+
it += offset;
145145
}
146146
}
147-
147+
148148
template <int RTYPE, template <class> class StoragePolicy >
149149
template <typename U>
150150
void Matrix<RTYPE,StoragePolicy>::fill_diag__dispatch( traits::true_type, const U& u){
@@ -154,7 +154,7 @@ namespace Rcpp{
154154
iterator it( VECTOR::begin()) ;
155155
for( int i=0; i<n; i++){
156156
*it = elem ;
157-
it += offset;
157+
it += offset;
158158
}
159159
}
160160

@@ -168,7 +168,7 @@ namespace Rcpp{
168168
}
169169
}
170170
}
171-
171+
172172
} // namespace Rcpp
173173

174174
#endif

inst/unitTests/cpp/Matrix.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Matrix.cpp: Rcpp R/C++ interface class library -- Matrix unit tests
44
//
5-
// Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2013 - 2014 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
66
//
77
// This file is part of Rcpp.
88
//
@@ -50,12 +50,19 @@ List matrix_generic( GenericMatrix m){
5050
}
5151

5252
// [[Rcpp::export]]
53-
IntegerMatrix matrix_integer_diag(){
53+
NumericMatrix matrix_opequals(SEXP x) {
54+
NumericMatrix xx;
55+
xx = NumericMatrix(x);
56+
return xx;
57+
}
58+
59+
// [[Rcpp::export]]
60+
IntegerMatrix matrix_integer_diag(){
5461
return IntegerMatrix::diag( 5, 1 ) ;
5562
}
5663

5764
// [[Rcpp::export]]
58-
CharacterMatrix matrix_character_diag(){
65+
CharacterMatrix matrix_character_diag(){
5966
return CharacterMatrix::diag( 5, "foo" ) ;
6067
}
6168

@@ -147,7 +154,7 @@ IntegerVector runit_GenericMatrix_column( GenericMatrix m ){
147154
std::transform(
148155
col.begin(), col.end(),
149156
out.begin(),
150-
unary_call<SEXP,int>( Function("length" ) )
157+
unary_call<SEXP,int>( Function("length" ) )
151158
) ;
152159
return wrap(out) ;
153160
}

inst/unitTests/runit.Matrix.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/r -t
22
#
3-
# Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
3+
# Copyright (C) 2010 - 2014 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
44
#
55
# This file is part of Rcpp.
66
#
@@ -141,5 +141,10 @@ test.NumericMatrix.SubMatrix <- function( ){
141141
checkEquals( runit_SubMatrix(), target, msg = "SubMatrix" )
142142
}
143143

144+
test.NumericMatrix.opequals <- function() {
145+
m <- matrix(1:4, nrow=2)
146+
checkEquals(m, matrix_opequals(m))
147+
}
148+
144149

145150
}

0 commit comments

Comments
 (0)