Skip to content

Commit ce8c4e2

Browse files
committed
Fix more cast errors
1 parent a610cf8 commit ce8c4e2

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

kmsr/cpp/heuristic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ vector<Cluster> kMeansPlusPlus(vector<Point> &points, int k, int seed)
6767
{
6868
vector<double> dist(n, numeric_limits<double>::max());
6969

70-
for (size_t j = 0; j < n; j++)
70+
for (int j = 0; j < n; j++)
7171
{
7272
for (const Point &center : centers)
7373
{
@@ -78,7 +78,7 @@ vector<Cluster> kMeansPlusPlus(vector<Point> &points, int k, int seed)
7878
// Calculate the probability distribution for selecting the next center
7979
vector<double> distSquared(n);
8080
double sumDist = 0.0;
81-
for (size_t j = 0; j < n; j++)
81+
for (int j = 0; j < n; j++)
8282
{
8383
distSquared[j] = dist[j] * dist[j];
8484
sumDist += distSquared[j];
@@ -88,7 +88,7 @@ vector<Cluster> kMeansPlusPlus(vector<Point> &points, int k, int seed)
8888
double r = disReal(gen);
8989
double cumulativeDist = 0.0;
9090

91-
for (size_t j = 0; j < n; j++)
91+
for (int j = 0; j < n; j++)
9292
{
9393
cumulativeDist += distSquared[j];
9494
if (cumulativeDist >= r)

kmsr/cpp/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool clustersOverlap(const Cluster &c1, const Cluster &c2)
3131
std::vector<Cluster> assignPointsToCluster(const std::vector<Point> &points,
3232
const std::vector<Point> &centers, int k)
3333
{
34-
int n = points.size();
34+
int n = static_cast<int>(points.size());
3535
std::vector<Cluster> clusters(k);
3636

3737
// Create clusters based on the centers
@@ -59,7 +59,7 @@ std::vector<Cluster> assignPointsToCluster(const std::vector<Point> &points,
5959
// Computes the centroid of the cluster
6060
Point computeCentroid(const std::vector<Point> &points)
6161
{
62-
int dimension = points[0].getCoordinates().size();
62+
int dimension = static_cast<int>(points[0].getCoordinates().size());
6363
std::vector<double> centroidCoords(dimension, 0.0);
6464

6565
// Sum of the coordinates of all points in the cluster

kmsr/cpp/welzl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct PointCoordAccessor
1818

1919
Ball findMinEnclosingBall(const vector<Point> &points)
2020
{
21-
int dimension = points.front().getCoordinates().size();
21+
int dimension = static_cast<int>(points.front().getCoordinates().size());
2222

2323
Miniball::Miniball<PointCoordAccessor> mb(dimension, points.begin(),
2424
points.end());

kmsr/cpp/yildirim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace std;
88
// Function to find the furthest point from a given point
99
int findFurthestPoint(const std::vector<Point> &points, const Point &p)
1010
{
11-
int furthestIndex = 0;
11+
size_t furthestIndex = 0;
1212
double maxDistSquared = 0.0;
1313
for (size_t i = 0; i < points.size(); i++)
1414
{
@@ -21,7 +21,7 @@ int findFurthestPoint(const std::vector<Point> &points, const Point &p)
2121
furthestIndex = i;
2222
}
2323
}
24-
return furthestIndex;
24+
return static_cast<int>(furthestIndex);
2525
}
2626

2727
// Function to calculate the weighted sum of the squares of the coordinates

0 commit comments

Comments
 (0)