7
7
8
8
namespace mathalgo {
9
9
10
- typedef unsigned int uint;
11
-
12
10
template <typename T>
13
11
struct matrix
14
12
{
15
- matrix (uint nRows, uint nCols) :
13
+ matrix (uint32_t nRows, uint32_t nCols) :
16
14
rows (nRows),
17
15
cols (nCols),
18
16
data (nRows * nCols, 0 )
19
17
{
20
18
}
21
- static matrix identity (uint nSize)
19
+ static matrix identity (uint32_t nSize)
22
20
{
23
21
matrix oResult (nSize, nSize);
24
22
@@ -28,18 +26,18 @@ struct matrix
28
26
29
27
return oResult;
30
28
}
31
- inline T& operator ()(uint nRow, uint nCol)
29
+ inline T& operator ()(uint32_t nRow, uint32_t nCol)
32
30
{
33
31
return data[nCol + cols*nRow];
34
32
}
35
33
inline matrix operator *(matrix& other)
36
34
{
37
35
matrix oResult (rows, other.cols );
38
- for (uint r = 0 ; r < rows; ++r)
36
+ for (uint32_t r = 0 ; r < rows; ++r)
39
37
{
40
- for (uint ocol = 0 ; ocol < other.cols ; ++ocol)
38
+ for (uint32_t ocol = 0 ; ocol < other.cols ; ++ocol)
41
39
{
42
- for (uint c = 0 ; c < cols; ++c)
40
+ for (uint32_t c = 0 ; c < cols; ++c)
43
41
{
44
42
oResult (r, ocol) += (*this )(r, c) * other (c, ocol);
45
43
}
@@ -50,18 +48,18 @@ struct matrix
50
48
inline matrix transpose ()
51
49
{
52
50
matrix oResult (cols, rows);
53
- for (uint r = 0 ; r < rows; ++r)
51
+ for (uint32_t r = 0 ; r < rows; ++r)
54
52
{
55
- for (uint c = 0 ; c < cols; ++c)
53
+ for (uint32_t c = 0 ; c < cols; ++c)
56
54
{
57
55
oResult (c, r) += (*this )(r, c);
58
56
}
59
57
}
60
58
return oResult;
61
59
}
62
60
Vortex::Vector<T> data;
63
- uint rows;
64
- uint cols;
61
+ uint32_t rows;
62
+ uint32_t cols;
65
63
};
66
64
67
65
template <typename T>
@@ -263,29 +261,30 @@ Vortex::Vector<T> polyfit(const T* oX, const T* oY, size_t nCount, int nDegree)
263
261
264
262
// Specialized version for BPM testing, writes degree + 1 coefficients to outCoefs.
265
263
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)
267
265
{
268
266
// more intuative this way
269
267
++degree;
270
268
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 );
273
272
274
273
// 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)
276
275
{
277
276
while (inValues[i] == 0 ) ++i;
278
277
oYMatrix (nRow, 0 ) = inValues[i];
279
278
}
280
279
281
280
// 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)
283
282
{
284
283
while (inValues[i] == 0 ) ++i;
285
284
T nVal = 1 .0f , x = T (offsetX + i);
286
285
for (int nCol = 0 ; nCol < degree; nCol++)
287
286
{
288
- oXMatrix (nRow, nCol) = nVal;
287
+ oXMatrix (static_cast < uint32_t >( nRow) , nCol) = nVal;
289
288
nVal *= x;
290
289
}
291
290
}
0 commit comments