Skip to content

Commit 0d6adbb

Browse files
committed
Replace uint typedef in Polyfit.h with uint32_t
uint32_t will ensure a type of a specific size more accurately than unsigned int does. This also resolves the compiler warnings that Polyfit.h was causing due to a mix of size_t (8 bytes) and unsigned int (4 bytes, MSVC)
1 parent e1fdbb4 commit 0d6adbb

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/Core/Polyfit.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77

88
namespace mathalgo {
99

10-
typedef unsigned int uint;
11-
1210
template <typename T>
1311
struct matrix
1412
{
15-
matrix(uint nRows, uint nCols) :
13+
matrix(uint32_t nRows, uint32_t nCols) :
1614
rows(nRows),
1715
cols(nCols),
1816
data(nRows * nCols, 0)
1917
{
2018
}
21-
static matrix identity(uint nSize)
19+
static matrix identity(uint32_t nSize)
2220
{
2321
matrix oResult(nSize, nSize);
2422

@@ -28,18 +26,18 @@ struct matrix
2826

2927
return oResult;
3028
}
31-
inline T& operator()(uint nRow, uint nCol)
29+
inline T& operator()(uint32_t nRow, uint32_t nCol)
3230
{
3331
return data[nCol + cols*nRow];
3432
}
3533
inline matrix operator*(matrix& other)
3634
{
3735
matrix oResult(rows, other.cols);
38-
for(uint r = 0; r < rows; ++r)
36+
for(uint32_t r = 0; r < rows; ++r)
3937
{
40-
for(uint ocol = 0; ocol < other.cols; ++ocol)
38+
for(uint32_t ocol = 0; ocol < other.cols; ++ocol)
4139
{
42-
for(uint c = 0; c < cols; ++c)
40+
for(uint32_t c = 0; c < cols; ++c)
4341
{
4442
oResult(r, ocol) += (*this)(r, c) * other(c, ocol);
4543
}
@@ -50,18 +48,18 @@ struct matrix
5048
inline matrix transpose()
5149
{
5250
matrix oResult(cols, rows);
53-
for(uint r = 0; r < rows; ++r)
51+
for(uint32_t r = 0; r < rows; ++r)
5452
{
55-
for(uint c = 0; c < cols; ++c)
53+
for(uint32_t c = 0; c < cols; ++c)
5654
{
5755
oResult(c, r) += (*this)(r, c);
5856
}
5957
}
6058
return oResult;
6159
}
6260
Vortex::Vector<T> data;
63-
uint rows;
64-
uint cols;
61+
uint32_t rows;
62+
uint32_t cols;
6563
};
6664

6765
template <typename T>
@@ -263,29 +261,30 @@ Vortex::Vector<T> polyfit(const T* oX, const T* oY, size_t nCount, int nDegree)
263261

264262
// Specialized version for BPM testing, writes degree + 1 coefficients to outCoefs.
265263
template <typename T>
266-
void polyfit(int degree, T* outCoefs, const T* inValues, size_t numNonZeroValues, int offsetX)
264+
void polyfit(int degree, T* outCoefs, const T* inValues, uint32_t numNonZeroValues, int offsetX)
267265
{
268266
// more intuative this way
269267
++degree;
270268

271-
matrix<T> oXMatrix(numNonZeroValues, degree);
272-
matrix<T> oYMatrix(numNonZeroValues, 1);
269+
const uint32_t numValues = static_cast<uint32_t>(numNonZeroValues);
270+
matrix<T> oXMatrix(numValues, degree);
271+
matrix<T> oYMatrix(numValues, 1);
273272

274273
// copy y matrix
275-
for(size_t nRow = 0, i = 0; nRow < numNonZeroValues; ++nRow, ++i)
274+
for(uint32_t nRow = 0, i = 0; nRow < numValues; ++nRow, ++i)
276275
{
277276
while(inValues[i] == 0) ++i;
278277
oYMatrix(nRow, 0) = inValues[i];
279278
}
280279

281280
// create the X matrix
282-
for(size_t nRow = 0, i = 0; nRow < numNonZeroValues; ++nRow, ++i)
281+
for(uint32_t nRow = 0, i = 0; nRow < numValues; ++nRow, ++i)
283282
{
284283
while(inValues[i] == 0) ++i;
285284
T nVal = 1.0f, x = T(offsetX + i);
286285
for(int nCol = 0; nCol < degree; nCol++)
287286
{
288-
oXMatrix(nRow, nCol) = nVal;
287+
oXMatrix(static_cast<uint32_t>(nRow), nCol) = nVal;
289288
nVal *= x;
290289
}
291290
}

0 commit comments

Comments
 (0)