Skip to content

Commit be4d07b

Browse files
committed
no coversion
1 parent 189da19 commit be4d07b

File tree

15 files changed

+99
-90
lines changed

15 files changed

+99
-90
lines changed

src/aggregate.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
#include <limits>
55
#include <cmath>
66

7-
8-
std::vector<int > get_dims( std::vector<int > dim) {
7+
std::vector<int > get_dims( std::vector<int> dim) {
98

109
dim.resize(9);
1110
for (int i=0; i < 3; i++) {
12-
dim[i+6] = std::ceil(dim[i] / double(dim[i+3]));
11+
dim[i+6] = (int) std::ceil(dim[i] / double(dim[i+3]));
1312
}
1413
return(dim);
1514

@@ -86,7 +85,7 @@ std::vector<std::vector< double > > get_aggregates(std::vector<std::vector< doub
8685

8786

8887

89-
std::vector<std::vector< double > > aggregate(std::vector<std::vector< double > > data, std::vector<int> dim, bool narm, int fun) {
88+
std::vector<std::vector<double>> aggregate(std::vector<std::vector< double > > data, std::vector<int> dim, bool narm, int fun) {
9089

9190
// fun = 'sum', 'mean', 'min', 'max'
9291
// 0, 1, 2, 3
@@ -109,15 +108,15 @@ std::vector<std::vector< double > > aggregate(std::vector<std::vector< double >
109108
// get the aggregates
110109
std::vector<std::vector< double > > a = get_aggregates(data, dim);
111110

112-
int nblocks = a.size();
113-
int naggs = a[0].size();
111+
int nblocks = (int) a.size();
112+
int naggs = (int) a[0].size();
114113
// Rcout << nblocks << ", " << naggs << "\n";
115114

116115
for (int i = 0; i < nblocks; i++) {
117116
int row = (i / ncol) % nrow;
118117
int col = i % ncol;
119118
int cell = row * ncol + col;
120-
int lyr = std::floor(i / (nrow * ncol));
119+
int lyr = (int) std::floor(i / (nrow * ncol));
121120

122121
// Rcout << row << ", " << col << ", " << lyr << "\n";
123122

src/broom.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ std::vector<double> broom(std::vector<double> d, std::vector<double> f, std::vec
1414
double dy = dist[1];
1515
double dxy = dist[2];
1616
int leftright = 2; //INTEGER(lr)[0];
17-
size_t nr = dm[0];
18-
size_t nc = dm[1];
17+
size_t nr = (size_t)dm[0];
18+
size_t nc = (size_t)dm[1];
1919
size_t n = nr * nc;
2020
// Rprintf ("n = %i \n", n);
2121

@@ -77,7 +77,7 @@ std::vector<double> broom(std::vector<double> d, std::vector<double> f, std::vec
7777
}
7878

7979
// other cells
80-
for (int i=(nc-2); i > -1; i--) {
80+
for (long i=((long)nc-2); i > -1; i--) {
8181
if (std::isnan(d[i])) {
8282
dis[i] = min(min(min(dis[i], f[i] + dy), f[i+1] + dxy), dis[i+1] + dx);
8383
} else {

src/clamp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* Robert Hijmans, October 2011 */
22

3+
34
#include <Rcpp.h>
45

56
// [[Rcpp::export(name = ".clamp")]]

src/distance.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ std::vector<double> distance_lonlat(std::vector<double> lon1, std::vector<double
2727
double azi1, azi2;
2828
struct geod_geodesic g;
2929
geod_init(&g, a, f);
30-
int n = lat1.size();
30+
int n = (int) lat1.size();
3131
for (int i=0; i < n; i++) {
3232
geod_inverse(&g, lat1[i], lon1[i], lat2[i], lon2[i], &r[i], &azi1, &azi2);
3333
}
@@ -37,8 +37,8 @@ std::vector<double> distance_lonlat(std::vector<double> lon1, std::vector<double
3737

3838
std::vector<double> distanceToNearest_lonlat(std::vector<double> lon1, std::vector<double> lat1, std::vector<double> lon2, std::vector<double> lat2, double a, double f) {
3939
double azi1, azi2, s12;
40-
int n = lon1.size();
41-
int m = lon2.size();
40+
int n = (int) lon1.size();
41+
int m = (int) lon2.size();
4242
std::vector<double> r(n);
4343

4444
struct geod_geodesic g;
@@ -64,16 +64,16 @@ double distance_plane(double x1, double y1, double x2, double y2) {
6464
std::vector<double> distance_plane(std::vector<double> x1, std::vector<double> y1, std::vector<double> x2, std::vector<double> y2) {
6565
// xy1 and xy2 should have the same length
6666
std::vector<double> r (x1.size());
67-
int n = x1.size();
67+
int n = (int) x1.size();
6868
for (int i=0; i < n; i++) {
6969
r[i] = sqrt(pow((x2[i]-x1[i]),2) + pow((y2[i]-y1[i]), 2));
7070
}
7171
return r;
7272
}
7373

7474
std::vector<double> distanceToNearest_plane(std::vector<double> x1, std::vector<double> y1, std::vector<double> x2, std::vector<double> y2) {
75-
int n = x1.size();
76-
int m = x2.size();
75+
int n = (int) x1.size();
76+
int m = (int) x2.size();
7777
std::vector<double> r(n);
7878
double d;
7979
for (int i=0; i < n; i++) {
@@ -109,7 +109,7 @@ std::vector<double> direction_lonlat(std::vector<double> lon1, std::vector<doubl
109109
double s12, azi2;
110110
struct geod_geodesic g;
111111
geod_init(&g, a, f);
112-
int n = lat1.size();
112+
int n = (int) lat1.size();
113113
if (degrees) {
114114
for (int i=0; i < n; i++) {
115115
geod_inverse(&g, lat1[i], lon1[i], lat2[i], lon2[i], &s12, &azi1[i], &azi2);
@@ -126,8 +126,8 @@ std::vector<double> direction_lonlat(std::vector<double> lon1, std::vector<doubl
126126

127127
std::vector<double> directionToNearest_lonlat(std::vector<double> lon1, std::vector<double> lat1, std::vector<double> lon2, std::vector<double> lat2, bool degrees, bool from, double a, double f) {
128128
double azi1, azi2, s12, dist;
129-
int n = lon1.size();
130-
int m = lon2.size();
129+
int n = (int)lon1.size();
130+
int m = (int)lon2.size();
131131
std::vector<double> azi(n);
132132

133133
struct geod_geodesic g;
@@ -181,7 +181,7 @@ std::vector<double> direction_plane(std::vector<double> x1, std::vector<double>
181181
// xy1 and xy2 should have the same length
182182
std::vector<double> r (x1.size());
183183
//double a;
184-
int n = x1.size();
184+
int n = (int)x1.size();
185185
for (int i=0; i < n; i++) {
186186
r[i] = direction_plane(x1[i], y1[i], x2[i], y2[i], degrees);
187187
}
@@ -191,8 +191,8 @@ std::vector<double> direction_plane(std::vector<double> x1, std::vector<double>
191191

192192

193193
std::vector<double> directionToNearest_plane(std::vector<double> x1, std::vector<double> y1, std::vector<double> x2, std::vector<double> y2, bool degrees, bool from) {
194-
int n = x1.size();
195-
int m = x2.size();
194+
int n = (int)x1.size();
195+
int m = (int)x2.size();
196196
std::vector<double> r(n);
197197
double d, mind;
198198
int minj;
@@ -243,7 +243,7 @@ std::vector<double> destpoint_lonlat(double longitude, double latitude, double
243243
std::vector<std::vector<double> > destpoint_lonlat(std::vector<double> longitude, std::vector<double> latitude, std::vector<double> bearing, std::vector<double> distance, double a, double f) {
244244
struct geod_geodesic g;
245245
geod_init(&g, a, f);
246-
int n = longitude.size();
246+
int n = (int)longitude.size();
247247
std::vector<std::vector<double> > out;
248248
double lat2, lon2, azi2;
249249
for (int i=0; i < n; i++) {
@@ -264,7 +264,7 @@ std::vector<double> destpoint_plane(double x, double y, double bearing, double d
264264

265265

266266
std::vector<std::vector<double> > destpoint_plane(std::vector<double> x, std::vector<double> y, std::vector<double> bearing, std::vector<double> distance) {
267-
int n = x.size();
267+
int n = (int)x.size();
268268
std::vector<std::vector<double> > out(n, std::vector<double>(3));
269269
double xd, yd, b;
270270
for (int i=0; i < n; i++) {
@@ -284,7 +284,7 @@ double area_polygon_lonlat(std::vector<double> lon, std::vector<double> lat, dou
284284
struct geod_polygon p;
285285
geod_init(&g, a, f);
286286
geod_polygon_init(&p, 0);
287-
int n = lat.size();
287+
int n = (int)lat.size();
288288
for (int i=0; i < n; i++) {
289289
geod_polygon_addpoint(&g, &p, lat[i], lon[i]);
290290
}
@@ -304,7 +304,7 @@ std::vector<double> area_polygon_lonlat(std::vector<double> lon, std::vector<dou
304304
double area, P, pa, tota;
305305
int pol = 1;
306306
int part = 1;
307-
int n = lon.size();
307+
int n = (int)lon.size();
308308
tota = 0;
309309
for (int i=0; i < n; i++) {
310310
if (parts[i] != part || pols[i] != pol) {
@@ -333,7 +333,7 @@ std::vector<double> area_polygon_lonlat(std::vector<double> lon, std::vector<dou
333333

334334
double area_polygon_plane(std::vector<double> x, std::vector<double> y) {
335335
// based on http://paulbourke.net/geometry/polygonmesh/source1.c
336-
int n = x.size();
336+
int n = (int)x.size();
337337
double area = x[n-1] * y[0];
338338
area -= y[n-1] * x[0];
339339
for (int i=0; i < (n-1); i++) {
@@ -383,7 +383,7 @@ std::vector<double> area_polygon_plane(std::vector<double> x, std::vector<double
383383
std::vector<double> out;
384384
int pol = 1;
385385
int part = 1;
386-
int n = x.size();
386+
int n = (int)x.size();
387387
double tota = 0;
388388
double pa;
389389
int ps = 0;

src/focal_get.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* Robert Hijmans, October 2011 */
22

3+
34
#include <Rcpp.h>
45

56
// [[Rcpp::export(name = ".focal_get")]]

src/focal_sum.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* Robert Hijmans, October 2011 */
22

3+
34
#include <Rcpp.h>
45

56
// [[Rcpp::export(name = ".focal_sum")]]
67
std::vector<double> do_focal_sum(std::vector<double> d, Rcpp::NumericMatrix w, std::vector<double> dim, bool narm, bool naonly, bool bemean) {
78

89
int wrows = w.nrow();
910
int wcols = w.ncol();
10-
int nrow = dim[0];
11-
int ncol = dim[1];
11+
int nrow = (int)dim[0];
12+
int ncol = (int)dim[1];
1213
int n = nrow * ncol;
1314
std::vector<double> val(n);
1415

@@ -59,7 +60,7 @@ std::vector<double> do_focal_sum(std::vector<double> d, Rcpp::NumericMatrix w, s
5960
if (p==0) {
6061
val[i] = NAN;
6162
} else if (bemean) {
62-
val[i] = val[i] / p;
63+
val[i] = val[i] / (double) p;
6364
}
6465
}
6566
}
@@ -100,7 +101,7 @@ std::vector<double> do_focal_sum(std::vector<double> d, Rcpp::NumericMatrix w, s
100101
if (p==0) {
101102
val[i] = NAN;
102103
} else if (bemean) {
103-
val[i] = val[i] / p;
104+
val[i] = val[i] / (double) p;
104105
}
105106
}
106107
}
@@ -153,7 +154,7 @@ std::vector<double> do_focal_sum(std::vector<double> d, Rcpp::NumericMatrix w, s
153154
}
154155
}
155156
if (bemean) {
156-
val[i] = val[i] / q;
157+
val[i] = val[i] / (double) q;
157158
}
158159
}
159160
}
@@ -186,7 +187,7 @@ std::vector<double> do_focal_sum(std::vector<double> d, Rcpp::NumericMatrix w, s
186187
}
187188

188189
if (bemean) {
189-
val[i] = val[i] / q;
190+
val[i] = val[i] / (double) q;
190191
}
191192
}
192193
}

src/memory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Robert Hijmans with improvements by Ben Fasoli
22
// https://github.com/rspatial/raster/pull/175
33

4+
45
#ifdef _WIN32
56
#include <windows.h>
67
#elif __linux__
@@ -19,7 +20,7 @@ double availableRAM(double ram) {
1920
MEMORYSTATUSEX statex;
2021
statex.dwLength = sizeof(statex);
2122
GlobalMemoryStatusEx(&statex);
22-
ram = statex.ullAvailPhys;
23+
ram = (double) statex.ullAvailPhys;
2324
#elif __linux__
2425
// source available memory from /proc/meminfo
2526
// default to searching for MemAvailable field (kernel versions >= 3.14)

src/modal.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
11
#include <Rcpp.h>
22
using namespace Rcpp;
33

4+
45
// [[Rcpp::export(name = ".getMode")]]
56
double getMode(NumericVector values, int ties) {
6-
int n = values.length();
7+
size_t n = values.length();
78
IntegerVector counts(n);
89

910
if (ties < 2) {
1011
std::sort(values.begin(), values.end());
1112
}
1213

13-
for (int i = 0; i < n; ++i) {
14+
for (size_t i = 0; i < n; ++i) {
1415
counts[i] = 0;
15-
int j = 0;
16+
size_t j = 0;
1617
while ((j < i) && (values[i] != values[j])) {
1718
++j;
1819
}
1920
++(counts[j]);
2021
}
2122

22-
int maxCount = 0;
23+
size_t maxCount = 0;
2324
// first (lowest due to sorting)
2425
if (ties == 0) {
25-
for (int i = 1; i < n; ++i) {
26+
for (size_t i = 1; i < n; ++i) {
2627
if (counts[i] > counts[maxCount]) {
2728
maxCount = i;
2829
}
2930
}
3031
// last
3132
} else if (ties == 1) {
32-
for (int i = 1; i < n; ++i) {
33+
for (size_t i = 1; i < n; ++i) {
3334
if (counts[i] >= counts[maxCount]) {
3435
maxCount = i;
3536
}
3637
}
3738

3839
// dont care (first, but not sorted)
3940
} else if (ties == 2) {
40-
for (int i = 1; i < n; ++i) {
41+
for (size_t i = 1; i < n; ++i) {
4142
if (counts[i] > counts[maxCount]) {
4243
maxCount = i;
4344
}
4445
}
4546

4647
// random
4748
} else if (ties == 3) {
48-
int tieCount = 1;
49-
for (int i = 1; i < n; ++i) {
49+
size_t tieCount = 1;
50+
for (size_t i = 1; i < n; ++i) {
5051
if (counts[i] > counts[maxCount]) {
5152
maxCount = i;
5253
tieCount = 1;
5354
} else if (counts[i] == counts[maxCount]) {
5455
tieCount++;
55-
if (R::runif(0,1) < (1.0 / tieCount)) {
56+
double vv = (1.0 / (double)tieCount);
57+
if (R::runif(0,1) < vv) {
5658
maxCount = i;
5759
}
5860
}
5961
}
6062

6163
// NA
6264
} else {
63-
int tieCount = 1;
64-
for (int i = 1; i < n; ++i) {
65+
size_t tieCount = 1;
66+
for (size_t i = 1; i < n; ++i) {
6567
if (counts[i] > counts[maxCount]) {
6668
maxCount = i;
6769
tieCount = 1;

0 commit comments

Comments
 (0)