@@ -10,30 +10,30 @@ namespace vtr {
10
10
/* *
11
11
* @brief A half-open range specification for a matrix dimension [begin_index, last_index)
12
12
*
13
- * It comes with valid indicies from [begin_index() ... end_index()-1], provided size() > 0.
13
+ * It comes with valid indices from [begin_index() ... end_index()-1], provided size() > 0.
14
14
*/
15
15
class DimRange {
16
16
public:
17
17
// /@brief default constructor
18
18
DimRange () = default ;
19
19
20
20
// /@brief a constructor with begin_index, end_index
21
- DimRange (size_t begin, size_t end)
21
+ DimRange (int begin, int end)
22
22
: begin_index_(begin)
23
23
, end_index_(end) {}
24
24
25
25
// /@brief Return the begin index
26
- size_t begin_index () const { return begin_index_; }
26
+ int begin_index () const { return begin_index_; }
27
27
28
28
// /@brief Return the end index
29
- size_t end_index () const { return end_index_; }
29
+ int end_index () const { return end_index_; }
30
30
31
31
// /@brief Return the size
32
32
size_t size () const { return end_index_ - begin_index_; }
33
33
34
34
private:
35
- size_t begin_index_ = 0 ;
36
- size_t end_index_ = 0 ;
35
+ int begin_index_ = 0 ;
36
+ int end_index_ = 0 ;
37
37
};
38
38
39
39
/* *
@@ -69,7 +69,7 @@ class NdOffsetMatrixProxy {
69
69
, start_(start) {}
70
70
71
71
// /@brief const [] operator
72
- const NdOffsetMatrixProxy<T, N - 1 > operator [](size_t index) const {
72
+ const NdOffsetMatrixProxy<T, N - 1 > operator [](int index) const {
73
73
VTR_ASSERT_SAFE_MSG (index >= dim_ranges_[idim_].begin_index (), " Index out of range (below dimension minimum)" );
74
74
VTR_ASSERT_SAFE_MSG (index < dim_ranges_[idim_].end_index (), " Index out of range (above dimension maximum)" );
75
75
@@ -79,10 +79,10 @@ class NdOffsetMatrixProxy {
79
79
* The elements are stored in zero-indexed form, so we need to adjust
80
80
* for any non-zero minimum index
81
81
*/
82
- size_t effective_index = index - dim_ranges_[idim_].begin_index ();
82
+ int effective_index = index - dim_ranges_[idim_].begin_index ();
83
83
84
84
// Determine the stride of the next dimension
85
- size_t next_dim_stride = dim_stride_ / dim_ranges_[idim_ + 1 ].size ();
85
+ int next_dim_stride = dim_stride_ / dim_ranges_[idim_ + 1 ].size ();
86
86
87
87
// Strip off one dimension
88
88
return NdOffsetMatrixProxy<T, N - 1 >(dim_ranges_, // Pass the dimension information
@@ -92,7 +92,7 @@ class NdOffsetMatrixProxy {
92
92
}
93
93
94
94
// /@brief [] operator
95
- NdOffsetMatrixProxy<T, N - 1 > operator [](size_t index) {
95
+ NdOffsetMatrixProxy<T, N - 1 > operator [](int index) {
96
96
// Call the const version and cast-away constness
97
97
return const_cast <const NdOffsetMatrixProxy<T, N>*>(this )->operator [](index );
98
98
}
@@ -122,21 +122,21 @@ class NdOffsetMatrixProxy<T, 1> {
122
122
, start_(start) {}
123
123
124
124
// /@brief const [] operator
125
- const T& operator [](size_t index) const {
125
+ const T& operator [](int index) const {
126
126
VTR_ASSERT_SAFE_MSG (dim_stride_ == 1 , " Final dimension must have stride 1" );
127
127
VTR_ASSERT_SAFE_MSG (index >= dim_ranges_[idim_].begin_index (), " Index out of range (below dimension minimum)" );
128
128
VTR_ASSERT_SAFE_MSG (index < dim_ranges_[idim_].end_index (), " Index out of range (above dimension maximum)" );
129
129
130
130
// The elements are stored in zero-indexed form, so we need to adjust
131
131
// for any non-zero minimum index
132
- size_t effective_index = index - dim_ranges_[idim_].begin_index ();
132
+ int effective_index = index - dim_ranges_[idim_].begin_index ();
133
133
134
134
// Base case
135
135
return start_[effective_index];
136
136
}
137
137
138
138
// /@brief [] operator
139
- T& operator [](size_t index) {
139
+ T& operator [](int index) {
140
140
// Call the const version and cast-away constness
141
141
return const_cast <T&>(const_cast <const NdOffsetMatrixProxy<T, 1 >*>(this )->operator [](index ));
142
142
}
@@ -163,7 +163,7 @@ class NdOffsetMatrixProxy<T, 1> {
163
163
* This should improve memory usage (no extra pointers to store for each dimension),
164
164
* and cache locality (less indirection via pointers, predictable strides).
165
165
*
166
- * The indicies are calculated based on the dimensions to access the appropriate elements.
166
+ * The indices are calculated based on the dimensions to access the appropriate elements.
167
167
* Since the indexing calculations are visible to the compiler at compile time they can be
168
168
* optimized to be efficient.
169
169
*/
@@ -230,14 +230,14 @@ class NdOffsetMatrixBase {
230
230
}
231
231
232
232
// /@brief Returns the starting index of ith dimension
233
- size_t begin_index (size_t i) const {
233
+ int begin_index (size_t i) const {
234
234
VTR_ASSERT_SAFE (i < ndims ());
235
235
236
236
return dim_ranges_[i].begin_index ();
237
237
}
238
238
239
239
// /@brief Returns the one-past-the-end index of the ith dimension
240
- size_t end_index (size_t i) const {
240
+ int end_index (size_t i) const {
241
241
VTR_ASSERT_SAFE (i < ndims ());
242
242
243
243
return dim_ranges_[i].end_index ();
@@ -333,7 +333,7 @@ class NdOffsetMatrixBase {
333
333
*
334
334
* Examples:
335
335
*
336
- * //A 2-dimensional matrix with indicies [0..4][0..9]
336
+ * //A 2-dimensional matrix with indices [0..4][0..9]
337
337
* NdOffsetMatrix<int,2> m1({5,10});
338
338
*
339
339
* //Accessing an element
@@ -342,28 +342,28 @@ class NdOffsetMatrixBase {
342
342
* //Setting an element
343
343
* m4[6][20] = 0;
344
344
*
345
- * //A 2-dimensional matrix with indicies [2..6][5..9]
345
+ * //A 2-dimensional matrix with indices [2..6][5..9]
346
346
* // Note that C++ requires one more set of curly brace than you would expect
347
347
* NdOffsetMatrix<int,2> m2({{{2,7},{5,10}}});
348
348
*
349
- * //A 3-dimensional matrix with indicies [0..4][0..9][0..19]
349
+ * //A 3-dimensional matrix with indices [0..4][0..9][0..19]
350
350
* NdOffsetMatrix<int,3> m3({5,10,20});
351
351
*
352
- * //A 3-dimensional matrix with indicies [2..6][1..19][50..89]
352
+ * //A 3-dimensional matrix with indices [2..6][1..19][50..89]
353
353
* NdOffsetMatrix<int,3> m4({{{2,7}, {1,20}, {50,90}}});
354
354
*
355
- * //A 2-dimensional matrix with indicies [2..6][1..20], with all entries
356
- * //intialized to 42
355
+ * //A 2-dimensional matrix with indices [2..6][1..20], with all entries
356
+ * //initialized to 42
357
357
* NdOffsetMatrix<int,2> m4({{{2,7}, {1,21}}}, 42);
358
358
*
359
- * //A 2-dimensional matrix with indicies [0..4][0..9], with all entries
359
+ * //A 2-dimensional matrix with indices [0..4][0..9], with all entries
360
360
* //initialized to 42
361
361
* NdOffsetMatrix<int,2> m1({5,10}, 42);
362
362
*
363
363
* //Filling all entries with value 101
364
364
* m1.fill(101);
365
365
*
366
- * //Resizing an existing matrix (all values reset to default constucted value)
366
+ * //Resizing an existing matrix (all values reset to default constructed value)
367
367
* m1.resize({5,5})
368
368
*
369
369
* //Resizing an existing matrix (all elements set to value 88)
@@ -385,25 +385,25 @@ class NdOffsetMatrix : public NdOffsetMatrixBase<T, N> {
385
385
* Returns a proxy-object to allow chained array-style indexing (N >= 2 case)
386
386
* template<typename = typename std::enable_if<N >= 2>::type, typename T1=T>
387
387
*/
388
- const NdOffsetMatrixProxy<T, N - 1 > operator [](size_t index) const {
388
+ const NdOffsetMatrixProxy<T, N - 1 > operator [](int index) const {
389
389
VTR_ASSERT_SAFE_MSG (this ->dim_size (0 ) > 0 , " Can not index into size zero dimension" );
390
390
VTR_ASSERT_SAFE_MSG (this ->dim_size (1 ) > 0 , " Can not index into size zero dimension" );
391
391
VTR_ASSERT_SAFE_MSG (index >= this ->dim_ranges_ [0 ].begin_index (), " Index out of range (below dimension minimum)" );
392
392
VTR_ASSERT_SAFE_MSG (index < this ->dim_ranges_ [0 ].end_index (), " Index out of range (above dimension maximum)" );
393
393
394
394
/*
395
- * Clacluate the effective index
395
+ * Calculate the effective index
396
396
*
397
397
* The elements are stored in zero-indexed form, so adjust for any
398
398
* non-zero minimum index in this dimension
399
399
*/
400
- size_t effective_index = index - this ->dim_ranges_ [0 ].begin_index ();
400
+ int effective_index = index - this ->dim_ranges_ [0 ].begin_index ();
401
401
402
402
// Calculate the stride for the current dimension
403
- size_t dim_stride = this ->size () / this ->dim_size (0 );
403
+ int dim_stride = this ->size () / this ->dim_size (0 );
404
404
405
405
// Calculate the stride for the next dimension
406
- size_t next_dim_stride = dim_stride / this ->dim_size (1 );
406
+ int next_dim_stride = dim_stride / this ->dim_size (1 );
407
407
408
408
// Peel off the first dimension
409
409
return NdOffsetMatrixProxy<T, N - 1 >(this ->dim_ranges_ .data (), // Pass the dimension information
@@ -417,7 +417,7 @@ class NdOffsetMatrix : public NdOffsetMatrixBase<T, N> {
417
417
*
418
418
* Returns a proxy-object to allow chained array-style indexing
419
419
*/
420
- NdOffsetMatrixProxy<T, N - 1 > operator [](size_t index) {
420
+ NdOffsetMatrixProxy<T, N - 1 > operator [](int index) {
421
421
// Call the const version, since returned by value don't need to worry about const
422
422
return const_cast <const NdOffsetMatrix<T, N>*>(this )->operator [](index );
423
423
}
@@ -436,7 +436,7 @@ class NdOffsetMatrix<T, 1> : public NdOffsetMatrixBase<T, 1> {
436
436
437
437
public:
438
438
// /@brief Access an element (immutable)
439
- const T& operator [](size_t index) const {
439
+ const T& operator [](int index) const {
440
440
VTR_ASSERT_SAFE_MSG (this ->dim_size (0 ) > 0 , " Can not index into size zero dimension" );
441
441
VTR_ASSERT_SAFE_MSG (index >= this ->dim_ranges_ [0 ].begin_index (), " Index out of range (below dimension minimum)" );
442
442
VTR_ASSERT_SAFE_MSG (index < this ->dim_ranges_ [0 ].end_index (), " Index out of range (above dimension maximum)" );
@@ -445,7 +445,7 @@ class NdOffsetMatrix<T, 1> : public NdOffsetMatrixBase<T, 1> {
445
445
}
446
446
447
447
// /@brief Access an element (mutable)
448
- T& operator [](size_t index) {
448
+ T& operator [](int index) {
449
449
// Call the const version, and cast away const-ness
450
450
return const_cast <T&>(const_cast <const NdOffsetMatrix<T, 1 >*>(this )->operator [](index ));
451
451
}
0 commit comments