Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add at accessors with bounds checking#342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
eddelbuettel merged 14 commits intoRcppCore:masterfromfplazaonate:at-accessors-patch
Aug 25, 2015
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Change offset methods to detect negative indexes
  • Loading branch information
Florian Plaza Oñate committedAug 20, 2015
commit2eab5d8c1fc1663bd0b5dcaacfe25fbf4631c441
18 changes: 9 additions & 9 deletionsinst/include/Rcpp/vector/Vector.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,26 +278,26 @@ class Vector :
/**
* offset based on the dimensions of this vector
*/
size_t offset(constsize_t& i, constsize_t& j) const {
R_xlen_t offset(constint& i, constint& j) const {
if( !::Rf_isMatrix(Storage::get__()) ) throw not_a_matrix() ;

/* we need to extract the dimensions */
int *dim = dims() ;
size_tnrow =static_cast<size_t>(dim[0]) ;
size_tncol =static_cast<size_t>(dim[1]) ;
if(i >= nrow || j >= ncol ) throw index_out_of_bounds() ;
return i + nrow*j ;
const int*dim = dims() ;
const intnrow = dim[0] ;
const intncol = dim[1] ;
if(i < 0||i >= nrow || j < 0 || j >= ncol ) throw index_out_of_bounds() ;
return i +static_cast<R_xlen_t>(nrow)*j ;
}

/**
* one dimensional offset doing bounds checking to ensure
* it is valid
*/
size_t offset(constsize_t& i) const {
if( static_cast<R_xlen_t>(i) >= ::Rf_xlength(Storage::get__()) ) throw index_out_of_bounds() ;
R_xlen_t offset(constR_xlen_t& i) const {
if(i < 0 || i >= ::Rf_xlength(Storage::get__()) ) throw index_out_of_bounds() ;
return i ;
}

R_xlen_t offset(const std::string& name) const {
SEXP names = RCPP_GET_NAMES( Storage::get__() ) ;
if( Rf_isNull(names) ) throw index_out_of_bounds();
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp