Skip to content

Commit 7d556da

Browse files
committed
Merge pull request #370 from fplaza/large-matrices-fix
Fix creation and access to elements of large matrices
2 parents 0585a21 + d3dab9f commit 7d556da

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

inst/include/Rcpp/Dimension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace Rcpp{
5757
return (int) dims.size() ;
5858
}
5959
inline int prod() const {
60-
return std::accumulate( dims.begin(), dims.end(), 1, std::multiplies<int>() ) ;
60+
return std::accumulate( dims.begin(), dims.end(), static_cast<R_xlen_t>(1), std::multiplies<R_xlen_t>() );
6161
}
6262

6363
inline reference operator[](int i){

inst/include/Rcpp/vector/Matrix.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Matrix : public Vector<RTYPE, StoragePolicy>, public MatrixBase<RTYPE, tru
5858

5959
template <typename Iterator>
6060
Matrix( const int& nrows_, const int& ncols, Iterator start ) :
61-
VECTOR( start, start + (nrows_*ncols) ),
61+
VECTOR( start, start + (static_cast<R_xlen_t>(nrows_)*ncols) ),
6262
nrows(nrows_)
6363
{
6464
VECTOR::attr( "dim" ) = Dimension( nrows, ncols ) ;
@@ -163,8 +163,7 @@ class Matrix : public Vector<RTYPE, StoragePolicy>, public MatrixBase<RTYPE, tru
163163

164164

165165
private:
166-
167-
inline R_xlen_t offset( int i, int j) const { return i + nrows * j ; }
166+
inline R_xlen_t offset(const int i, const int j) const { return i + static_cast<R_xlen_t>(nrows) * j ; }
168167

169168
template <typename U>
170169
void fill_diag__dispatch( traits::false_type, const U& u) {

0 commit comments

Comments
 (0)