Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce -Wconversion warnings for sugar code #688

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions inst/include/Rcpp/sugar/functions/rowSums.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ inline void incr(Rcomplex* lhs, const Rcomplex& rhs) {


inline void div(double* lhs, R_xlen_t rhs) {
*lhs /= rhs;
*lhs /= static_cast<double>(rhs);
}

inline void div(Rcomplex* lhs, R_xlen_t rhs) {
lhs->r /= rhs;
lhs->i /= rhs;
lhs->r /= static_cast<double>(rhs);
lhs->i /= static_cast<double>(rhs);
}


Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/sugar/functions/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace sugar {
inline void Normalize(Vector<REALSXP>& p, int require_k, bool replace)
{
double sum = 0.0;
int npos = 0, i = 0, n = p.size();
R_xlen_t npos = 0, i = 0, n = p.size();

for ( ; i < n; i++) {
if (!R_FINITE(p[i]) || (p[i] < 0)) {
Expand Down
3 changes: 2 additions & 1 deletion inst/include/Rcpp/sugar/functions/strings/trimws.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ inline Vector<STRSXP> trimws(const Vector<STRSXP>& x, const char* which = "both"
}

inline Matrix<STRSXP> trimws(const Matrix<STRSXP>& x, const char* which = "both") {
R_xlen_t i = 0, nr = x.nrow(), nc = x.ncol(), sz = x.size();
R_xlen_t i = 0, sz = x.size();
int nr = x.nrow(), nc = x.ncol();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking here: Even with R_xlen_t, rows and cols are still int in R itself, but number of matrix elements can exceed int. Do I have that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the way it's implemented currently, see R-ints.

Copy link
Contributor

@coatless coatless May 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://stat.ethz.ch/R-manual/R-devel/library/base/html/LongVectors.html

Arrays (including matrices) can be based on long vectors provided each of their dimensions is at most 2^31 - 1:

Type Storage size Value range
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647

In theory, you are bounded by: (2^31 - 1)^2 = 4,611,686,014,132,420,609

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too, was just trying to confirm. Because otherwise nrow, ncol should not be int here and in Matrix.

Have a test running with the now-merged PR. Things take some time of course.

Copy link
Member

@eddelbuettel eddelbuettel May 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not uint though. R only uses signed ints.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R> .Machine$integer.max
[1] 2147483647
R> 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoted the 2byte bounds instead of 4byte blah.

Matrix<STRSXP> res = no_init(nr, nc);
std::string buffer;

Expand Down